use of org.apache.zeppelin.client.ParagraphResult in project zeppelin by apache.
the class ZeppelinClientIntegrationTest method testExecuteNote.
@Test
public void testExecuteNote() throws Exception {
try {
zeppelinClient.executeNote("unknown_id");
fail("Should fail to submit non-existed note");
} catch (Exception e) {
assertTrue(e.getMessage(), e.getMessage().contains("No such note"));
}
String noteId = zeppelinClient.createNote("/test/note_3");
String p0Id = zeppelinClient.addParagraph(noteId, "run sh", "%sh echo 'hello world'");
NoteResult noteResult = zeppelinClient.executeNote(noteId, new HashMap<>());
assertEquals(noteId, noteResult.getNoteId());
assertEquals(false, noteResult.isRunning());
assertEquals(1, noteResult.getParagraphResultList().size());
ParagraphResult p0 = noteResult.getParagraphResultList().get(0);
assertEquals(Status.FINISHED, p0.getStatus());
assertEquals(1, p0.getResults().size());
assertEquals("TEXT", p0.getResults().get(0).getType());
assertEquals("hello world\n", p0.getResults().get(0).getData());
// update paragraph with dynamic forms
zeppelinClient.updateParagraph(noteId, p0Id, "run sh", "%sh(form=simple) echo 'hello ${name=abc}'");
noteResult = zeppelinClient.executeNote(noteId);
assertEquals(noteId, noteResult.getNoteId());
assertEquals(false, noteResult.isRunning());
assertEquals(1, noteResult.getParagraphResultList().size());
p0 = noteResult.getParagraphResultList().get(0);
assertEquals(Status.FINISHED, p0.getStatus());
assertEquals(1, p0.getResults().size());
assertEquals("TEXT", p0.getResults().get(0).getType());
assertEquals("hello abc\n", p0.getResults().get(0).getData());
// execute paragraph with parameters
Map<String, String> parameters = new HashMap<>();
parameters.put("name", "zeppelin");
noteResult = zeppelinClient.executeNote(noteId, parameters);
assertEquals(noteId, noteResult.getNoteId());
assertEquals(false, noteResult.isRunning());
assertEquals(1, noteResult.getParagraphResultList().size());
p0 = noteResult.getParagraphResultList().get(0);
assertEquals(Status.FINISHED, p0.getStatus());
assertEquals(1, p0.getResults().size());
assertEquals("TEXT", p0.getResults().get(0).getType());
assertEquals("hello zeppelin\n", p0.getResults().get(0).getData());
zeppelinClient.addParagraph(noteId, "run sh", "%sh invalid_command");
zeppelinClient.addParagraph(noteId, "run sh", "%sh pwd");
noteResult = zeppelinClient.executeNote(noteId, parameters);
assertEquals(noteId, noteResult.getNoteId());
assertEquals(false, noteResult.isRunning());
assertEquals(3, noteResult.getParagraphResultList().size());
p0 = noteResult.getParagraphResultList().get(0);
assertEquals(Status.FINISHED, p0.getStatus());
assertEquals(1, p0.getResults().size());
assertEquals("TEXT", p0.getResults().get(0).getType());
assertEquals("hello zeppelin\n", p0.getResults().get(0).getData());
ParagraphResult p1 = noteResult.getParagraphResultList().get(1);
assertEquals(Status.ERROR, p1.getStatus());
assertEquals("TEXT", p1.getResults().get(0).getType());
assertTrue(p1.getResults().get(0).getData(), p1.getResults().get(0).getData().contains("command not found"));
assertEquals("TEXT", p1.getResults().get(1).getType());
assertTrue(p1.getResults().get(1).getData(), p1.getResults().get(1).getData().contains("ExitValue"));
// p2 will be skipped because p1 fails.
ParagraphResult p2 = noteResult.getParagraphResultList().get(2);
assertEquals(Status.READY, p2.getStatus());
assertEquals(0, p2.getResults().size());
}
Aggregations