Notebook { public Note createNote(AuthenticationInfo subject) throws IOException { Note note; if (conf.getBoolean(ConfVars.ZEPPELIN_NOTEBOOK_AUTO_INTERPRETER_BINDING)) { note = createNote(replFactory.getDefaultInterpreterSettingList(), subject); } else { note = createNote(null, subject); } notebookIndex.addIndexDoc(note); return note; } Notebook(ZeppelinConfiguration conf, NotebookRepo notebookRepo,
      SchedulerFactory schedulerFactory,
      InterpreterFactory replFactory, JobListenerFactory jobListenerFactory,
      SearchService notebookIndex,
      NotebookAuthorization notebookAuthorization,
      Credentials credentials); Note createNote(AuthenticationInfo subject); Note createNote(List<String> interpreterIds, AuthenticationInfo subject); String exportNote(String noteId); Note importNote(String sourceJson, String noteName, AuthenticationInfo subject); Note cloneNote(String sourceNoteID, String newNoteName, AuthenticationInfo subject); void bindInterpretersToNote(String id,
      List<String> interpreterSettingIds); List<String> getBindedInterpreterSettingsIds(String id); List<InterpreterSetting> getBindedInterpreterSettings(String id); Note getNote(String id); void removeNote(String id, AuthenticationInfo subject); void checkpointNote(String noteId, String checkpointMessage, AuthenticationInfo subject); void reloadAllNotes(AuthenticationInfo subject); List<Note> getAllNotes(); JobListenerFactory getJobListenerFactory(); void setJobListenerFactory(JobListenerFactory jobListenerFactory); List<Map<String, Object>> getJobListforNotebook(boolean needsReload,
      long lastUpdateServerUnixTime, AuthenticationInfo subject); void refreshCron(String id); InterpreterFactory getInterpreterFactory(); NotebookAuthorization getNotebookAuthorization(); ZeppelinConfiguration getConf(); void close();  }
@Test public void testSelectingReplImplementation() throws IOException { Note note = notebook.createNote(null); note.getNoteReplLoader().setInterpreters(factory.getDefaultInterpreterSettingList()); Paragraph p1 = note.addParagraph(); Map config = p1.getConfig(); config.put("enabled", true); p1.setConfig(config); p1.setText("hello world"); note.run(p1.getId()); while(p1.isTerminated()==false || p1.getResult()==null) Thread.yield(); assertEquals("repl1: hello world", p1.getResult().message()); Paragraph p2 = note.addParagraph(); p2.setConfig(config); p2.setText("%mock2 hello world"); note.run(p2.getId()); while(p2.isTerminated()==false || p2.getResult()==null) Thread.yield(); assertEquals("repl2: hello world", p2.getResult().message()); }
@Test public void testClearParagraphOutput() throws IOException, SchedulerException{ Note note = notebook.createNote(null); Paragraph p1 = note.addParagraph(); Map config = p1.getConfig(); config.put("enabled", true); p1.setConfig(config); p1.setText("hello world"); note.run(p1.getId()); while(p1.isTerminated()==false || p1.getResult()==null) Thread.yield(); assertEquals("repl1: hello world", p1.getResult().message()); note.clearParagraphOutput(p1.getId()); assertNull(p1.getResult()); }
@Test public void testAngularObjectRemovalOnParagraphRemove() throws InterruptedException, IOException { Note note = notebook.createNote(null); note.getNoteReplLoader().setInterpreters(factory.getDefaultInterpreterSettingList()); AngularObjectRegistry registry = note.getNoteReplLoader() .getInterpreterSettings().get(0).getInterpreterGroup("sharedProcess") .getAngularObjectRegistry(); Paragraph p1 = note.addParagraph(); registry.add("o1", "object1", note.id(), p1.getId()); registry.add("o2", "object2", note.id(), null); registry.add("o3", "object3", null, null); note.removeParagraph(p1.getId()); assertNull(registry.get("o1", note.id(), null)); assertNotNull(registry.get("o2", note.id(), null)); assertNotNull(registry.get("o3", null, null)); }
@Test public void testAbortParagraphStatusOnInterpreterRestart() throws InterruptedException, IOException { Note note = notebook.createNote(null); note.getNoteReplLoader().setInterpreters(factory.getDefaultInterpreterSettingList()); ArrayList<Paragraph> paragraphs = new ArrayList<>(); for (int i = 0; i < 100; i++) { Paragraph tmp = note.addParagraph(); tmp.setText("p" + tmp.getId()); paragraphs.add(tmp); } for (Paragraph p : paragraphs) { assertEquals(Job.Status.READY, p.getStatus()); } note.runAll(); while (paragraphs.get(0).getStatus() != Status.FINISHED) Thread.yield(); factory.restart(note.getNoteReplLoader().getInterpreterSettings().get(0).id()); boolean isAborted = false; for (Paragraph p : paragraphs) { logger.debug(p.getStatus().name()); if (isAborted) { assertEquals(Job.Status.ABORT, p.getStatus()); } if (p.getStatus() == Status.ABORT) { isAborted = true; } } assertTrue(isAborted); }