[ZEPPELIN-2368]. Option to run all paragraphs *sequentially*

This commit is contained in:
Jeff Zhang 2017-10-08 09:08:34 +08:00
parent 86f387e940
commit f701d5b1ae
24 changed files with 194 additions and 105 deletions

View file

@ -711,7 +711,7 @@ public class ZeppelinConfiguration extends XMLConfiguration {
ZEPPELIN_INTERPRETER_LIFECYCLE_MANAGER_TIMEOUT_CHECK_INTERVAL(
"zeppelin.interpreter.lifecyclemanager.timeout.checkinterval", 6000L),
ZEPPELIN_INTERPRETER_LIFECYCLE_MANAGER_TIMEOUT_THRESHOLD(
"zeppelin.interpreter.lifecyclemanager.timeout.threshold", 360000L);
"zeppelin.interpreter.lifecyclemanager.timeout.threshold", 3600000L);
private String varName;
@SuppressWarnings("rawtypes")

View file

@ -63,6 +63,10 @@ public abstract class Job {
public boolean isPending() {
return this == PENDING;
}
public boolean isCompleted() {
return this == FINISHED || this == ERROR || this == ABORT;
}
}
private String jobName;

View file

@ -650,7 +650,7 @@ public class NotebookRestApi {
checkIfUserCanRun(noteId, "Insufficient privileges you cannot run job for this note");
try {
note.runAll(subject);
note.runAll(subject, true);
} catch (Exception ex) {
LOG.error("Exception from run", ex);
return new JsonResponse<>(Status.PRECONDITION_FAILED,

View file

@ -1678,7 +1678,10 @@ public class NotebookServer extends WebSocketServlet
Paragraph p = setParagraphUsingMessage(note, fromMessage,
paragraphId, text, title, params, config);
persistAndExecuteSingleParagraph(conn, note, p);
if (!persistAndExecuteSingleParagraph(conn, note, p, true)) {
// stop execution when one paragraph fails.
break;
}
}
}
@ -1770,7 +1773,7 @@ public class NotebookServer extends WebSocketServlet
Paragraph p = setParagraphUsingMessage(note, fromMessage, paragraphId,
text, title, params, config);
persistAndExecuteSingleParagraph(conn, note, p);
persistAndExecuteSingleParagraph(conn, note, p, false);
}
private void addNewParagraphIfLastParagraphIsExecuted(Note note, Paragraph p) {
@ -1802,15 +1805,16 @@ public class NotebookServer extends WebSocketServlet
}
}
private void persistAndExecuteSingleParagraph(NotebookSocket conn,
Note note, Paragraph p) throws IOException {
private boolean persistAndExecuteSingleParagraph(NotebookSocket conn,
Note note, Paragraph p,
boolean blocking) throws IOException {
addNewParagraphIfLastParagraphIsExecuted(note, p);
if (!persistNoteWithAuthInfo(conn, note, p)) {
return;
return false;
}
try {
note.run(p.getId());
return note.run(p.getId(), blocking);
} catch (Exception ex) {
LOG.error("Exception from run", ex);
if (p != null) {
@ -1818,6 +1822,7 @@ public class NotebookServer extends WebSocketServlet
p.setStatus(Status.ERROR);
broadcast(note.getId(), new Message(OP.PARAGRAPH).put("paragraph", p));
}
return false;
}
}

View file

@ -90,6 +90,9 @@ public abstract class AbstractTestRestApi {
"/api/version = anon\n" +
"/** = authc";
protected static File zeppelinHome;
protected static File confDir;
private String getUrl(String path) {
String url;
if (System.getProperty("url") != null) {
@ -124,10 +127,17 @@ public abstract class AbstractTestRestApi {
}
};
private static void start(boolean withAuth) throws Exception {
private static void start(boolean withAuth, String testClassName) throws Exception {
if (!wasRunning) {
System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_HOME.getVarName(), new File("../").getAbsolutePath());
// copy the resources files to a temp folder
zeppelinHome = new File("..");
LOG.info("ZEPPELIN_HOME: " + zeppelinHome.getAbsolutePath());
confDir = new File(zeppelinHome, "conf_" + testClassName);
confDir.mkdirs();
System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_HOME.getVarName(), zeppelinHome.getAbsolutePath());
System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_WAR.getVarName(), new File("../zeppelin-web/dist").getAbsolutePath());
System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_CONF_DIR.getVarName(), confDir.getAbsolutePath());
// some test profile does not build zeppelin-web.
// to prevent zeppelin starting up fail, create zeppelin-web/dist directory
@ -142,7 +152,7 @@ public abstract class AbstractTestRestApi {
System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_ANONYMOUS_ALLOWED.getVarName(), "false");
// Create a shiro env test.
shiroIni = new File("../conf/shiro.ini");
shiroIni = new File(confDir, "shiro.ini");
if (!shiroIni.exists()) {
shiroIni.createNewFile();
}
@ -245,12 +255,12 @@ public abstract class AbstractTestRestApi {
}
}
protected static void startUpWithAuthenticationEnable() throws Exception {
start(true);
protected static void startUpWithAuthenticationEnable(String testClassName) throws Exception {
start(true, testClassName);
}
protected static void startUp() throws Exception {
start(false);
protected static void startUp(String testClassName) throws Exception {
start(false, testClassName);
}
private static String getHostname() {
@ -339,6 +349,8 @@ public abstract class AbstractTestRestApi {
System
.clearProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_ANONYMOUS_ALLOWED.getVarName());
}
FileUtils.deleteDirectory(confDir);
}
}

View file

@ -36,7 +36,7 @@ public class ConfigurationsRestApiTest extends AbstractTestRestApi {
@BeforeClass
public static void init() throws Exception {
AbstractTestRestApi.startUp();
AbstractTestRestApi.startUp(ConfigurationsRestApi.class.getSimpleName());
}
@AfterClass

View file

@ -43,7 +43,7 @@ public class CredentialsRestApiTest extends AbstractTestRestApi {
@BeforeClass
public static void init() throws Exception {
AbstractTestRestApi.startUp();
AbstractTestRestApi.startUp(CredentialsRestApiTest.class.getSimpleName());
}
@AfterClass

View file

@ -39,7 +39,7 @@ public class HeliumRestApiTest extends AbstractTestRestApi {
@BeforeClass
public static void init() throws Exception {
AbstractTestRestApi.startUp();
AbstractTestRestApi.startUp(HeliumRestApi.class.getSimpleName());
}
@AfterClass

View file

@ -59,7 +59,7 @@ public class InterpreterRestApiTest extends AbstractTestRestApi {
@BeforeClass
public static void init() throws Exception {
AbstractTestRestApi.startUp();
AbstractTestRestApi.startUp(InterpreterRestApiTest.class.getSimpleName());
}
@AfterClass

View file

@ -50,7 +50,7 @@ public class NotebookRepoRestApiTest extends AbstractTestRestApi {
@BeforeClass
public static void init() throws Exception {
AbstractTestRestApi.startUp();
AbstractTestRestApi.startUp(NotebookRepoRestApiTest.class.getSimpleName());
}
@AfterClass

View file

@ -55,7 +55,7 @@ public class NotebookRestApiTest extends AbstractTestRestApi {
@BeforeClass
public static void init() throws Exception {
AbstractTestRestApi.startUp();
startUp(NotebookRestApiTest.class.getSimpleName());
}
@AfterClass
@ -120,6 +120,68 @@ public class NotebookRestApiTest extends AbstractTestRestApi {
ZeppelinServer.notebook.removeNote(note1.getId(), anonymous);
}
@Test
public void testRunAllParagraph_AllSuccess() throws IOException {
Note note1 = ZeppelinServer.notebook.createNote(anonymous);
// 2 paragraphs
// P1:
// %python
// import time
// time.sleep(1)
// user='abc'
// P2:
// %python
// from __future__ import print_function
// print(user)
//
Paragraph p1 = note1.addNewParagraph(AuthenticationInfo.ANONYMOUS);
Paragraph p2 = note1.addNewParagraph(AuthenticationInfo.ANONYMOUS);
p1.setText("%python import time\ntime.sleep(1)\nuser='abc'");
p2.setText("%python from __future__ import print_function\nprint(user)");
PostMethod post = httpPost("/notebook/job/" + note1.getId(), "");
assertThat(post, isAllowed());
Map<String, Object> resp = gson.fromJson(post.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
}.getType());
assertEquals(resp.get("status"), "OK");
post.releaseConnection();
assertEquals(Job.Status.FINISHED, p1.getStatus());
assertEquals(Job.Status.FINISHED, p2.getStatus());
assertEquals("abc\n", p2.getResult().message().get(0).getData());
}
@Test
public void testRunAllParagraph_FirstFailed() throws IOException {
Note note1 = ZeppelinServer.notebook.createNote(anonymous);
// 2 paragraphs
// P1:
// %python
// import time
// time.sleep(1)
// from __future__ import print_function
// print(user)
// P2:
// %python
// user='abc'
//
Paragraph p1 = note1.addNewParagraph(AuthenticationInfo.ANONYMOUS);
Paragraph p2 = note1.addNewParagraph(AuthenticationInfo.ANONYMOUS);
p1.setText("%python import time\ntime.sleep(1)\nfrom __future__ import print_function\nprint(user2)");
p2.setText("%python user2='abc'\nprint(user2)");
PostMethod post = httpPost("/notebook/job/" + note1.getId(), "");
assertThat(post, isAllowed());
Map<String, Object> resp = gson.fromJson(post.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
}.getType());
assertEquals(resp.get("status"), "OK");
post.releaseConnection();
assertEquals(Job.Status.ERROR, p1.getStatus());
// p2 will be skipped because p1 is failed.
assertEquals(Job.Status.READY, p2.getStatus());
}
@Test
public void testCloneNote() throws IOException {
Note note1 = ZeppelinServer.notebook.createNote(anonymous);

View file

@ -46,7 +46,7 @@ public class NotebookSecurityRestApiTest extends AbstractTestRestApi {
@BeforeClass
public static void init() throws Exception {
AbstractTestRestApi.startUpWithAuthenticationEnable();
AbstractTestRestApi.startUpWithAuthenticationEnable(NotebookSecurityRestApiTest.class.getSimpleName());
}
@AfterClass

View file

@ -40,7 +40,7 @@ public class SecurityRestApiTest extends AbstractTestRestApi {
@BeforeClass
public static void init() throws Exception {
AbstractTestRestApi.startUpWithAuthenticationEnable();
AbstractTestRestApi.startUpWithAuthenticationEnable(SecurityRestApiTest.class.getSimpleName());
}
@AfterClass

View file

@ -56,7 +56,7 @@ public class ZeppelinRestApiTest extends AbstractTestRestApi {
@BeforeClass
public static void init() throws Exception {
AbstractTestRestApi.startUp();
AbstractTestRestApi.startUp(ZeppelinRestApiTest.class.getSimpleName());
}
@AfterClass
@ -441,12 +441,6 @@ public class ZeppelinRestApiTest extends AbstractTestRestApi {
String noteId = note.getId();
note.runAll();
// wait until paragraph gets started
while (!paragraph.getStatus().isRunning()) {
Thread.sleep(100);
}
// assume that status of the paragraph is running
GetMethod get = httpGet("/notebook/job/" + noteId);
assertThat("test get note job: ", get, isAllowed());
@ -494,15 +488,6 @@ public class ZeppelinRestApiTest extends AbstractTestRestApi {
String noteId = note.getId();
note.runAll();
// wait until job is finished or timeout.
int timeout = 1;
while (!paragraph.isTerminated()) {
Thread.sleep(1000);
if (timeout++ > 120) {
LOG.info("testRunParagraphWithParams timeout job.");
break;
}
}
// Call Run paragraph REST API
PostMethod postParagraph = httpPost("/notebook/job/" + noteId + "/" + paragraph.getId(),
@ -534,17 +519,8 @@ public class ZeppelinRestApiTest extends AbstractTestRestApi {
config.put("enabled", true);
paragraph.setConfig(config);
note.runAll();
// wait until job is finished or timeout.
int timeout = 1;
while (!paragraph.isTerminated()) {
Thread.sleep(1000);
if (timeout++ > 10) {
LOG.info("testNoteJobs timeout job.");
break;
}
}
note.runAll(AuthenticationInfo.ANONYMOUS, false);
String jsonRequest = "{\"cron\":\"* * * * * ?\" }";
// right cron expression but not exist note.
PostMethod postCron = httpPost("/notebook/cron/notexistnote", jsonRequest);

View file

@ -0,0 +1,23 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.zeppelin.rest;
public class ZeppelinServerTest extends AbstractTestRestApi {
}

View file

@ -49,7 +49,7 @@ public class ZeppelinSparkClusterTest extends AbstractTestRestApi {
@BeforeClass
public static void init() throws Exception {
AbstractTestRestApi.startUp();
AbstractTestRestApi.startUp(ZeppelinSparkClusterTest.class.getSimpleName());
}
@AfterClass

View file

@ -30,7 +30,7 @@ public class DirAccessTest extends AbstractTestRestApi {
public void testDirAccessForbidden() throws Exception {
synchronized (this) {
System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_SERVER_DEFAULT_DIR_ALLOWED.getVarName(), "false");
AbstractTestRestApi.startUp();
AbstractTestRestApi.startUp(DirAccessTest.class.getSimpleName());
HttpClient httpClient = new HttpClient();
GetMethod getMethod = new GetMethod(getUrlToTest() + "/app/");
httpClient.executeMethod(getMethod);
@ -43,7 +43,7 @@ public class DirAccessTest extends AbstractTestRestApi {
public void testDirAccessOk() throws Exception {
synchronized (this) {
System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_SERVER_DEFAULT_DIR_ALLOWED.getVarName(), "true");
AbstractTestRestApi.startUp();
AbstractTestRestApi.startUp(DirAccessTest.class.getSimpleName());
HttpClient httpClient = new HttpClient();
GetMethod getMethod = new GetMethod(getUrlToTest() + "/app/");
httpClient.executeMethod(getMethod);

View file

@ -63,7 +63,7 @@ public class NotebookServerTest extends AbstractTestRestApi {
@BeforeClass
public static void init() throws Exception {
AbstractTestRestApi.startUp();
AbstractTestRestApi.startUp(NotebookServerTest.class.getSimpleName());
gson = new Gson();
notebook = ZeppelinServer.notebook;
notebookServer = ZeppelinServer.notebookWsServer;

View file

@ -803,7 +803,7 @@ public class InterpreterSettingManager {
}
public void restart(String id) throws InterpreterException {
restart(id, "", "anonymous");
interpreterSettings.get(id).close();
}
public InterpreterSetting get(String id) {

View file

@ -592,32 +592,39 @@ public class Note implements ParagraphJobListener, JsonSerializable {
}
AuthenticationInfo authenticationInfo = new AuthenticationInfo();
authenticationInfo.setUser(cronExecutingUser);
runAll(authenticationInfo);
runAll(authenticationInfo, true);
}
public void runAll(AuthenticationInfo authenticationInfo) {
public void runAll(AuthenticationInfo authenticationInfo, boolean blocking) {
for (Paragraph p : getParagraphs()) {
if (!p.isEnabled()) {
continue;
}
p.setAuthenticationInfo(authenticationInfo);
run(p.getId());
if (!run(p.getId(), blocking)) {
logger.warn("Skip running the remain notes because paragraph {} fails", p.getId());
break;
}
}
}
public boolean run(String paragraphId) {
return run(paragraphId, false);
}
/**
* Run a single paragraph.
*
* @param paragraphId ID of paragraph
*/
public void run(String paragraphId) {
public boolean run(String paragraphId, boolean blocking) {
Paragraph p = getParagraph(paragraphId);
p.setListener(jobListenerFactory.getParagraphJobListener(this));
if (p.isBlankParagraph()) {
logger.info("skip to run blank paragraph. {}", p.getId());
p.setStatus(Job.Status.FINISHED);
return;
return true;
}
p.clearRuntimeInfo(null);
@ -638,6 +645,19 @@ public class Note implements ParagraphJobListener, JsonSerializable {
p.setAuthenticationInfo(p.getAuthenticationInfo());
intp.getScheduler().submit(p);
}
if (blocking) {
while (!p.getStatus().isCompleted()) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
return p.getStatus() == Status.FINISHED;
} else {
return true;
}
}
/**

View file

@ -646,7 +646,7 @@ public class Paragraph extends Job implements Cloneable, JsonSerializable {
@Override
public void run() {
note.run(getParagraphId());
note.run(getParagraphId(), false);
}
}

View file

@ -54,8 +54,9 @@ public abstract class AbstractInterpreterTest {
System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_CONF_DIR.getVarName(), confDir.getAbsolutePath());
System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETER_DIR.getVarName(), interpreterDir.getAbsolutePath());
System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_NOTEBOOK_DIR.getVarName(), notebookDir.getAbsolutePath());
System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETER_GROUP_ORDER.getVarName(), "test,mock1,mock2,mock_resource_pool");
conf.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETER_GROUP_ORDER.getVarName(), "test,mock1,mock2,mock_resource_pool");
conf = new ZeppelinConfiguration();
interpreterSettingManager = new InterpreterSettingManager(conf,
mock(AngularObjectRegistryListener.class), mock(RemoteInterpreterProcessListener.class), mock(ApplicationEventListener.class));
interpreterFactory = new InterpreterFactory(interpreterSettingManager);

View file

@ -17,6 +17,7 @@
package org.apache.zeppelin.interpreter;
import org.apache.zeppelin.interpreter.mock.MockInterpreter1;
import org.apache.zeppelin.interpreter.remote.RemoteInterpreter;
import org.junit.Test;
@ -36,19 +37,19 @@ public class InterpreterFactoryTest extends AbstractInterpreterTest {
interpreterSettingManager.setInterpreterBinding("user1", "note1", interpreterSettingManager.getSettingIds());
assertTrue(interpreterFactory.getInterpreter("user1", "note1", "") instanceof RemoteInterpreter);
RemoteInterpreter remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("user1", "note1", "");
// EchoInterpreter is the default interpreter (see zeppelin-interpreter/src/test/resources/conf/interpreter.json)
// EchoInterpreter is the default interpreter because mock1 is the default interpreter group
assertEquals(EchoInterpreter.class.getName(), remoteInterpreter.getClassName());
assertTrue(interpreterFactory.getInterpreter("user1", "note1", "test") instanceof RemoteInterpreter);
remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("user1", "note1", "test");
assertEquals(EchoInterpreter.class.getName(), remoteInterpreter.getClassName());
assertTrue(interpreterFactory.getInterpreter("user1", "note1", "echo") instanceof RemoteInterpreter);
remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("user1", "note1", "echo");
assertTrue(interpreterFactory.getInterpreter("user1", "note1", "test2") instanceof RemoteInterpreter);
remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("user1", "note1", "test2");
assertEquals(EchoInterpreter.class.getName(), remoteInterpreter.getClassName());
assertTrue(interpreterFactory.getInterpreter("user1", "note1", "double_echo") instanceof RemoteInterpreter);
remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("user1", "note1", "double_echo");
assertTrue(interpreterFactory.getInterpreter("user1", "note1", "test2.double_echo") instanceof RemoteInterpreter);
remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("user1", "note1", "test2.double_echo");
assertEquals(DoubleEchoInterpreter.class.getName(), remoteInterpreter.getClassName());
}

View file

@ -114,7 +114,7 @@ public class NotebookTest extends AbstractInterpreterTest implements JobListener
Map config = p1.getConfig();
config.put("enabled", true);
p1.setConfig(config);
p1.setText("hello world");
p1.setText("%mock1 hello world");
p1.setAuthenticationInfo(anonymous);
note.run(p1.getId());
while(p1.isTerminated()==false || p1.getResult()==null) Thread.yield();
@ -268,7 +268,7 @@ public class NotebookTest extends AbstractInterpreterTest implements JobListener
Map config = p1.getConfig();
config.put("enabled", true);
p1.setConfig(config);
p1.setText("hello world");
p1.setText("%mock1 hello world");
p1.setAuthenticationInfo(anonymous);
note.run(p1.getId());
@ -305,27 +305,22 @@ public class NotebookTest extends AbstractInterpreterTest implements JobListener
Map config1 = p1.getConfig();
config1.put("enabled", true);
p1.setConfig(config1);
p1.setText("p1");
p1.setText("%mock1 p1");
// p2
Paragraph p2 = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
Map config2 = p2.getConfig();
config2.put("enabled", false);
p2.setConfig(config2);
p2.setText("p2");
p2.setText("%mock1 p2");
// p3
Paragraph p3 = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
p3.setText("p3");
p3.setText("%mock1 p3");
// when
note.runAll();
// wait for finish
while(p3.isTerminated() == false || p3.getResult() == null) {
Thread.yield();
}
assertEquals("repl1: p1", p1.getResult().message().get(0).getData());
assertNull(p2.getResult());
assertEquals("repl1: p3", p3.getResult().message().get(0).getData());
@ -415,7 +410,7 @@ public class NotebookTest extends AbstractInterpreterTest implements JobListener
Paragraph p = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
Map config = new HashMap<>();
p.setConfig(config);
p.setText("sleep 1000");
p.setText("%mock1 sleep 1000");
Paragraph p2 = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
p2.setConfig(config);
@ -466,9 +461,6 @@ public class NotebookTest extends AbstractInterpreterTest implements JobListener
p.setText(simpleText);
note.runAll();
while (p.isTerminated() == false || p.getResult() == null) {
Thread.yield();
}
String exportedNoteJson = notebook.exportNote(note.getId());
@ -503,7 +495,6 @@ public class NotebookTest extends AbstractInterpreterTest implements JobListener
final Paragraph p = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
p.setText("hello world");
note.runAll();
while(p.isTerminated()==false || p.getResult()==null) Thread.yield();
p.setStatus(Status.RUNNING);
Note cloneNote = notebook.cloneNote(note.getId(), "clone note", anonymous);
@ -549,9 +540,7 @@ public class NotebookTest extends AbstractInterpreterTest implements JobListener
final Paragraph p = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
p.setText("hello world");
note.runAll();
while (p.isTerminated() == false || p.getResult() == null) {
Thread.yield();
}
// Force paragraph to have String type object
p.setResult("Exception");
@ -572,15 +561,13 @@ public class NotebookTest extends AbstractInterpreterTest implements JobListener
interpreterSettingManager.setInterpreterBinding(anonymous.getUser(), note.getId(), interpreterSettingManager.getInterpreterSettingIds());
Paragraph p1 = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
p1.setText("hello");
p1.setText("%mock1 hello");
Paragraph p2 = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
p2.setText("%mock2 world");
for (InterpreterGroup intpGroup : interpreterSettingManager.getAllInterpreterGroup()) {
intpGroup.setResourcePool(new LocalResourcePool(intpGroup.getId()));
}
note.runAll();
while (p1.isTerminated() == false || p1.getResult() == null) Thread.yield();
while (p2.isTerminated() == false || p2.getResult() == null) Thread.yield();
assertEquals(2, interpreterSettingManager.getAllResources().size());
@ -796,14 +783,14 @@ public class NotebookTest extends AbstractInterpreterTest implements JobListener
// create three paragraphs
Paragraph p1 = note.addNewParagraph(anonymous);
p1.setText("sleep 1000");
p1.setText("%mock1 sleep 1000");
Paragraph p2 = note.addNewParagraph(anonymous);
p2.setText("sleep 1000");
p2.setText("%mock1 sleep 1000");
Paragraph p3 = note.addNewParagraph(anonymous);
p3.setText("sleep 1000");
p3.setText("%mock1 sleep 1000");
note.runAll();
note.runAll(AuthenticationInfo.ANONYMOUS, false);
// wait until first paragraph finishes and second paragraph starts
while (p1.getStatus() != Status.FINISHED || p2.getStatus() != Status.RUNNING) Thread.yield();
@ -813,9 +800,9 @@ public class NotebookTest extends AbstractInterpreterTest implements JobListener
assertEquals(Status.PENDING, p3.getStatus());
// restart interpreter
interpreterSettingManager.restart(interpreterSettingManager.getInterpreterSettings(note.getId()).get(0).getId());
interpreterSettingManager.restart(interpreterSettingManager.getInterpreterSettingByName("mock1").getId());
// make sure three differnt status aborted well.
// make sure three different status aborted well.
assertEquals(Status.FINISHED, p1.getStatus());
assertEquals(Status.ABORT, p2.getStatus());
assertEquals(Status.ABORT, p3.getStatus());
@ -828,7 +815,7 @@ public class NotebookTest extends AbstractInterpreterTest implements JobListener
// create a notes
Note note1 = notebook.createNote(anonymous);
Paragraph p1 = note1.addNewParagraph(AuthenticationInfo.ANONYMOUS);
p1.setText("getId");
p1.setText("%mock1 getId");
p1.setAuthenticationInfo(anonymous);
// restart interpreter with per user session enabled
@ -845,7 +832,7 @@ public class NotebookTest extends AbstractInterpreterTest implements JobListener
notebook.removeNote(note1.getId(), anonymous);
note1 = notebook.createNote(anonymous);
p1 = note1.addNewParagraph(AuthenticationInfo.ANONYMOUS);
p1.setText("getId");
p1.setText("%mock1 getId");
p1.setAuthenticationInfo(anonymous);
note1.run(p1.getId());
@ -864,9 +851,9 @@ public class NotebookTest extends AbstractInterpreterTest implements JobListener
Note note2 = notebook.createNote(anonymous);
Paragraph p2 = note2.addNewParagraph(AuthenticationInfo.ANONYMOUS);
p1.setText("getId");
p1.setText("%mock1 getId");
p1.setAuthenticationInfo(anonymous);
p2.setText("getId");
p2.setText("%mock1 getId");
p2.setAuthenticationInfo(anonymous);
// run per note session disabled
@ -908,9 +895,9 @@ public class NotebookTest extends AbstractInterpreterTest implements JobListener
Note note2 = notebook.createNote(anonymous);
Paragraph p2 = note2.addNewParagraph(AuthenticationInfo.ANONYMOUS);
p1.setText("getId");
p1.setText("%mock1 getId");
p1.setAuthenticationInfo(anonymous);
p2.setText("getId");
p2.setText("%mock1 getId");
p2.setAuthenticationInfo(anonymous);
// shared mode.
@ -925,8 +912,7 @@ public class NotebookTest extends AbstractInterpreterTest implements JobListener
// restart interpreter with scoped mode enabled
for (InterpreterSetting setting : notebook.getInterpreterSettingManager().getInterpreterSettings(note1.getId())) {
setting.getOption().setPerNote(InterpreterOption.SCOPED);
notebook.getInterpreterSettingManager().restart(setting.getId(), note1.getId(), anonymous.getUser());
notebook.getInterpreterSettingManager().restart(setting.getId(), note2.getId(), anonymous.getUser());
notebook.getInterpreterSettingManager().restart(setting.getId());
}
// run per note session enabled
@ -941,8 +927,7 @@ public class NotebookTest extends AbstractInterpreterTest implements JobListener
// restart interpreter with isolated mode enabled
for (InterpreterSetting setting : notebook.getInterpreterSettingManager().getInterpreterSettings(note1.getId())) {
setting.getOption().setPerNote(InterpreterOption.ISOLATED);
notebook.getInterpreterSettingManager().restart(setting.getId(), note1.getId(), anonymous.getUser());
notebook.getInterpreterSettingManager().restart(setting.getId(), note2.getId(), anonymous.getUser());
setting.getInterpreterSettingManager().restart(setting.getId());
}
// run per note process enabled
@ -964,7 +949,7 @@ public class NotebookTest extends AbstractInterpreterTest implements JobListener
Note note1 = notebook.createNote(anonymous);
Paragraph p1 = note1.addNewParagraph(AuthenticationInfo.ANONYMOUS);
p1.setAuthenticationInfo(anonymous);
p1.setText("getId");
p1.setText("%mock1 getId");
// restart interpreter with per note session enabled
for (InterpreterSetting setting : interpreterSettingManager.getInterpreterSettings(note1.getId())) {