VFSNotebookRepo implements NotebookRepo { @Override public synchronized void save(Note note, AuthenticationInfo subject) throws IOException { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setPrettyPrinting(); Gson gson = gsonBuilder.create(); String json = gson.toJson(note); FileObject rootDir = getRootDir(); FileObject noteDir = rootDir.resolveFile(note.id(), NameScope.CHILD); if (!noteDir.exists()) { noteDir.createFolder(); } if (!isDirectory(noteDir)) { throw new IOException(noteDir.getName().toString() + " is not a directory"); } FileObject noteJson = noteDir.resolveFile(".note.json", NameScope.CHILD); OutputStream out = noteJson.getContent().getOutputStream(false); out.write(json.getBytes(conf.getString(ConfVars.ZEPPELIN_ENCODING))); out.close(); noteJson.moveTo(noteDir.resolveFile("note.json", NameScope.CHILD)); } VFSNotebookRepo(ZeppelinConfiguration conf); @Override List<NoteInfo> list(AuthenticationInfo subject); @Override Note get(String noteId, AuthenticationInfo subject); @Override synchronized void save(Note note, AuthenticationInfo subject); @Override void remove(String noteId, AuthenticationInfo subject); @Override void close(); @Override Revision checkpoint(String noteId, String checkpointMsg, AuthenticationInfo subject); @Override Note get(String noteId, Revision rev, AuthenticationInfo subject); @Override List<Revision> revisionHistory(String noteId, AuthenticationInfo subject);  }
@Test public void testSaveNotebook() throws IOException, InterruptedException { Note note = notebook.createNote(null); note.getNoteReplLoader().setInterpreters(factory.getDefaultInterpreterSettingList()); Paragraph p1 = note.addParagraph(); Map<String, Object> config = p1.getConfig(); config.put("enabled", true); p1.setConfig(config); p1.setText("%mock1 hello world"); note.run(p1.getId()); int timeout = 1; while (!p1.isTerminated()) { Thread.sleep(1000); if (timeout++ > 10) { break; } } int i = 0; int TEST_COUNT = 10; while (i++ < TEST_COUNT) { p1.setText("%mock1 hello zeppelin"); new Thread(new NotebookWriter(note)).start(); p1.setText("%mock1 hello world"); new Thread(new NotebookWriter(note)).start(); } note.setName("SaveTest"); notebookRepo.save(note, null); assertEquals(note.getName(), "SaveTest"); }