Notebook { public Note createNote(String notePath, AuthenticationInfo subject) throws IOException { return createNote(notePath, interpreterSettingManager.getDefaultInterpreterSetting().getName(), subject); } Notebook(
      ZeppelinConfiguration conf,
      AuthorizationService authorizationService,
      NotebookRepo notebookRepo,
      NoteManager noteManager,
      InterpreterFactory replFactory,
      InterpreterSettingManager interpreterSettingManager,
      SearchService noteSearchService,
      Credentials credentials); @Inject  Notebook(
      ZeppelinConfiguration conf,
      AuthorizationService authorizationService,
      NotebookRepo notebookRepo,
      NoteManager noteManager,
      InterpreterFactory replFactory,
      InterpreterSettingManager interpreterSettingManager,
      SearchService noteSearchService,
      Credentials credentials,
      NoteEventListener noteEventListener); void recoveryIfNecessary(); NoteManager getNoteManager(); void setParagraphJobListener(ParagraphJobListener paragraphJobListener); Note createNote(String notePath,
                         AuthenticationInfo subject); Note createNote(String notePath,
                         AuthenticationInfo subject,
                         boolean save); Note createNote(String notePath,
                         String defaultInterpreterGroup,
                         AuthenticationInfo subject); Note createNote(String notePath,
                         String defaultInterpreterGroup,
                         AuthenticationInfo subject,
                         boolean save); String exportNote(String noteId); Note importNote(String sourceJson, String notePath, AuthenticationInfo subject); Note cloneNote(String sourceNoteId, String newNotePath, AuthenticationInfo subject); void removeNote(Note note, AuthenticationInfo subject); Note getNote(String noteId); Note getNote(String noteId, boolean reload); void saveNote(Note note, AuthenticationInfo subject); boolean containsNote(String notePath); boolean containsFolder(String folderPath); void moveNote(String noteId, String newNotePath, AuthenticationInfo subject); void moveFolder(String folderPath, String newFolderPath, AuthenticationInfo subject); void removeFolder(String folderPath, AuthenticationInfo subject); void emptyTrash(AuthenticationInfo subject); void restoreAll(AuthenticationInfo subject); Revision checkpointNote(String noteId, String notePath, String checkpointMessage,
      AuthenticationInfo subject); List<Revision> listRevisionHistory(String noteId,
                                            String notePath,
                                            AuthenticationInfo subject); Note setNoteRevision(String noteId, String notePath, String revisionId, AuthenticationInfo subject); Note getNoteByRevision(String noteId, String noteName,
                                String revisionId, AuthenticationInfo subject); @SuppressWarnings("rawtypes") Note loadNoteFromRepo(String id, AuthenticationInfo subject); void reloadAllNotes(AuthenticationInfo subject); List<NoteInfo> getNotesInfo(); Stream<Note> getNoteStream(); @VisibleForTesting List<Note> getAllNotes(Function<Note, Boolean> func); @VisibleForTesting List<Note> getAllNotes(); List<NoteInfo> getNotesInfo(Function<String, Boolean> func); List<InterpreterSetting> getBindedInterpreterSettings(String noteId); InterpreterFactory getInterpreterFactory(); InterpreterSettingManager getInterpreterSettingManager(); ZeppelinConfiguration getConf(); void close(); void addNotebookEventListener(NoteEventListener listener); Boolean isRevisionSupported();  }
@Test public void testSchedulePoolUsage() throws InterruptedException, IOException { final int timeout = 30; final String everySecondCron = "* * * * * ?"; final CountDownLatch jobsToExecuteCount = new CountDownLatch(13); final Note note = notebook.createNote("note1", anonymous); executeNewParagraphByCron(note, everySecondCron); afterStatusChangedListener = new StatusChangedListener() { @Override public void onStatusChanged(Job job, Status before, Status after) { if (after == Status.FINISHED) { jobsToExecuteCount.countDown(); } } }; assertTrue(jobsToExecuteCount.await(timeout, TimeUnit.SECONDS)); terminateScheduledNote(note); afterStatusChangedListener = null; }
@Test public void testScheduleDisabled() throws InterruptedException, IOException { System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_CRON_ENABLE.getVarName(), "false"); try { final int timeout = 10; final String everySecondCron = "* * * * * ?"; final CountDownLatch jobsToExecuteCount = new CountDownLatch(5); final Note note = notebook.createNote("note1", anonymous); executeNewParagraphByCron(note, everySecondCron); afterStatusChangedListener = new StatusChangedListener() { @Override public void onStatusChanged(Job job, Status before, Status after) { if (after == Status.FINISHED) { jobsToExecuteCount.countDown(); } } }; assertFalse(jobsToExecuteCount.await(timeout, TimeUnit.SECONDS)); terminateScheduledNote(note); afterStatusChangedListener = null; } finally { System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_CRON_ENABLE.getVarName(), "true"); } }
@Test public void testScheduleDisabledWithName() throws InterruptedException, IOException { System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_CRON_FOLDERS.getVarName(), "/System"); try { final int timeout = 10; final String everySecondCron = "* * * * * ?"; final CountDownLatch jobsToExecuteCount = new CountDownLatch(5); final Note note = notebook.createNote("note1", anonymous); executeNewParagraphByCron(note, everySecondCron); afterStatusChangedListener = new StatusChangedListener() { @Override public void onStatusChanged(Job job, Status before, Status after) { if (after == Status.FINISHED) { jobsToExecuteCount.countDown(); } } }; assertFalse(jobsToExecuteCount.await(timeout, TimeUnit.SECONDS)); terminateScheduledNote(note); afterStatusChangedListener = null; final Note noteNameSystem = notebook.createNote("/System/test1", anonymous); final CountDownLatch jobsToExecuteCountNameSystem = new CountDownLatch(5); executeNewParagraphByCron(noteNameSystem, everySecondCron); afterStatusChangedListener = new StatusChangedListener() { @Override public void onStatusChanged(Job job, Status before, Status after) { if (after == Status.FINISHED) { jobsToExecuteCountNameSystem.countDown(); } } }; assertTrue(jobsToExecuteCountNameSystem.await(timeout, TimeUnit.SECONDS)); terminateScheduledNote(noteNameSystem); afterStatusChangedListener = null; } finally { System.clearProperty(ConfVars.ZEPPELIN_NOTEBOOK_CRON_FOLDERS.getVarName()); } }
@Test public void testCloneImportCheck() throws IOException { Note sourceNote = notebook.createNote("note1", new AuthenticationInfo("user")); sourceNote.setName("TestNote"); assertEquals("TestNote",sourceNote.getName()); Paragraph sourceParagraph = sourceNote.addNewParagraph(AuthenticationInfo.ANONYMOUS); assertEquals("anonymous", sourceParagraph.getUser()); Note destNote = notebook.createNote("note2", new AuthenticationInfo("user")); destNote.setName("ClonedNote"); assertEquals("ClonedNote",destNote.getName()); List<Paragraph> paragraphs = sourceNote.getParagraphs(); for (Paragraph p : paragraphs) { destNote.addCloneParagraph(p, AuthenticationInfo.ANONYMOUS); assertEquals("anonymous", p.getUser()); } }