use of org.apache.zeppelin.interpreter.ManagedInterpreterGroup in project zeppelin by apache.
the class ParagraphTest method returnUnchangedResultsWithDifferentUser.
@Ignore
public void returnUnchangedResultsWithDifferentUser() throws Throwable {
Note mockNote = mock(Note.class);
when(mockNote.getCredentials()).thenReturn(mock(Credentials.class));
Paragraph spyParagraph = spy(new Paragraph("para_1", mockNote, null));
Interpreter mockInterpreter = mock(Interpreter.class);
spyParagraph.setInterpreter(mockInterpreter);
doReturn(mockInterpreter).when(spyParagraph).getBindedInterpreter();
ManagedInterpreterGroup mockInterpreterGroup = mock(ManagedInterpreterGroup.class);
when(mockInterpreter.getInterpreterGroup()).thenReturn(mockInterpreterGroup);
when(mockInterpreterGroup.getId()).thenReturn("mock_id_1");
when(mockInterpreterGroup.getAngularObjectRegistry()).thenReturn(mock(AngularObjectRegistry.class));
when(mockInterpreterGroup.getResourcePool()).thenReturn(mock(ResourcePool.class));
List<InterpreterSetting> spyInterpreterSettingList = spy(new ArrayList<>());
InterpreterSetting mockInterpreterSetting = mock(InterpreterSetting.class);
when(mockInterpreterGroup.getInterpreterSetting()).thenReturn(mockInterpreterSetting);
InterpreterOption mockInterpreterOption = mock(InterpreterOption.class);
when(mockInterpreterSetting.getOption()).thenReturn(mockInterpreterOption);
when(mockInterpreterOption.permissionIsSet()).thenReturn(false);
when(mockInterpreterSetting.getStatus()).thenReturn(Status.READY);
when(mockInterpreterSetting.getId()).thenReturn("mock_id_1");
when(mockInterpreterSetting.getOrCreateInterpreterGroup(anyString(), anyString())).thenReturn(mockInterpreterGroup);
when(mockInterpreterSetting.isUserAuthorized(any(List.class))).thenReturn(true);
spyInterpreterSettingList.add(mockInterpreterSetting);
when(mockNote.getId()).thenReturn("any_id");
when(mockInterpreter.getFormType()).thenReturn(FormType.NONE);
ParagraphJobListener mockJobListener = mock(ParagraphJobListener.class);
doReturn(mockJobListener).when(spyParagraph).getListener();
InterpreterResult mockInterpreterResult = mock(InterpreterResult.class);
when(mockInterpreter.interpret(anyString(), Mockito.<InterpreterContext>any())).thenReturn(mockInterpreterResult);
when(mockInterpreterResult.code()).thenReturn(Code.SUCCESS);
// Actual test
List<InterpreterResultMessage> result1 = new ArrayList<>();
result1.add(new InterpreterResultMessage(Type.TEXT, "result1"));
when(mockInterpreterResult.message()).thenReturn(result1);
AuthenticationInfo user1 = new AuthenticationInfo("user1");
spyParagraph.setAuthenticationInfo(user1);
spyParagraph.jobRun();
Paragraph p1 = spyParagraph.getUserParagraph(user1.getUser());
mockInterpreterResult = mock(InterpreterResult.class);
when(mockInterpreter.interpret(anyString(), Mockito.<InterpreterContext>any())).thenReturn(mockInterpreterResult);
when(mockInterpreterResult.code()).thenReturn(Code.SUCCESS);
List<InterpreterResultMessage> result2 = new ArrayList<>();
result2.add(new InterpreterResultMessage(Type.TEXT, "result2"));
when(mockInterpreterResult.message()).thenReturn(result2);
AuthenticationInfo user2 = new AuthenticationInfo("user2");
spyParagraph.setAuthenticationInfo(user2);
spyParagraph.jobRun();
Paragraph p2 = spyParagraph.getUserParagraph(user2.getUser());
assertNotEquals(p1.getReturn().toString(), p2.getReturn().toString());
assertEquals(p1, spyParagraph.getUserParagraph(user1.getUser()));
}
use of org.apache.zeppelin.interpreter.ManagedInterpreterGroup in project zeppelin by apache.
the class RecoveryTest method testRecovery_2.
@Test
public void testRecovery_2() throws Exception {
LOG.info("Test testRecovery_2");
String note1Id = null;
try {
note1Id = notebook.createNote("note2", AuthenticationInfo.ANONYMOUS);
// run python interpreter and create new variable `user`
notebook.processNote(note1Id, note1 -> {
Paragraph p1 = note1.addNewParagraph(AuthenticationInfo.ANONYMOUS);
p1.setText("%python user='abc'");
return null;
});
CloseableHttpResponse post = httpPost("/notebook/job/" + note1Id + "?blocking=true", "");
assertThat(post, isAllowed());
Map<String, Object> resp = gson.fromJson(EntityUtils.toString(post.getEntity(), StandardCharsets.UTF_8), new TypeToken<Map<String, Object>>() {
}.getType());
assertEquals("OK", resp.get("status"));
post.close();
notebook.processNote(note1Id, note1 -> {
Paragraph p1 = note1.getParagraph(0);
assertEquals(Job.Status.FINISHED, p1.getStatus());
TestUtils.getInstance(Notebook.class).saveNote(note1, AuthenticationInfo.ANONYMOUS);
// restart the python interpreter
try {
TestUtils.getInstance(Notebook.class).getInterpreterSettingManager().restart(((ManagedInterpreterGroup) p1.getBindedInterpreter().getInterpreterGroup()).getInterpreterSetting().getId());
} catch (InterpreterException e) {
fail();
}
return null;
});
// shutdown zeppelin and restart it
shutDown();
startUp(RecoveryTest.class.getSimpleName(), false);
Thread.sleep(5 * 1000);
// run the paragraph again, but change the text to print variable `user`.
// can not recover the python interpreter, because it has been shutdown.
TestUtils.getInstance(Notebook.class).processNote(note1Id, note1 -> {
Paragraph p1 = note1.getParagraph(0);
p1.setText("%python print(user)");
return null;
});
post = httpPost("/notebook/job/" + note1Id + "?blocking=true", "");
assertEquals("OK", resp.get("status"));
post.close();
TestUtils.getInstance(Notebook.class).processNote(note1Id, note1 -> {
Paragraph p1 = note1.getParagraph(0);
assertEquals(Job.Status.ERROR, p1.getStatus());
return null;
});
} catch (Exception e) {
LOG.error(e.toString(), e);
throw e;
} finally {
if (null != note1Id) {
TestUtils.getInstance(Notebook.class).removeNote(note1Id, anonymous);
}
}
}
Aggregations