enhancement #I5IOC5 LiteFlowResponse增加一个errorCode

This commit is contained in:
zendwang
2022-07-26 14:59:32 +08:00
parent daa65d0d0e
commit bffd69cd8f
43 changed files with 827 additions and 23 deletions

View File

@@ -0,0 +1,12 @@
package com.yomahub.liteflow.test.exception;
import com.yomahub.liteflow.exception.LiteFlowException;
/**
* 用户自定义带状态码的异常
*/
public class CustomStatefulException extends LiteFlowException {
public CustomStatefulException(int code, String message) {
super(code, message);
}
}

View File

@@ -2,6 +2,7 @@ package com.yomahub.liteflow.test.exception;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.exception.ChainNotFoundException;
import com.yomahub.liteflow.exception.LiteFlowException;
import com.yomahub.liteflow.exception.NoSwitchTargetNodeException;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.test.BaseTest;
@@ -50,4 +51,21 @@ public class Exception2ELSpringTest extends BaseTest {
Assert.assertFalse(response.isSuccess());
throw response.getCause();
}
@Test
public void testInvokeCustomStatefulException() {
LiteflowResponse response = flowExecutor.execute2Resp("chain6", "custom-stateful-exception");
Assert.assertFalse(response.isSuccess());
Assert.assertEquals(300, response.getCode());
Assert.assertNotNull(response.getCause());
Assert.assertTrue(response.getCause() instanceof LiteFlowException);
Assert.assertNotNull(response.getSlot());
}
@Test
public void testNotInvokeCustomStatefulException() {
LiteflowResponse response = flowExecutor.execute2Resp("chain6", "test");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals(0, response.getCode());
}
}

View File

@@ -0,0 +1,31 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.exception.cmp;
import cn.hutool.core.util.StrUtil;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.test.exception.CustomStatefulException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@Component("f")
public class FCmp extends NodeComponent {
private static final Logger LOG = LoggerFactory.getLogger(FCmp.class);
@Override
public void process() {
String str = this.getRequestData();
if(StrUtil.isNotBlank(str) && str.equals("custom-stateful-exception")) {
throw new CustomStatefulException(300, "chain execute custom stateful execption");
}
LOG.info("Fcomp executed!");
}
}

View File

@@ -0,0 +1,24 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.exception.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@Component("g")
public class GCmp extends NodeComponent {
private static final Logger LOG = LoggerFactory.getLogger(GCmp.class);
@Override
public void process() {
LOG.info("Gcomp executed!");
}
}

View File

@@ -16,4 +16,8 @@
SWITCH(e).to(b, c);
</chain>
<chain name="chain6">
THEN(f, g);
</chain>
</flow>