Skip to content

Commit

Permalink
bugfix: saga ExpressionEvaluator not support null value (apache#1837)
Browse files Browse the repository at this point in the history
  • Loading branch information
long187 authored and zhangthen committed Nov 1, 2019
1 parent c772c7d commit 5473a62
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ public boolean evaluate(Map<String, Object> variables) {
Object rootObject;
if (StringUtils.hasText(this.rootObjectName)) {
rootObject = variables.get(this.rootObjectName);
if (rootObject == null) {
if (LOGGER.isWarnEnabled()) {
LOGGER.warn("Variable [{}] is not exits. Cannot execute expression {}, return false instead.", rootObjectName, expression.getExpressionString());
}
return false;
}
} else {
rootObject = variables;
}
Expand Down
12 changes: 5 additions & 7 deletions test/src/test/java/io/seata/saga/engine/mock/DemoService.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
package io.seata.saga.engine.mock;

import io.seata.saga.engine.exception.EngineExecutionException;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand All @@ -28,7 +26,7 @@ public class DemoService {

public Map<String, Object> foo(Map<String, Object> input) {
if(input == null){
return new HashMap<>(0);
return null;
}
if("true".equals(input.get("throwException"))){
throw new EngineExecutionException("foo execute failed");
Expand All @@ -43,7 +41,7 @@ public Map<String, Object> foo(Map<String, Object> input) {

public Map<String, Object> compensateFoo(Map<String, Object> input) {
if(input == null){
return new HashMap<>(0);
return null;
}
if("true".equals(input.get("throwException"))){
throw new EngineExecutionException("compensateFoo execute failed");
Expand All @@ -58,7 +56,7 @@ public Map<String, Object> compensateFoo(Map<String, Object> input) {

public Map<String, Object> bar(Map<String, Object> input) {
if(input == null){
return new HashMap<>(0);
return null;
}
if("true".equals(input.get("throwException"))){
throw new EngineExecutionException("bar execute failed");
Expand All @@ -73,7 +71,7 @@ public Map<String, Object> bar(Map<String, Object> input) {

public Map<String, Object> compensateBar(Map<String, Object> input) {
if(input == null){
return new HashMap<>(0);
return null;
}
if("true".equals(input.get("throwException"))){
throw new EngineExecutionException("compensateBar execute failed");
Expand Down Expand Up @@ -159,4 +157,4 @@ public void setName(String name) {
this.name = name;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"Type": "ServiceTask",
"ServiceName": "demoService",
"ServiceMethod": "foo",
"Next": "ChoiceState",
"Next": "ReturnNullState",
"Input": [
{
"fooInput": "$.[a]"
Expand All @@ -18,6 +18,18 @@
"fooResult": "$.#root"
}
},
"ReturnNullState": {
"Type": "ServiceTask",
"ServiceName": "demoService",
"ServiceMethod": "foo",
"Next": "ChoiceState",
"Status": {
"$Exception{io.seata.saga.engine.exception.EngineExecutionException}": "UN",
"$Exception{java.lang.Exception}": "FA",
"#root != null && #root.size() > 0": "SU",
"#root == null || #root.size() == 0": "FA"
}
},
"ChoiceState":{
"Type": "Choice",
"Choices":[
Expand Down

0 comments on commit 5473a62

Please sign in to comment.