VFSNotebookRepo implements NotebookRepo { @Override public synchronized void save(Note note) 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(); @Override Note get(String noteId); @Override synchronized void save(Note note); @Override void remove(String noteId); @Override void close();  }
@Test public void testSaveNotebook() throws IOException, InterruptedException { Note note = notebook.createNote(); 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); assertEquals(note.getName(), "SaveTest"); }