Skip to content

Commit 846d7a8

Browse files
committed
java functions can work but with caveats #1558
1 parent 905f57f commit 846d7a8

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

karate-core/src/main/java/com/intuit/karate/core/ScenarioEngine.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -1209,8 +1209,12 @@ private Object recurseAndDetachAndDeepClone(String name, Object o, Set<Object> s
12091209
if (o instanceof Value) {
12101210
Value value = (Value) o;
12111211
try {
1212-
if (value.canExecute() && value.isMetaObject()) { // js function
1213-
return new JsFunction(value);
1212+
if (value.canExecute()) {
1213+
if (value.isMetaObject()) { // js function
1214+
return new JsFunction(value);
1215+
} else { // java function
1216+
return new JsExecutable(value);
1217+
}
12141218
} else {
12151219
return value;
12161220
}

karate-core/src/main/java/com/intuit/karate/core/ScenarioRuntime.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ private Map<String, Object> initMagicVariables() {
268268
}
269269
if (scenario.isOutlineExample() && !this.isDynamicBackground()) { // init examples row magic variables
270270
Map<String, Object> exampleData = scenario.getExampleData();
271-
exampleData.forEach((k, v) -> map.put(k, v));
271+
map.putAll(exampleData);
272272
map.put("__row", exampleData);
273273
map.put("__num", scenario.getExampleIndex());
274274
}

karate-core/src/main/java/com/intuit/karate/graal/JsExecutable.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,14 @@ public JsExecutable(Value value) {
4242
this.value = value;
4343
}
4444

45+
private static final Object LOCK = new Object();
46+
4547
@Override
4648
public Object execute(Value... arguments) {
47-
if (logger.isTraceEnabled()) {
48-
logger.trace("begin execute: {}", value);
49+
synchronized (LOCK) {
50+
logger.warn("[*** execute ***] global lock on java function possibly from callonce / callSingle: {}", value);
51+
return value.execute(arguments);
4952
}
50-
return value.execute(arguments);
5153
}
5254

5355
}

karate-core/src/test/java/com/intuit/karate/core/parallel/parallel.feature

+12-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ Scenario: one
1515
* match response == { one: '#string' }
1616
* def result = karate.callSingle('call-single-from-feature.feature')
1717
* match result.response == { message: 'from feature' }
18-
# use java class instance from callSingle in config
18+
1919
* match HelloConfigSingle.sayHello('world') == 'hello world'
20-
# use java method instance from callSingle in config
21-
# * match sayHello('world') == 'hello world'
20+
* match HelloOnce.sayHello('world') == 'hello world'
21+
* match sayHello('world') == 'hello world'
2222

2323
Scenario: two
2424
* path 'two'
@@ -28,10 +28,18 @@ Scenario: two
2828
* def result = karate.callSingle('call-single-from-feature.feature')
2929
* match result.response == { message: 'from feature' }
3030

31+
* match HelloConfigSingle.sayHello('world') == 'hello world'
32+
* match HelloOnce.sayHello('world') == 'hello world'
33+
* match sayHello('world') == 'hello world'
34+
3135
Scenario: three
3236
* path 'three'
3337
* method get
3438
* status 200
3539
* match response == { three: '#string' }
3640
* def result = karate.callSingle('call-single-from-feature.feature')
37-
* match result.response == { message: 'from feature' }
41+
* match result.response == { message: 'from feature' }
42+
43+
* match HelloConfigSingle.sayHello('world') == 'hello world'
44+
* match HelloOnce.sayHello('world') == 'hello world'
45+
* match sayHello('world') == 'hello world'

0 commit comments

Comments
 (0)