use of org.apache.zeppelin.notebook.Notebook in project zeppelin by apache.
the class NotebookServerTest method unbindAngularObjectFromRemoteForParagraphs.
@Test
public void unbindAngularObjectFromRemoteForParagraphs() throws Exception {
// Given
final String varName = "name";
final String value = "val";
final Message messageReceived = new Message(OP.ANGULAR_OBJECT_CLIENT_UNBIND).put("noteId", "noteId").put("name", varName).put("paragraphId", "paragraphId");
try {
final Notebook notebook = mock(Notebook.class);
notebookServer.setNotebook(() -> notebook);
notebookServer.setNotebookService(() -> notebookService);
final Note note = mock(Note.class, RETURNS_DEEP_STUBS);
when(notebook.processNote(eq("noteId"), Mockito.any())).then(e -> e.getArgumentAt(1, NoteProcessor.class).process(note));
final Paragraph paragraph = mock(Paragraph.class, RETURNS_DEEP_STUBS);
when(note.getParagraph("paragraphId")).thenReturn(paragraph);
final RemoteAngularObjectRegistry mdRegistry = mock(RemoteAngularObjectRegistry.class);
final InterpreterGroup mdGroup = new InterpreterGroup("mdGroup");
mdGroup.setAngularObjectRegistry(mdRegistry);
when(paragraph.getBindedInterpreter().getInterpreterGroup()).thenReturn(mdGroup);
final AngularObject<String> ao1 = AngularObjectBuilder.build(varName, value, "noteId", "paragraphId");
when(mdRegistry.removeAndNotifyRemoteProcess(varName, "noteId", "paragraphId")).thenReturn(ao1);
NotebookSocket conn = mock(NotebookSocket.class);
NotebookSocket otherConn = mock(NotebookSocket.class);
final String mdMsg1 = notebookServer.serializeMessage(new Message(OP.ANGULAR_OBJECT_REMOVE).put("angularObject", ao1).put("interpreterGroupId", "mdGroup").put("noteId", "noteId").put("paragraphId", "paragraphId"));
notebookServer.getConnectionManager().noteSocketMap.put("noteId", asList(conn, otherConn));
// When
notebookServer.angularObjectClientUnbind(conn, messageReceived);
// Then
verify(mdRegistry, never()).removeAndNotifyRemoteProcess(varName, "noteId", null);
verify(otherConn).send(mdMsg1);
} finally {
// reset these so that it won't affect other tests
notebookServer.setNotebook(() -> NotebookServerTest.notebook);
notebookServer.setNotebookService(() -> NotebookServerTest.notebookService);
}
}
use of org.apache.zeppelin.notebook.Notebook in project zeppelin by apache.
the class ZeppelinClientWithAuthIntegrationTest method setUp.
@BeforeClass
public static void setUp() throws Exception {
System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_HELIUM_REGISTRY.getVarName(), "helium");
System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_ALLOWED_ORIGINS.getVarName(), "*");
AbstractTestRestApi.startUpWithAuthenticationEnable(ZeppelinClientWithAuthIntegrationTest.class.getSimpleName());
notebook = TestUtils.getInstance(Notebook.class);
clientConfig = new ClientConfig("http://localhost:8080");
zeppelinClient = new ZeppelinClient(clientConfig);
}
use of org.apache.zeppelin.notebook.Notebook in project zeppelin by apache.
the class NotebookRepoSyncTest method testOneWaySyncOnReloadedList.
@Test
public void testOneWaySyncOnReloadedList() throws IOException, SchedulerException {
System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_DIR.getVarName(), mainNotebookDir.getAbsolutePath());
System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_ONE_WAY_SYNC.getVarName(), "true");
conf = ZeppelinConfiguration.create();
notebookRepoSync = new NotebookRepoSync(conf);
notebook = new Notebook(conf, mock(AuthorizationService.class), notebookRepoSync, new NoteManager(notebookRepoSync, conf), factory, interpreterSettingManager, credentials, null);
// check that both storage repos are empty
assertTrue(notebookRepoSync.getRepoCount() > 1);
assertEquals(0, notebookRepoSync.list(0, null).size());
assertEquals(0, notebookRepoSync.list(1, null).size());
File srcDir = new File("src/test/resources/notebook");
File destDir = secNotebookDir;
/* copy manually new notebook into secondary storage repo and check repos */
try {
FileUtils.copyDirectory(srcDir, destDir);
} catch (IOException e) {
LOG.error(e.toString(), e);
}
assertEquals(0, notebookRepoSync.list(0, null).size());
assertEquals(2, notebookRepoSync.list(1, null).size());
// after reloading the notebook should be wiped from secondary storage
notebook.reloadAllNotes(null);
assertEquals(0, notebookRepoSync.list(0, null).size());
assertEquals(0, notebookRepoSync.list(1, null).size());
destDir = mainNotebookDir;
// copy manually new notebook into primary storage repo and check repos
try {
FileUtils.copyDirectory(srcDir, destDir);
} catch (IOException e) {
LOG.error(e.toString(), e);
}
assertEquals(2, notebookRepoSync.list(0, null).size());
assertEquals(0, notebookRepoSync.list(1, null).size());
// after reloading notebooks repos should be synchronized
notebook.reloadAllNotes(null);
assertEquals(2, notebookRepoSync.list(0, null).size());
assertEquals(2, notebookRepoSync.list(1, null).size());
}
use of org.apache.zeppelin.notebook.Notebook in project zeppelin by apache.
the class ZeppelinRestApiTest method testListNotes.
@Test
public void testListNotes() throws IOException {
LOG.info("testListNotes");
CloseableHttpResponse get = httpGet("/notebook/");
assertThat("List notes method", get, isAllowed());
Map<String, Object> resp = gson.fromJson(EntityUtils.toString(get.getEntity(), StandardCharsets.UTF_8), new TypeToken<Map<String, Object>>() {
}.getType());
List<Map<String, String>> body = (List<Map<String, String>>) resp.get("body");
// TODO(khalid): anonymous or specific user notes?
HashSet<String> anonymous = new HashSet<>(Arrays.asList("anonymous"));
AuthorizationService authorizationService = TestUtils.getInstance(AuthorizationService.class);
assertEquals("List notes are equal", TestUtils.getInstance(Notebook.class).getNotesInfo(noteId -> authorizationService.isReader(noteId, anonymous)).size(), body.size());
get.close();
}
use of org.apache.zeppelin.notebook.Notebook in project zeppelin by apache.
the class ZeppelinRestApiTest method testRegressionZEPPELIN_527.
@Test
public void testRegressionZEPPELIN_527() throws Exception {
String noteId = null;
try {
noteId = TestUtils.getInstance(Notebook.class).createNote("note1_testRegressionZEPPELIN_527", anonymous);
// use write lock because name is overwritten
TestUtils.getInstance(Notebook.class).processNote(noteId, note -> {
note.setName("note for run test");
Paragraph paragraph = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
paragraph.setText("%spark\nval param = z.input(\"param\").toString\nprintln(param)");
return null;
});
TestUtils.getInstance(Notebook.class).processNote(noteId, note -> {
try {
note.runAll(AuthenticationInfo.ANONYMOUS, true, false, new HashMap<>());
TestUtils.getInstance(Notebook.class).saveNote(note, anonymous);
} catch (Exception e) {
fail();
}
return null;
});
CloseableHttpResponse getNoteJobs = httpGet("/notebook/job/" + noteId);
assertThat("test note jobs run:", getNoteJobs, isAllowed());
Map<String, Object> resp = gson.fromJson(EntityUtils.toString(getNoteJobs.getEntity(), StandardCharsets.UTF_8), new TypeToken<Map<String, Object>>() {
}.getType());
NoteJobStatus noteJobStatus = NoteJobStatus.fromJson(gson.toJson(resp.get("body")));
assertNotNull(noteJobStatus.getParagraphJobStatusList().get(0).getStarted());
assertNotNull(noteJobStatus.getParagraphJobStatusList().get(0).getFinished());
getNoteJobs.close();
} finally {
// cleanup
if (null != noteId) {
TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous);
}
}
}
Aggregations