use of org.apache.zeppelin.interpreter.Interpreter in project zeppelin by apache.
the class RemoteInterpreterTest method testScopedMode.
@Test
public void testScopedMode() throws InterpreterException, IOException {
interpreterSetting.getOption().setPerUser(InterpreterOption.SCOPED);
Interpreter interpreter1 = interpreterSetting.getDefaultInterpreter("user1", note1Id);
Interpreter interpreter2 = interpreterSetting.getDefaultInterpreter("user2", note1Id);
assertTrue(interpreter1 instanceof RemoteInterpreter);
RemoteInterpreter remoteInterpreter1 = (RemoteInterpreter) interpreter1;
assertTrue(interpreter2 instanceof RemoteInterpreter);
RemoteInterpreter remoteInterpreter2 = (RemoteInterpreter) interpreter2;
assertNotEquals(interpreter1.getScheduler(), interpreter2.getScheduler());
InterpreterContext context1 = createDummyInterpreterContext();
assertEquals("hello", remoteInterpreter1.interpret("hello", context1).message().get(0).getData());
assertEquals("hello", remoteInterpreter2.interpret("hello", context1).message().get(0).getData());
assertEquals(Interpreter.FormType.NATIVE, interpreter1.getFormType());
assertEquals(0, remoteInterpreter1.getProgress(context1));
assertNotNull(remoteInterpreter1.getOrCreateInterpreterProcess());
assertTrue(remoteInterpreter1.getInterpreterGroup().getRemoteInterpreterProcess().isRunning());
assertEquals(remoteInterpreter1.getInterpreterGroup().getRemoteInterpreterProcess(), remoteInterpreter2.getInterpreterGroup().getRemoteInterpreterProcess());
// Call InterpreterGroup.close instead of Interpreter.close, otherwise we will have the
// RemoteInterpreterProcess leakage.
remoteInterpreter1.getInterpreterGroup().close(remoteInterpreter1.getSessionId());
try {
assertEquals("hello", remoteInterpreter1.interpret("hello", context1).message().get(0).getData());
fail("Should not be able to call interpret after interpreter is closed");
} catch (Exception e) {
e.printStackTrace();
}
assertTrue(remoteInterpreter2.getInterpreterGroup().getRemoteInterpreterProcess().isRunning());
assertEquals("hello", remoteInterpreter2.interpret("hello", context1).message().get(0).getData());
remoteInterpreter2.getInterpreterGroup().close(remoteInterpreter2.getSessionId());
InterpreterResult result = remoteInterpreter2.interpret("hello", context1);
assertEquals(Code.ERROR, result.code());
assertEquals("Interpreter process is not running\n", result.message().get(0).getData());
assertNull(remoteInterpreter2.getInterpreterGroup().getRemoteInterpreterProcess());
}
use of org.apache.zeppelin.interpreter.Interpreter in project zeppelin by apache.
the class RemoteInterpreterTest method testExecuteIncorrectPrecode.
@Test
public void testExecuteIncorrectPrecode() throws TTransportException, IOException, InterpreterException {
interpreterSetting.getOption().setPerUser(InterpreterOption.SHARED);
interpreterSetting.setProperty("zeppelin.SleepInterpreter.precode", "fail test");
Interpreter interpreter1 = interpreterSetting.getInterpreter("user1", note1Id, "sleep");
InterpreterContext context1 = createDummyInterpreterContext();
;
assertEquals(Code.ERROR, interpreter1.interpret("10", context1).code());
}
use of org.apache.zeppelin.interpreter.Interpreter in project zeppelin by apache.
the class RemoteInterpreterTest method testConvertDynamicForms.
@Test
public void testConvertDynamicForms() throws InterpreterException {
GUI gui = new GUI();
OptionInput.ParamOption[] paramOptions = { new OptionInput.ParamOption("value1", "param1"), new OptionInput.ParamOption("value2", "param2") };
List<Object> defaultValues = new ArrayList<>();
defaultValues.add("default1");
defaultValues.add("default2");
gui.checkbox("checkbox_id", paramOptions, defaultValues);
gui.select("select_id", paramOptions, "default");
gui.textbox("textbox_id");
Map<String, Input> expected = new LinkedHashMap<>(gui.getForms());
Interpreter interpreter = interpreterSetting.getDefaultInterpreter("user1", note1Id);
InterpreterContext context = createDummyInterpreterContext();
interpreter.interpret("text", context);
assertArrayEquals(expected.values().toArray(), gui.getForms().values().toArray());
}
use of org.apache.zeppelin.interpreter.Interpreter in project zeppelin by apache.
the class LocalRecoveryStorageTest method testSingleInterpreterProcess.
@Test
public void testSingleInterpreterProcess() throws InterpreterException, IOException {
InterpreterSetting interpreterSetting = interpreterSettingManager.getByName("test");
interpreterSetting.getOption().setPerUser(InterpreterOption.SHARED);
Interpreter interpreter1 = interpreterSetting.getDefaultInterpreter("user1", note1Id);
RemoteInterpreter remoteInterpreter1 = (RemoteInterpreter) interpreter1;
InterpreterContext context1 = InterpreterContext.builder().setNoteId("noteId").setParagraphId("paragraphId").build();
remoteInterpreter1.interpret("hello", context1);
assertEquals(1, interpreterSettingManager.getRecoveryStorage().restore().size());
interpreterSetting.close();
assertEquals(0, interpreterSettingManager.getRecoveryStorage().restore().size());
}
use of org.apache.zeppelin.interpreter.Interpreter in project SSM by Intel-bigdata.
the class NoteInterpreterLoaderTest method testNoteInterpreterCloseForAll.
@Test
public void testNoteInterpreterCloseForAll() throws IOException {
interpreterSettingManager.setInterpreters("user", "FitstNote", interpreterSettingManager.getDefaultInterpreterSettingList());
interpreterSettingManager.getInterpreterSettings("FitstNote").get(0).getOption().setPerNote(InterpreterOption.SCOPED);
interpreterSettingManager.setInterpreters("user", "yourFirstNote", interpreterSettingManager.getDefaultInterpreterSettingList());
interpreterSettingManager.getInterpreterSettings("yourFirstNote").get(0).getOption().setPerNote(InterpreterOption.ISOLATED);
// interpreters are not created before accessing it
assertNull(interpreterSettingManager.getInterpreterSettings("FitstNote").get(0).getInterpreterGroup("user", "FitstNote").get("FitstNote"));
assertNull(interpreterSettingManager.getInterpreterSettings("yourFirstNote").get(0).getInterpreterGroup("user", "yourFirstNote").get("yourFirstNote"));
Interpreter firstNoteIntp = factory.getInterpreter("user", "FitstNote", "group1.mock1");
Interpreter yourFirstNoteIntp = factory.getInterpreter("user", "yourFirstNote", "group1.mock1");
firstNoteIntp.open();
yourFirstNoteIntp.open();
assertTrue(((LazyOpenInterpreter) firstNoteIntp).isOpen());
assertTrue(((LazyOpenInterpreter) yourFirstNoteIntp).isOpen());
interpreterSettingManager.closeNote("user", "FitstNote");
assertFalse(((LazyOpenInterpreter) firstNoteIntp).isOpen());
assertTrue(((LazyOpenInterpreter) yourFirstNoteIntp).isOpen());
// reopen
firstNoteIntp.open();
assertTrue(((LazyOpenInterpreter) firstNoteIntp).isOpen());
assertTrue(((LazyOpenInterpreter) yourFirstNoteIntp).isOpen());
// invalid check
interpreterSettingManager.closeNote("invalid", "Note");
assertTrue(((LazyOpenInterpreter) firstNoteIntp).isOpen());
assertTrue(((LazyOpenInterpreter) yourFirstNoteIntp).isOpen());
// invalid contains value check
interpreterSettingManager.closeNote("u", "Note");
assertTrue(((LazyOpenInterpreter) firstNoteIntp).isOpen());
assertTrue(((LazyOpenInterpreter) yourFirstNoteIntp).isOpen());
}
Aggregations