add testcase and fix the doc.

This commit is contained in:
astroshim 2016-09-16 23:55:42 +09:00
parent 3127154ef5
commit 72a2259522
3 changed files with 66 additions and 1 deletions

View file

@ -400,6 +400,16 @@ The role of registered interpreters, settings and interpreters group are describ
<td>Fail code</td>
<td> 500 </td>
</tr>
<tr>
<td>Sample JSON input (Optional)</td>
<td>
<pre>
{
"noteId": "2AVQJVC8N"
}
</pre>
</td>
</tr>
<tr>
<td>Sample JSON response</td>
<td>

View file

@ -25,6 +25,7 @@ import org.apache.commons.httpclient.methods.DeleteMethod;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.PutMethod;
import org.apache.zeppelin.interpreter.InterpreterOption;
import org.apache.zeppelin.interpreter.InterpreterSetting;
import org.apache.zeppelin.notebook.Note;
import org.apache.zeppelin.notebook.Paragraph;
@ -190,6 +191,60 @@ public class InterpreterRestApiTest extends AbstractTestRestApi {
ZeppelinServer.notebook.removeNote(note.getId(), null);
}
@Test
public void testRestartInterpreterPerNote() throws IOException, InterruptedException {
// create new note
Note note = ZeppelinServer.notebook.createNote(null);
note.addParagraph();
Paragraph p = note.getLastParagraph();
Map config = p.getConfig();
config.put("enabled", true);
// run markdown paragraph.
p.setConfig(config);
p.setText("%md markdown");
note.run(p.getId());
while (p.getStatus() != Status.FINISHED) {
Thread.sleep(100);
}
assertEquals("<p>markdown</p>\n", p.getResult().message());
// get md interpreter
InterpreterSetting mdIntpSetting = null;
for (InterpreterSetting setting : ZeppelinServer.notebook.getInterpreterFactory().getInterpreterSettings(note.getId())) {
if (setting.getName().equals("md")) {
mdIntpSetting = setting;
break;
}
}
String jsonRequest = "{\"noteId\":\"" + note.getId() + "\"}";
LOG.info("=========>{}", jsonRequest);
// Restart isolated mode of Interpreter for note.
mdIntpSetting.getOption().setPerNoteProcess(true);
mdIntpSetting.getOption().setPerNoteSession(false);
PutMethod put = httpPut("/interpreter/setting/restart/" + mdIntpSetting.getId(), jsonRequest);
assertThat("isolated interpreter restart:", put, isAllowed());
put.releaseConnection();
// Restart scoped mode of Interpreter for note.
mdIntpSetting.getOption().setPerNoteSession(true);
mdIntpSetting.getOption().setPerNoteProcess(false);
put = httpPut("/interpreter/setting/restart/" + mdIntpSetting.getId(), jsonRequest);
assertThat("scoped interpreter restart:", put, isAllowed());
put.releaseConnection();
// Restart shared mode of Interpreter for note.
mdIntpSetting.getOption().setPerNoteProcess(false);
mdIntpSetting.getOption().setPerNoteSession(false);
put = httpPut("/interpreter/setting/restart/" + mdIntpSetting.getId(), jsonRequest);
assertThat("shared interpreter restart:", put, isAllowed());
put.releaseConnection();
ZeppelinServer.notebook.removeNote(note.getId(), null);
}
@Test
public void testListRepository() throws IOException {
GetMethod get = httpGet("/interpreter/repository");

View file

@ -861,7 +861,7 @@ public class InterpreterFactory implements InterpreterGroupFactory {
}
private boolean isNotSharedInterpreter(InterpreterOption intpOption) {
return intpOption.isPerNoteSession() || intpOption.isConnectExistingProcess();
return intpOption.isPerNoteSession() || intpOption.isExistingProcess();
}