mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
Add more unittests
This commit is contained in:
parent
6dd981a036
commit
cc33c25843
2 changed files with 112 additions and 10 deletions
|
|
@ -45,7 +45,13 @@ public class MockInterpreter1 extends Interpreter{
|
|||
|
||||
@Override
|
||||
public InterpreterResult interpret(String st, InterpreterContext context) {
|
||||
return new InterpreterResult(InterpreterResult.Code.SUCCESS, "repl1: "+st);
|
||||
|
||||
if ("getId".equals(st)) {
|
||||
// get unique id of this interpreter instance
|
||||
return new InterpreterResult(InterpreterResult.Code.SUCCESS, "" + this.hashCode());
|
||||
} else {
|
||||
return new InterpreterResult(InterpreterResult.Code.SUCCESS, "repl1: " + st);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -26,21 +26,14 @@ import static org.mockito.Mockito.mock;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.zeppelin.conf.ZeppelinConfiguration;
|
||||
import org.apache.zeppelin.conf.ZeppelinConfiguration.ConfVars;
|
||||
import org.apache.zeppelin.dep.DependencyResolver;
|
||||
import org.apache.zeppelin.display.AngularObjectRegistry;
|
||||
import org.apache.zeppelin.interpreter.InterpreterFactory;
|
||||
import org.apache.zeppelin.interpreter.InterpreterOption;
|
||||
import org.apache.zeppelin.interpreter.InterpreterOutput;
|
||||
import org.apache.zeppelin.interpreter.InterpreterSetting;
|
||||
import org.apache.zeppelin.interpreter.*;
|
||||
import org.apache.zeppelin.interpreter.mock.MockInterpreter1;
|
||||
import org.apache.zeppelin.interpreter.mock.MockInterpreter2;
|
||||
import org.apache.zeppelin.notebook.repo.NotebookRepo;
|
||||
|
|
@ -444,6 +437,109 @@ public class NotebookTest implements JobListenerFactory{
|
|||
assertTrue(isAborted);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPerSessionInterpreterCloseOnNoteRemoval() throws IOException {
|
||||
// create a notes
|
||||
Note note1 = notebook.createNote();
|
||||
Paragraph p1 = note1.addParagraph();
|
||||
p1.setText("getId");
|
||||
|
||||
// restart interpreter with per note session enabled
|
||||
for (InterpreterSetting setting : note1.getNoteReplLoader().getInterpreterSettings()) {
|
||||
setting.getOption().setPerNoteSession(true);
|
||||
notebook.getInterpreterFactory().restart(setting.id());
|
||||
}
|
||||
|
||||
note1.run(p1.getId());
|
||||
while (p1.getStatus() != Status.FINISHED) Thread.yield();
|
||||
InterpreterResult result = p1.getResult();
|
||||
|
||||
// remove note and recreate
|
||||
notebook.removeNote(note1.getId());
|
||||
note1 = notebook.createNote();
|
||||
p1 = note1.addParagraph();
|
||||
p1.setText("getId");
|
||||
|
||||
note1.run(p1.getId());
|
||||
while (p1.getStatus() != Status.FINISHED) Thread.yield();
|
||||
assertNotEquals(p1.getResult().message(), result.message());
|
||||
|
||||
notebook.removeNote(note1.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPerSessionInterpreter() throws IOException {
|
||||
// create two notes
|
||||
Note note1 = notebook.createNote();
|
||||
Paragraph p1 = note1.addParagraph();
|
||||
|
||||
Note note2 = notebook.createNote();
|
||||
Paragraph p2 = note2.addParagraph();
|
||||
|
||||
p1.setText("getId");
|
||||
p2.setText("getId");
|
||||
|
||||
// run per note session disabled
|
||||
note1.run(p1.getId());
|
||||
note2.run(p2.getId());
|
||||
|
||||
while (p1.getStatus() != Status.FINISHED) Thread.yield();
|
||||
while (p2.getStatus() != Status.FINISHED) Thread.yield();
|
||||
|
||||
assertEquals(p1.getResult(), p2.getResult());
|
||||
|
||||
|
||||
// restart interpreter with per note session enabled
|
||||
for (InterpreterSetting setting : note1.getNoteReplLoader().getInterpreterSettings()) {
|
||||
setting.getOption().setPerNoteSession(true);
|
||||
notebook.getInterpreterFactory().restart(setting.id());
|
||||
}
|
||||
|
||||
// run per note session enabled
|
||||
note1.run(p1.getId());
|
||||
note2.run(p2.getId());
|
||||
|
||||
while (p1.getStatus() != Status.FINISHED) Thread.yield();
|
||||
while (p2.getStatus() != Status.FINISHED) Thread.yield();
|
||||
|
||||
assertNotEquals(p1.getResult(), p2.getResult());
|
||||
|
||||
notebook.removeNote(note1.getId());
|
||||
notebook.removeNote(note2.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPerSessionInterpreterCloseOnUnbindInterpreterSetting() throws IOException {
|
||||
// create a notes
|
||||
Note note1 = notebook.createNote();
|
||||
Paragraph p1 = note1.addParagraph();
|
||||
p1.setText("getId");
|
||||
|
||||
// restart interpreter with per note session enabled
|
||||
for (InterpreterSetting setting : note1.getNoteReplLoader().getInterpreterSettings()) {
|
||||
setting.getOption().setPerNoteSession(true);
|
||||
notebook.getInterpreterFactory().restart(setting.id());
|
||||
}
|
||||
|
||||
note1.run(p1.getId());
|
||||
while (p1.getStatus() != Status.FINISHED) Thread.yield();
|
||||
InterpreterResult result = p1.getResult();
|
||||
|
||||
|
||||
// unbind, and rebind setting. that result interpreter instance close
|
||||
List<String> bindedSettings = notebook.getBindedInterpreterSettingsIds(note1.getId());
|
||||
notebook.bindInterpretersToNote(note1.getId(), new LinkedList<String>());
|
||||
notebook.bindInterpretersToNote(note1.getId(), bindedSettings);
|
||||
|
||||
note1.run(p1.getId());
|
||||
while (p1.getStatus() != Status.FINISHED) Thread.yield();
|
||||
|
||||
assertNotEquals(result.message(), p1.getResult().message());
|
||||
|
||||
notebook.removeNote(note1.getId());
|
||||
}
|
||||
|
||||
|
||||
private void delete(File file){
|
||||
if(file.isFile()) file.delete();
|
||||
else if(file.isDirectory()){
|
||||
|
|
|
|||
Loading…
Reference in a new issue