Notebook { public Note createNote() throws IOException { Note note; if (conf.getBoolean(ConfVars.ZEPPELIN_NOTEBOOK_AUTO_INTERPRETER_BINDING)) { note = createNote(replFactory.getDefaultInterpreterSettingList()); } else { note = createNote(null); } notebookIndex.addIndexDoc(note); return note; } Notebook(ZeppelinConfiguration conf, NotebookRepo notebookRepo,
      SchedulerFactory schedulerFactory,
      InterpreterFactory replFactory, JobListenerFactory jobListenerFactory,
      SearchService notebookIndex); Note createNote(); Note createNote(List<String> interpreterIds); Note cloneNote(String sourceNoteID, String newNoteName); 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); void reloadAllNotes(); List<Note> getAllNotes(); JobListenerFactory getJobListenerFactory(); void setJobListenerFactory(JobListenerFactory jobListenerFactory); void refreshCron(String id); InterpreterFactory getInterpreterFactory(); ZeppelinConfiguration getConf(); void close();  }
@Test public void testSelectingReplImplementation() throws IOException { Note note = notebook.createNote(); 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(); 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 testRunAll() throws IOException { Note note = notebook.createNote(); note.getNoteReplLoader().setInterpreters(factory.getDefaultInterpreterSettingList()); Paragraph p1 = note.addParagraph(); Map config = p1.getConfig(); config.put("enabled", true); p1.setConfig(config); p1.setText("p1"); Paragraph p2 = note.addParagraph(); Map config1 = p2.getConfig(); p2.setConfig(config1); p2.setText("p2"); assertEquals(null, p2.getResult()); note.runAll(); while(p2.isTerminated()==false || p2.getResult()==null) Thread.yield(); assertEquals("repl1: p2", p2.getResult().message()); }
@Test public void testAbortParagraphStatusOnInterpreterRestart() throws InterruptedException, IOException { Note note = notebook.createNote(); 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); }