use of org.apache.zeppelin.interpreter.Interpreter in project zeppelin by apache.
the class RemoteInterpreterTest method testEnvironmentAndProperty.
@Test
public void testEnvironmentAndProperty() throws InterpreterException {
interpreterSetting.getOption().setPerUser(InterpreterOption.SHARED);
interpreterSetting.setProperty("ENV_1", "VALUE_1");
interpreterSetting.setProperty("property_1", "value_1");
final Interpreter interpreter1 = interpreterSetting.getInterpreter("user1", note1Id, "get");
final InterpreterContext context1 = createDummyInterpreterContext();
assertEquals("VALUE_1", interpreter1.interpret("getEnv ENV_1", context1).message().get(0).getData());
assertEquals("null", interpreter1.interpret("getEnv ENV_2", context1).message().get(0).getData());
assertEquals("value_1", interpreter1.interpret("getProperty property_1", context1).message().get(0).getData());
assertEquals("null", interpreter1.interpret("getProperty not_existed_property", context1).message().get(0).getData());
}
use of org.apache.zeppelin.interpreter.Interpreter in project zeppelin by apache.
the class RemoteInterpreterTest method testIsolatedMode.
@Test
public void testIsolatedMode() throws InterpreterException, IOException {
interpreterSetting.getOption().setPerUser(InterpreterOption.ISOLATED);
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());
assertNotEquals(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());
assertNull(remoteInterpreter1.getInterpreterGroup().getRemoteInterpreterProcess());
assertTrue(remoteInterpreter2.getInterpreterGroup().getRemoteInterpreterProcess().isRunning());
InterpreterResult result = remoteInterpreter1.interpret("hello", context1);
assertEquals(Code.ERROR, result.code());
assertEquals("Interpreter process is not running\n", result.message().get(0).getData());
assertEquals("hello", remoteInterpreter2.interpret("hello", context1).message().get(0).getData());
remoteInterpreter2.getInterpreterGroup().close(remoteInterpreter2.getSessionId());
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 testRemoteInterpreterSharesTheSameSchedulerInstanceInTheSameGroup.
@Test
public void testRemoteInterpreterSharesTheSameSchedulerInstanceInTheSameGroup() {
interpreterSetting.getOption().setPerUser(InterpreterOption.SHARED);
Interpreter interpreter1 = interpreterSetting.getInterpreter("user1", note1Id, "sleep");
Interpreter interpreter2 = interpreterSetting.getInterpreter("user1", note1Id, "echo");
assertEquals(interpreter1.getInterpreterGroup(), interpreter2.getInterpreterGroup());
assertEquals(interpreter1.getScheduler(), interpreter2.getScheduler());
}
use of org.apache.zeppelin.interpreter.Interpreter in project zeppelin by apache.
the class RemoteInterpreterTest method testFailToLaunchInterpreterProcess_InvalidRunner.
@Test
public void testFailToLaunchInterpreterProcess_InvalidRunner() {
try {
System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETER_REMOTE_RUNNER.getVarName(), "invalid_runner");
final Interpreter interpreter1 = interpreterSetting.getInterpreter("user1", note1Id, "sleep");
final InterpreterContext context1 = createDummyInterpreterContext();
// time overhead of launching the process.
try {
interpreter1.interpret("1", context1);
fail("Should not be able to launch interpreter process");
} catch (InterpreterException e) {
assertTrue(ExceptionUtils.getStackTrace(e).contains("java.io.IOException"));
}
} finally {
System.clearProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETER_REMOTE_RUNNER.getVarName());
}
}
use of org.apache.zeppelin.interpreter.Interpreter in project zeppelin by apache.
the class RemoteInterpreterTest method testParallelScheduler.
@Test
public void testParallelScheduler() throws InterruptedException, InterpreterException {
interpreterSetting.getOption().setPerUser(InterpreterOption.SHARED);
interpreterSetting.setProperty("zeppelin.SleepInterpreter.parallel", "true");
final Interpreter interpreter1 = interpreterSetting.getInterpreter("user1", note1Id, "sleep");
final InterpreterContext context1 = createDummyInterpreterContext();
// run this dummy interpret method first to launch the RemoteInterpreterProcess to avoid the
// time overhead of launching the process.
interpreter1.interpret("1", context1);
Thread thread1 = new Thread() {
@Override
public void run() {
try {
assertEquals(Code.SUCCESS, interpreter1.interpret("100", context1).code());
} catch (InterpreterException e) {
e.printStackTrace();
fail();
}
}
};
Thread thread2 = new Thread() {
@Override
public void run() {
try {
assertEquals(Code.SUCCESS, interpreter1.interpret("100", context1).code());
} catch (InterpreterException e) {
e.printStackTrace();
fail();
}
}
};
long start = System.currentTimeMillis();
thread1.start();
thread2.start();
thread1.join();
thread2.join();
long end = System.currentTimeMillis();
assertTrue((end - start) <= 200);
}
Aggregations