adapt param usage to polyglot APIs

This commit is contained in:
Jonathan Shook
2020-08-06 13:03:42 -05:00
parent d422a24c6a
commit 625be1db16
4 changed files with 43 additions and 16 deletions

View File

@@ -154,18 +154,19 @@ public class AsyncScriptIntegrationTests {
@Test
public void testScriptParamsVariable() {
ScenarioResult scenarioResult = runScenario("params_variable", "one", "two", "three", "four");
assertThat(scenarioResult.getIOLog()).contains("params.get(\"one\")='two'");
assertThat(scenarioResult.getIOLog()).contains("params.get(\"three\")='four'");
assertThat(scenarioResult.getIOLog()).contains("params.size()=2");
assertThat(scenarioResult.getIOLog()).contains("params.get(\"three\") [overridden-three-five]='five'");
assertThat(scenarioResult.getIOLog()).contains("params.get(\"four\") [defaulted-four-niner]='niner'");
assertThat(scenarioResult.getIOLog()).contains("params[\"one\"]='two'");
assertThat(scenarioResult.getIOLog()).contains("params.[\"three\"]='four'");
assertThat(scenarioResult.getIOLog()).contains("overridden[\"three\"] [overridden-three-five]='five'");
assertThat(scenarioResult.getIOLog()).contains("defaulted.get[\"four\"] [defaulted-four-niner]='niner'");
}
@Test
public void testScriptParamsUndefVariableWithOverride() {
ScenarioResult scenarioResult = runScenario("undef_param", "one", "two", "three", "four");
assertThat(scenarioResult.getIOLog()).contains("before: params.get(\"three\"):four");
assertThat(scenarioResult.getIOLog()).contains("after: params.get(\"three\"):null");
assertThat(scenarioResult.getIOLog()).contains("before: params[\"three\"]:four");
assertThat(scenarioResult.getIOLog()).contains("before: params.three:four");
assertThat(scenarioResult.getIOLog()).contains("after: params[\"three\"]:undefined");
assertThat(scenarioResult.getIOLog()).contains("after: params.three:undefined");
}
@Test
@@ -219,6 +220,7 @@ public class AsyncScriptIntegrationTests {
ScenarioResult scenarioResult = runScenario("threadchange");
int changedTo1At = scenarioResult.getIOLog().indexOf("threads now 1");
int changedTo5At = scenarioResult.getIOLog().indexOf("threads now 5");
System.out.println("IOLOG:\n"+scenarioResult.getIOLog());
assertThat(changedTo1At).isGreaterThan(0);
assertThat(changedTo5At).isGreaterThan(changedTo1At);
}

View File

@@ -1,13 +1,31 @@
print('params.get("one")=\'' + params.get("one") + "'");
print('params.get("three")=\'' + params.get("three") + "'");
print('params.size()=' + params.size());
// With the API support for Polyglot, we lost the ability to expose
// map operations (underlying Java Map API) as well as proxy methods
// on ECMA objects. What works now is object semantics + non-map methods.
// More testing and refinement may be needed to clarify the rules here.
// previously:
// print('params.get("one")=\'' + params.get("one") + "'"); // worked with nashorn
// print('params.get("three")=\'' + params.get("three") + "'");
// print('params.size()=' + params.size());
// Called with one=two three=four
print('params["one"]=\'' + params["one"] + "'");
print('params.["three"]=\'' + params["three"] + "'");
var overrides = {
'three': "five"
};
print('params.get("three") [overridden-three-five]=\'' + params.withOverrides(overrides).get("three") + "'");
var overridden = params.withOverrides(overrides);
print('overridden["three"] [overridden-three-five]=\'' + overridden["three"] + "'");
var defaults = {
'four': "niner"
};
print('params.get("four") [defaulted-four-niner]=\'' + params.withDefaults(defaults).get("four") + "'");
var defaulted = params.withDefaults(defaults);
print('defaulted.get["four"] [defaulted-four-niner]=\'' + defaulted["four"] + "'");

View File

@@ -19,6 +19,8 @@ scenario.start('type=diag;alias=threadchange;cycles=0..100000000;threads=1;inter
activities.threadchange.threads=1;
print("threads now " + activities.threadchange.threads);
print('waiting 500 ms');
scenario.waitMillis(500);
activities.threadchange.threads=5;
print("threads now " + activities.threadchange.threads);
scenario.stop('threadchange');

View File

@@ -1,7 +1,12 @@
// With the API support for Polyglot, we lost the ability to expose
// map operations (underlying Java Map API) as well as proxy methods
// on ECMA objects. What works now is object semantics + non-map methods.
// More testing and refinement may be needed to clarify the rules here.
print("params from command line:");
print(params);
print('before: params.get("three"):' + params.get("three"));
print('before: params.three:' + params.get("three"));
print('before: params["three"]:' + params["three"]);
print('before: params.three:' + params.three);
var overrides = {
'three': "undef",
@@ -10,7 +15,7 @@ var overrides = {
print("params.three after overriding with three:UNDEF");
params = params.withOverrides({'three':'UNDEF'});
print(params);
print('after: params.get("three"):' + params.get("three"));
print('after: params.three:' + params.get("three"));
print('after: params["three"]:' + params["three"]);
print('after: params.three:' + params.three);