Add test case & Optimization code.

This commit is contained in:
liuxunorg 2018-12-26 23:32:42 +08:00
parent 6dfb8a15f2
commit 58c0f4451a
9 changed files with 102 additions and 53 deletions

View file

@ -120,8 +120,6 @@ Here is an example of `interpreter-setting.json` on your own interpreter.
"completionKey": "TAB"
},
"config": {
"fontSize": 9,
"colWidth": 12,
"runOnSelectionChange": true/false,
"title": true/false
}

View file

@ -549,6 +549,7 @@ public class ParagraphActionsIT extends AbstractZeppelinIT {
CoreMatchers.equalTo("Hello world"));
runParagraph(1);
ZeppelinITUtils.sleep(1000, false);
waitForParagraph(1, "FINISHED");
collector.checkThat("Only after running the paragraph, we can see the newly updated output",
driver.findElement(By.xpath(getParagraphXPath(1) + "//div[contains(@class, 'text plainTextContent')]")).getText(),

View file

@ -33,11 +33,12 @@ public class InterpreterInfo {
private Map<String, Object> config;
public InterpreterInfo(String className, String name, boolean defaultInterpreter,
Map<String, Object> editor) {
Map<String, Object> editor, Map<String, Object> config) {
this.className = className;
this.name = name;
this.defaultInterpreter = defaultInterpreter;
this.editor = editor;
this.config = config;
}
public String getName() {

View file

@ -400,7 +400,8 @@ public class InterpreterSettingManager implements InterpreterSettingManagerMBean
//TODO(zjffdu) merge RegisteredInterpreter & InterpreterInfo
InterpreterInfo interpreterInfo =
new InterpreterInfo(registeredInterpreter.getClassName(), registeredInterpreter.getName(),
registeredInterpreter.isDefaultInterpreter(), registeredInterpreter.getEditor());
registeredInterpreter.isDefaultInterpreter(), registeredInterpreter.getEditor(),
registeredInterpreter.getConfig());
interpreterInfo.setConfig(registeredInterpreter.getConfig());
group = registeredInterpreter.getGroup();
runner = registeredInterpreter.getRunner();

View file

@ -94,6 +94,7 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> implemen
/************** Transient fields which are not serializabled into note json **************/
private transient String intpText;
private transient Boolean configSettingNeedUpdate = true;
private transient String scriptText;
private transient Interpreter interpreter;
private transient Note note;
@ -103,10 +104,6 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> implemen
private transient Map<String, String> localProperties = new HashMap<>();
private transient Map<String, ParagraphRuntimeInfo> runtimeInfos = new HashMap<>();
private static String PARAGRAPH_CONFIG_FONTSIZE = "fontSize";
private static int PARAGRAPH_CONFIG_FONTSIZE_DEFAULT = 9;
private static String PARAGRAPH_CONFIG_COLWIDTH = "colWidth";
private static int PARAGRAPH_CONFIG_COLWIDTH_DEFAULT = 12;
private static String PARAGRAPH_CONFIG_RUNONSELECTIONCHANGE = "runOnSelectionChange";
private static boolean PARAGRAPH_CONFIG_RUNONSELECTIONCHANGE_DEFAULT = true;
private static String PARAGRAPH_CONFIG_TITLE = "title";
@ -169,6 +166,13 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> implemen
return p;
}
private void setIntpText(String newIntptext) {
if (null == intpText || !this.intpText.equals(newIntptext)) {
this.configSettingNeedUpdate = true;
}
this.intpText = newIntptext;
}
public void clearUserParagraphs() {
userParagraphMap.clear();
}
@ -199,7 +203,7 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> implemen
Matcher matcher = REPL_PATTERN.matcher(this.text);
if (matcher.matches()) {
String headingSpace = matcher.group(1);
this.intpText = matcher.group(2);
setIntpText(matcher.group(2));
if (matcher.groupCount() == 3 && matcher.group(3) != null) {
String localPropertiesText = matcher.group(3);
@ -225,7 +229,7 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> implemen
this.scriptText = this.text.substring(headingSpace.length() + intpText.length() + 1).trim();
}
} else {
this.intpText = "";
setIntpText("");
this.scriptText = this.text.trim();
}
}
@ -462,15 +466,18 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> implemen
// After the paragraph is executed,
// need to apply the paragraph to the configuration in the
// `interpreter-setting.json` config
InterpreterSettingManager intpSettingManager
= this.note.getInterpreterSettingManager();
if (null != intpSettingManager) {
InterpreterGroup intpGroup = interpreter.getInterpreterGroup();
if (intpGroup instanceof ManagedInterpreterGroup) {
String name = ((ManagedInterpreterGroup) intpGroup).getInterpreterSetting().getName();
Map<String, Object> config
= intpSettingManager.getConfigSetting(name);
applyConfigSetting(config);
if (this.configSettingNeedUpdate) {
this.configSettingNeedUpdate = false;
InterpreterSettingManager intpSettingManager
= this.note.getInterpreterSettingManager();
if (null != intpSettingManager) {
InterpreterGroup intpGroup = interpreter.getInterpreterGroup();
if (null != intpGroup && intpGroup instanceof ManagedInterpreterGroup) {
String name = ((ManagedInterpreterGroup) intpGroup).getInterpreterSetting().getName();
Map<String, Object> config
= intpSettingManager.getConfigSetting(name);
applyConfigSetting(config);
}
}
}
@ -608,8 +615,7 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> implemen
newConfig = getDefaultConfigSetting();
}
List<String> keysToRemove = Arrays.asList(PARAGRAPH_CONFIG_FONTSIZE,
PARAGRAPH_CONFIG_COLWIDTH, PARAGRAPH_CONFIG_RUNONSELECTIONCHANGE,
List<String> keysToRemove = Arrays.asList(PARAGRAPH_CONFIG_RUNONSELECTIONCHANGE,
PARAGRAPH_CONFIG_TITLE);
for (String removeKey : keysToRemove) {
if ((false == newConfig.containsKey(removeKey))
@ -624,8 +630,6 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> implemen
// default parameters of the interpreter
private Map<String, Object> getDefaultConfigSetting() {
Map<String, Object> config = new HashMap<>();
config.put(PARAGRAPH_CONFIG_FONTSIZE, PARAGRAPH_CONFIG_FONTSIZE_DEFAULT);
config.put(PARAGRAPH_CONFIG_COLWIDTH, PARAGRAPH_CONFIG_COLWIDTH_DEFAULT);
config.put(PARAGRAPH_CONFIG_RUNONSELECTIONCHANGE, PARAGRAPH_CONFIG_RUNONSELECTIONCHANGE_DEFAULT);
config.put(PARAGRAPH_CONFIG_TITLE, PARAGRAPH_CONFIG_TITLE_DEFAULT);

View file

@ -32,8 +32,11 @@ public class InterpreterSettingTest {
public void testCreateInterpreters() {
InterpreterOption interpreterOption = new InterpreterOption();
interpreterOption.setPerUser(InterpreterOption.SHARED);
InterpreterInfo interpreterInfo1 = new InterpreterInfo(EchoInterpreter.class.getName(), "echo", true, new HashMap<String, Object>());
InterpreterInfo interpreterInfo2 = new InterpreterInfo(DoubleEchoInterpreter.class.getName(), "double_echo", false, new HashMap<String, Object>());
InterpreterInfo interpreterInfo1 = new InterpreterInfo(EchoInterpreter.class.getName(),
"echo", true, new HashMap<String, Object>(), new HashMap<String, Object>());
InterpreterInfo interpreterInfo2 = new InterpreterInfo(DoubleEchoInterpreter.class.getName(),
"double_echo", false, new HashMap<String, Object>(),
new HashMap<String, Object>());
List<InterpreterInfo> interpreterInfos = new ArrayList<>();
interpreterInfos.add(interpreterInfo1);
interpreterInfos.add(interpreterInfo2);
@ -63,8 +66,10 @@ public class InterpreterSettingTest {
public void testSharedMode() {
InterpreterOption interpreterOption = new InterpreterOption();
interpreterOption.setPerUser(InterpreterOption.SHARED);
InterpreterInfo interpreterInfo1 = new InterpreterInfo(EchoInterpreter.class.getName(), "echo", true, new HashMap<String, Object>());
InterpreterInfo interpreterInfo2 = new InterpreterInfo(DoubleEchoInterpreter.class.getName(), "double_echo", false, new HashMap<String, Object>());
InterpreterInfo interpreterInfo1 = new InterpreterInfo(EchoInterpreter.class.getName(),
"echo", true, new HashMap<String, Object>(), new HashMap<String, Object>());
InterpreterInfo interpreterInfo2 = new InterpreterInfo(DoubleEchoInterpreter.class.getName(),
"double_echo", false, new HashMap<String, Object>(), new HashMap<String, Object>());
List<InterpreterInfo> interpreterInfos = new ArrayList<>();
interpreterInfos.add(interpreterInfo1);
interpreterInfos.add(interpreterInfo2);
@ -99,8 +104,10 @@ public class InterpreterSettingTest {
public void testPerUserScopedMode() {
InterpreterOption interpreterOption = new InterpreterOption();
interpreterOption.setPerUser(InterpreterOption.SCOPED);
InterpreterInfo interpreterInfo1 = new InterpreterInfo(EchoInterpreter.class.getName(), "echo", true, new HashMap<String, Object>());
InterpreterInfo interpreterInfo2 = new InterpreterInfo(DoubleEchoInterpreter.class.getName(), "double_echo", false, new HashMap<String, Object>());
InterpreterInfo interpreterInfo1 = new InterpreterInfo(EchoInterpreter.class.getName(),
"echo", true, new HashMap<String, Object>(), new HashMap<String, Object>());
InterpreterInfo interpreterInfo2 = new InterpreterInfo(DoubleEchoInterpreter.class.getName(),
"double_echo", false, new HashMap<String, Object>(), new HashMap<String, Object>());
List<InterpreterInfo> interpreterInfos = new ArrayList<>();
interpreterInfos.add(interpreterInfo1);
interpreterInfos.add(interpreterInfo2);
@ -135,8 +142,10 @@ public class InterpreterSettingTest {
public void testPerNoteScopedMode() {
InterpreterOption interpreterOption = new InterpreterOption();
interpreterOption.setPerNote(InterpreterOption.SCOPED);
InterpreterInfo interpreterInfo1 = new InterpreterInfo(EchoInterpreter.class.getName(), "echo", true, new HashMap<String, Object>());
InterpreterInfo interpreterInfo2 = new InterpreterInfo(DoubleEchoInterpreter.class.getName(), "double_echo", false, new HashMap<String, Object>());
InterpreterInfo interpreterInfo1 = new InterpreterInfo(EchoInterpreter.class.getName(),
"echo", true, new HashMap<String, Object>(), new HashMap<String, Object>());
InterpreterInfo interpreterInfo2 = new InterpreterInfo(DoubleEchoInterpreter.class.getName(),
"double_echo", false, new HashMap<String, Object>(), new HashMap<String, Object>());
List<InterpreterInfo> interpreterInfos = new ArrayList<>();
interpreterInfos.add(interpreterInfo1);
interpreterInfos.add(interpreterInfo2);
@ -171,8 +180,10 @@ public class InterpreterSettingTest {
public void testPerUserIsolatedMode() {
InterpreterOption interpreterOption = new InterpreterOption();
interpreterOption.setPerUser(InterpreterOption.ISOLATED);
InterpreterInfo interpreterInfo1 = new InterpreterInfo(EchoInterpreter.class.getName(), "echo", true, new HashMap<String, Object>());
InterpreterInfo interpreterInfo2 = new InterpreterInfo(DoubleEchoInterpreter.class.getName(), "double_echo", false, new HashMap<String, Object>());
InterpreterInfo interpreterInfo1 = new InterpreterInfo(EchoInterpreter.class.getName(),
"echo", true, new HashMap<String, Object>(), new HashMap<String, Object>());
InterpreterInfo interpreterInfo2 = new InterpreterInfo(DoubleEchoInterpreter.class.getName(),
"double_echo", false, new HashMap<String, Object>(), new HashMap<String, Object>());
List<InterpreterInfo> interpreterInfos = new ArrayList<>();
interpreterInfos.add(interpreterInfo1);
interpreterInfos.add(interpreterInfo2);
@ -207,8 +218,10 @@ public class InterpreterSettingTest {
public void testPerNoteIsolatedMode() {
InterpreterOption interpreterOption = new InterpreterOption();
interpreterOption.setPerNote(InterpreterOption.ISOLATED);
InterpreterInfo interpreterInfo1 = new InterpreterInfo(EchoInterpreter.class.getName(), "echo", true, new HashMap<String, Object>());
InterpreterInfo interpreterInfo2 = new InterpreterInfo(DoubleEchoInterpreter.class.getName(), "double_echo", false, new HashMap<String, Object>());
InterpreterInfo interpreterInfo1 = new InterpreterInfo(EchoInterpreter.class.getName(),
"echo", true, new HashMap<String, Object>(), new HashMap<String, Object>());
InterpreterInfo interpreterInfo2 = new InterpreterInfo(DoubleEchoInterpreter.class.getName(),
"double_echo", false, new HashMap<String, Object>(), new HashMap<String, Object>());
List<InterpreterInfo> interpreterInfos = new ArrayList<>();
interpreterInfos.add(interpreterInfo1);
interpreterInfos.add(interpreterInfo2);
@ -243,8 +256,10 @@ public class InterpreterSettingTest {
InterpreterOption interpreterOption = new InterpreterOption();
interpreterOption.setPerUser(InterpreterOption.ISOLATED);
interpreterOption.setPerNote(InterpreterOption.SCOPED);
InterpreterInfo interpreterInfo1 = new InterpreterInfo(EchoInterpreter.class.getName(), "echo", true, new HashMap<String, Object>());
InterpreterInfo interpreterInfo2 = new InterpreterInfo(DoubleEchoInterpreter.class.getName(), "double_echo", false, new HashMap<String, Object>());
InterpreterInfo interpreterInfo1 = new InterpreterInfo(EchoInterpreter.class.getName(),
"echo", true, new HashMap<String, Object>(), new HashMap<String, Object>());
InterpreterInfo interpreterInfo2 = new InterpreterInfo(DoubleEchoInterpreter.class.getName(),
"double_echo", false, new HashMap<String, Object>(), new HashMap<String, Object>());
List<InterpreterInfo> interpreterInfos = new ArrayList<>();
interpreterInfos.add(interpreterInfo1);
interpreterInfos.add(interpreterInfo2);
@ -294,8 +309,10 @@ public class InterpreterSettingTest {
InterpreterOption interpreterOption = new InterpreterOption();
interpreterOption.setPerUser(InterpreterOption.ISOLATED);
interpreterOption.setPerNote(InterpreterOption.ISOLATED);
InterpreterInfo interpreterInfo1 = new InterpreterInfo(EchoInterpreter.class.getName(), "echo", true, new HashMap<String, Object>());
InterpreterInfo interpreterInfo2 = new InterpreterInfo(DoubleEchoInterpreter.class.getName(), "double_echo", false, new HashMap<String, Object>());
InterpreterInfo interpreterInfo1 = new InterpreterInfo(EchoInterpreter.class.getName(),
"echo", true, new HashMap<String, Object>(), new HashMap<String, Object>());
InterpreterInfo interpreterInfo2 = new InterpreterInfo(DoubleEchoInterpreter.class.getName(),
"double_echo", false, new HashMap<String, Object>(), new HashMap<String, Object>());
List<InterpreterInfo> interpreterInfos = new ArrayList<>();
interpreterInfos.add(interpreterInfo1);
interpreterInfos.add(interpreterInfo2);
@ -350,8 +367,10 @@ public class InterpreterSettingTest {
InterpreterOption interpreterOption = new InterpreterOption();
interpreterOption.setPerUser(InterpreterOption.SCOPED);
interpreterOption.setPerNote(InterpreterOption.SCOPED);
InterpreterInfo interpreterInfo1 = new InterpreterInfo(EchoInterpreter.class.getName(), "echo", true, new HashMap<String, Object>());
InterpreterInfo interpreterInfo2 = new InterpreterInfo(DoubleEchoInterpreter.class.getName(), "double_echo", false, new HashMap<String, Object>());
InterpreterInfo interpreterInfo1 = new InterpreterInfo(EchoInterpreter.class.getName(),
"echo", true, new HashMap<String, Object>(), new HashMap<String, Object>());
InterpreterInfo interpreterInfo2 = new InterpreterInfo(DoubleEchoInterpreter.class.getName(),
"double_echo", false, new HashMap<String, Object>(), new HashMap<String, Object>());
List<InterpreterInfo> interpreterInfos = new ArrayList<>();
interpreterInfos.add(interpreterInfo1);
interpreterInfos.add(interpreterInfo2);

View file

@ -41,8 +41,10 @@ public class ManagedInterpreterGroupTest {
public void setUp() throws IOException, RepositoryException {
InterpreterOption interpreterOption = new InterpreterOption();
interpreterOption.setPerUser(InterpreterOption.SCOPED);
InterpreterInfo interpreterInfo1 = new InterpreterInfo(EchoInterpreter.class.getName(), "echo", true, new HashMap<String, Object>());
InterpreterInfo interpreterInfo2 = new InterpreterInfo(DoubleEchoInterpreter.class.getName(), "double_echo", false, new HashMap<String, Object>());
InterpreterInfo interpreterInfo1 = new InterpreterInfo(EchoInterpreter.class.getName(),
"echo", true, new HashMap<String, Object>(), new HashMap<String, Object>());
InterpreterInfo interpreterInfo2 = new InterpreterInfo(DoubleEchoInterpreter.class.getName(),
"double_echo", false, new HashMap<String, Object>(), new HashMap<String, Object>());
List<InterpreterInfo> interpreterInfos = new ArrayList<>();
interpreterInfos.add(interpreterInfo1);
interpreterInfos.add(interpreterInfo2);

View file

@ -1084,22 +1084,47 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
}
@Test
public void testInterpreterSettingConfig() throws InterruptedException,
IOException, InterpreterException {
public void testInterpreterSettingConfig() {
LOGGER.info("testInterpreterSettingConfig >>> ");
Note note = new Note("testInterpreterSettingConfig", "config_test",
interpreterFactory, interpreterSettingManager, null, null, new ArrayList<>());
interpreterFactory, interpreterSettingManager, this, credentials, new ArrayList<>());
// create three paragraphs
// create paragraphs
Paragraph p1 = note.addNewParagraph(anonymous);
Map<String, Object> config = p1.getConfig();
assertTrue(config.containsKey("fontSize"));
assertTrue(config.containsKey("colWidth"));
assertTrue(config.containsKey("runOnSelectionChange"));
assertTrue(config.containsKey("title"));
assertEquals(config.get("fontSize"), 9.0);
assertEquals(config.get("colWidth"), 12.0);
assertEquals(config.get("runOnSelectionChange"), false);
assertEquals(config.get("title"), true);
// The config_test interpreter sets the default parameters
// in interpreter/config_test/interpreter-setting.json
// "config": {
// "runOnSelectionChange": false,
// "title": true
// },
p1.setText("%config_test sleep 1000");
note.runAll(AuthenticationInfo.ANONYMOUS, false);
// wait until first paragraph finishes and second paragraph starts
while (p1.getStatus() != Status.FINISHED) Thread.yield();
// Check if the config_test interpreter default parameter takes effect
LOGGER.info("p1.getConfig() = " + p1.getConfig());
assertEquals(config.get("runOnSelectionChange"), false);
assertEquals(config.get("title"), true);
// The mock1 interpreter does not set default parameters
p1.setText("%mock1 sleep 1000");
note.runAll(AuthenticationInfo.ANONYMOUS, false);
// wait until first paragraph finishes and second paragraph starts
while (p1.getStatus() != Status.FINISHED) Thread.yield();
// Check if the mock1 interpreter parameter is updated
LOGGER.info("changed intp p1.getConfig() = " + p1.getConfig());
assertEquals(config.get("runOnSelectionChange"), true);
assertEquals(config.get("title"), false);
}
@Test

View file

@ -7,8 +7,6 @@
"properties": {
},
"config": {
"fontSize": 9,
"colWidth": 12,
"runOnSelectionChange": false,
"title": true
},