mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 20:22:07 +08:00
feature #I8MW6Q 完善测试用例
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
package com.yomahub.liteflow.test.script.aviator.remove;
|
||||
|
||||
import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder;
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.enums.ScriptTypeEnum;
|
||||
import com.yomahub.liteflow.exception.ELParseException;
|
||||
import com.yomahub.liteflow.flow.FlowBus;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.script.ScriptExecutor;
|
||||
import com.yomahub.liteflow.script.ScriptExecutorFactory;
|
||||
import com.yomahub.liteflow.script.exception.ScriptLoadException;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 测试脚本的卸载和重载功能
|
||||
*
|
||||
* @author DaleLee
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/remove/application.properties")
|
||||
@SpringBootTest(classes = LiteFlowAviatorScriptRemoveELTest.class)
|
||||
@EnableAutoConfiguration
|
||||
public class LiteFlowAviatorScriptRemoveELTest extends BaseTest {
|
||||
|
||||
@Resource
|
||||
private FlowExecutor flowExecutor;
|
||||
|
||||
private ScriptExecutor scriptExecutor = ScriptExecutorFactory.loadInstance()
|
||||
.getScriptExecutor(ScriptTypeEnum.AVIATOR.getDisplayName());
|
||||
|
||||
// 仅卸载脚本
|
||||
@Test
|
||||
public void testUnload() {
|
||||
flowExecutor.reloadRule();
|
||||
|
||||
// 获取节点id
|
||||
List<String> nodeIds = scriptExecutor.getNodeIds();
|
||||
Assertions.assertEquals(2, nodeIds.size());
|
||||
Assertions.assertTrue(nodeIds.contains("s1"));
|
||||
Assertions.assertTrue(nodeIds.contains("s2"));
|
||||
|
||||
// 保证脚本可以正常运行
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
Assertions.assertEquals(Long.valueOf(6), context.getData("s1"));
|
||||
|
||||
// 卸载脚本
|
||||
scriptExecutor.unLoad("s1");
|
||||
response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
Assertions.assertFalse(response.isSuccess());
|
||||
Assertions.assertEquals(ScriptLoadException.class, response.getCause().getClass());
|
||||
Assertions.assertEquals("script for node[s1] is not loaded", response.getMessage());
|
||||
|
||||
// 脚本已卸载
|
||||
Assertions.assertFalse(scriptExecutor.getNodeIds().contains("s1"));
|
||||
}
|
||||
|
||||
// 卸载节点和脚本
|
||||
@Test
|
||||
public void testRemove() {
|
||||
flowExecutor.reloadRule();
|
||||
|
||||
// 保证脚本可以正常运行
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
Assertions.assertEquals(Long.valueOf(5), context.getData("s2"));
|
||||
|
||||
// 卸载节点
|
||||
FlowBus.removeNode("s2");
|
||||
|
||||
// 旧 chain 报脚本加载错误
|
||||
response = flowExecutor.execute2Resp("chain2", "arg");
|
||||
Assertions.assertEquals(ScriptLoadException.class, response.getCause().getClass());
|
||||
|
||||
// 新 chian 会找不到节点
|
||||
Assertions.assertThrows(ELParseException.class,
|
||||
() -> LiteFlowChainELBuilder.createChain()
|
||||
.setChainId("chain3")
|
||||
.setEL("THEN(s2)")
|
||||
.build());
|
||||
|
||||
// 节点已卸载
|
||||
Assertions.assertFalse(FlowBus.containNode("s2"));
|
||||
// 脚本已卸载
|
||||
Assertions.assertFalse(scriptExecutor.getNodeIds().contains("s2"));
|
||||
}
|
||||
|
||||
// 重载脚本
|
||||
@Test
|
||||
public void testReloadScript() {
|
||||
flowExecutor.reloadRule();
|
||||
String script = "setData(defaultContext,\"s1\",\"abc\");";
|
||||
FlowBus.reloadScript("s1", script);
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
// 执行结果变更
|
||||
Assertions.assertEquals("abc", context.getData("s1"));
|
||||
// 脚本变更
|
||||
Assertions.assertEquals(FlowBus.getNode("s1").getScript(), script);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
liteflow.rule-source=remove/flow.xml
|
||||
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<flow>
|
||||
<nodes>
|
||||
<node id="s1" name="普通脚本1" type="script" language="aviator">
|
||||
<![CDATA[
|
||||
a=1;
|
||||
b=2;
|
||||
c=3;
|
||||
setData(defaultContext,"s1",a+b+c);
|
||||
]]>
|
||||
</node>
|
||||
|
||||
<node id="s2" name="普通脚本2" type="script" language="aviator">
|
||||
<![CDATA[
|
||||
a=1;
|
||||
b=2;
|
||||
c=3;
|
||||
setData(defaultContext,"s2",a*b+c);
|
||||
]]>
|
||||
</node>
|
||||
</nodes>
|
||||
|
||||
<chain name="chain1">
|
||||
THEN(s1);
|
||||
</chain>
|
||||
|
||||
<chain name="chain2">
|
||||
THEN(s2);
|
||||
</chain>
|
||||
</flow>
|
||||
@@ -23,7 +23,7 @@ import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 测试脚本的卸载功能
|
||||
* 测试脚本的卸载和重载功能
|
||||
*
|
||||
* @author DaleLee
|
||||
*/
|
||||
@@ -36,14 +36,17 @@ public class LiteFlowJsScriptRemoveELTest extends BaseTest {
|
||||
@Resource
|
||||
private FlowExecutor flowExecutor;
|
||||
|
||||
private ScriptExecutor scriptExecutor = ScriptExecutorFactory.loadInstance()
|
||||
.getScriptExecutor(ScriptTypeEnum.JS.getDisplayName());
|
||||
|
||||
// 仅卸载脚本
|
||||
@Test
|
||||
public void testUnload() {
|
||||
ScriptExecutor scriptExecutor = ScriptExecutorFactory.loadInstance()
|
||||
.getScriptExecutor(ScriptTypeEnum.JS.getDisplayName());
|
||||
flowExecutor.reloadRule();
|
||||
|
||||
// 获取节点id
|
||||
List<String> nodeIds = scriptExecutor.getNodeIds();
|
||||
Assertions.assertEquals(nodeIds.size(), 2);
|
||||
Assertions.assertEquals(2, nodeIds.size());
|
||||
Assertions.assertTrue(nodeIds.contains("s1"));
|
||||
Assertions.assertTrue(nodeIds.contains("s2"));
|
||||
|
||||
@@ -62,8 +65,50 @@ public class LiteFlowJsScriptRemoveELTest extends BaseTest {
|
||||
|
||||
// 脚本已卸载
|
||||
Assertions.assertFalse(scriptExecutor.getNodeIds().contains("s1"));
|
||||
}
|
||||
|
||||
// 卸载节点和脚本
|
||||
@Test
|
||||
public void testRemove() {
|
||||
flowExecutor.reloadRule();
|
||||
|
||||
// 保证脚本可以正常运行
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
Assertions.assertEquals(Integer.valueOf(5), context.getData("s2"));
|
||||
|
||||
// 卸载节点
|
||||
FlowBus.removeNode("s2");
|
||||
|
||||
// 旧 chain 报脚本加载错误
|
||||
response = flowExecutor.execute2Resp("chain2", "arg");
|
||||
Assertions.assertEquals(ScriptLoadException.class, response.getCause().getClass());
|
||||
|
||||
// 新 chian 会找不到节点
|
||||
Assertions.assertThrows(ELParseException.class,
|
||||
() -> LiteFlowChainELBuilder.createChain()
|
||||
.setChainId("chain3")
|
||||
.setEL("THEN(s2)")
|
||||
.build());
|
||||
|
||||
// 节点已卸载
|
||||
Assertions.assertFalse(FlowBus.containNode("s1"));
|
||||
Assertions.assertFalse(FlowBus.removeNode("s1"));
|
||||
Assertions.assertFalse(FlowBus.containNode("s2"));
|
||||
// 脚本已卸载
|
||||
Assertions.assertFalse(scriptExecutor.getNodeIds().contains("s2"));
|
||||
}
|
||||
|
||||
// 重载脚本
|
||||
@Test
|
||||
public void testReloadScript() {
|
||||
flowExecutor.reloadRule();
|
||||
String script = "defaultContext.setData(\"s1\",\"abc\");";
|
||||
FlowBus.reloadScript("s1", script);
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
// 执行结果变更
|
||||
Assertions.assertEquals("abc", context.getData("s1"));
|
||||
// 脚本变更
|
||||
Assertions.assertEquals(FlowBus.getNode("s1").getScript(), script);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
package com.yomahub.liteflow.test.script.groovy.remove;
|
||||
|
||||
import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder;
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.enums.ScriptTypeEnum;
|
||||
import com.yomahub.liteflow.exception.ELParseException;
|
||||
import com.yomahub.liteflow.flow.FlowBus;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.script.ScriptExecutor;
|
||||
import com.yomahub.liteflow.script.ScriptExecutorFactory;
|
||||
import com.yomahub.liteflow.script.exception.ScriptLoadException;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 测试脚本的卸载和重载功能
|
||||
*
|
||||
* @author DaleLee
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/remove/application.properties")
|
||||
@SpringBootTest(classes = LiteFlowGroovyScriptRemoveELTest.class)
|
||||
@EnableAutoConfiguration
|
||||
public class LiteFlowGroovyScriptRemoveELTest extends BaseTest {
|
||||
|
||||
@Resource
|
||||
private FlowExecutor flowExecutor;
|
||||
|
||||
private ScriptExecutor scriptExecutor = ScriptExecutorFactory.loadInstance()
|
||||
.getScriptExecutor(ScriptTypeEnum.GROOVY.getDisplayName());
|
||||
|
||||
// 仅卸载脚本
|
||||
@Test
|
||||
public void testUnload() {
|
||||
flowExecutor.reloadRule();
|
||||
|
||||
// 获取节点id
|
||||
List<String> nodeIds = scriptExecutor.getNodeIds();
|
||||
Assertions.assertEquals(2, nodeIds.size());
|
||||
Assertions.assertTrue(nodeIds.contains("s1"));
|
||||
Assertions.assertTrue(nodeIds.contains("s2"));
|
||||
|
||||
// 保证脚本可以正常运行
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
Assertions.assertEquals(Integer.valueOf(6), context.getData("s1"));
|
||||
|
||||
// 卸载脚本
|
||||
scriptExecutor.unLoad("s1");
|
||||
response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
Assertions.assertFalse(response.isSuccess());
|
||||
Assertions.assertEquals(ScriptLoadException.class, response.getCause().getClass());
|
||||
Assertions.assertEquals("script for node[s1] is not loaded", response.getMessage());
|
||||
|
||||
// 脚本已卸载
|
||||
Assertions.assertFalse(scriptExecutor.getNodeIds().contains("s1"));
|
||||
}
|
||||
|
||||
// 卸载节点和脚本
|
||||
@Test
|
||||
public void testRemove() {
|
||||
flowExecutor.reloadRule();
|
||||
|
||||
// 保证脚本可以正常运行
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
Assertions.assertEquals(Integer.valueOf(5), context.getData("s2"));
|
||||
|
||||
// 卸载节点
|
||||
FlowBus.removeNode("s2");
|
||||
|
||||
// 旧 chain 报脚本加载错误
|
||||
response = flowExecutor.execute2Resp("chain2", "arg");
|
||||
Assertions.assertEquals(ScriptLoadException.class, response.getCause().getClass());
|
||||
|
||||
// 新 chian 会找不到节点
|
||||
Assertions.assertThrows(ELParseException.class,
|
||||
() -> LiteFlowChainELBuilder.createChain()
|
||||
.setChainId("chain3")
|
||||
.setEL("THEN(s2)")
|
||||
.build());
|
||||
|
||||
// 节点已卸载
|
||||
Assertions.assertFalse(FlowBus.containNode("s2"));
|
||||
// 脚本已卸载
|
||||
Assertions.assertFalse(scriptExecutor.getNodeIds().contains("s2"));
|
||||
}
|
||||
|
||||
// 重载脚本
|
||||
@Test
|
||||
public void testReloadScript() {
|
||||
flowExecutor.reloadRule();
|
||||
String script = "defaultContext.setData(\"s1\",\"abc\");";
|
||||
FlowBus.reloadScript("s1", script);
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
// 执行结果变更
|
||||
Assertions.assertEquals("abc", context.getData("s1"));
|
||||
// 脚本变更
|
||||
Assertions.assertEquals(FlowBus.getNode("s1").getScript(), script);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
liteflow.rule-source=remove/flow.xml
|
||||
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<flow>
|
||||
<nodes>
|
||||
<node id="s1" name="普通脚本1" type="script" language="groovy">
|
||||
<![CDATA[
|
||||
int a=1;
|
||||
int b=2;
|
||||
int c=3;
|
||||
defaultContext.setData("s1",a+b+c);
|
||||
]]>
|
||||
</node>
|
||||
|
||||
<node id="s2" name="普通脚本2" type="script" language="groovy">
|
||||
<![CDATA[
|
||||
int a=1;
|
||||
int b=2;
|
||||
int c=3;
|
||||
defaultContext.setData("s2",a*b+c);
|
||||
]]>
|
||||
</node>
|
||||
</nodes>
|
||||
|
||||
<chain name="chain1">
|
||||
THEN(s1);
|
||||
</chain>
|
||||
|
||||
<chain name="chain2">
|
||||
THEN(s2);
|
||||
</chain>
|
||||
</flow>
|
||||
@@ -0,0 +1,124 @@
|
||||
package com.yomahub.liteflow.test.script.java.remove;
|
||||
|
||||
import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder;
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.enums.ScriptTypeEnum;
|
||||
import com.yomahub.liteflow.exception.ELParseException;
|
||||
import com.yomahub.liteflow.flow.FlowBus;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.script.ScriptExecutor;
|
||||
import com.yomahub.liteflow.script.ScriptExecutorFactory;
|
||||
import com.yomahub.liteflow.script.exception.ScriptLoadException;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 测试脚本的卸载和重载功能
|
||||
*
|
||||
* @author DaleLee
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/remove/application.properties")
|
||||
@SpringBootTest(classes = LiteFlowJavaScriptRemoveELTest.class)
|
||||
@EnableAutoConfiguration
|
||||
public class LiteFlowJavaScriptRemoveELTest extends BaseTest {
|
||||
|
||||
@Resource
|
||||
private FlowExecutor flowExecutor;
|
||||
|
||||
private ScriptExecutor scriptExecutor = ScriptExecutorFactory.loadInstance()
|
||||
.getScriptExecutor(ScriptTypeEnum.JAVA.getDisplayName());
|
||||
|
||||
// 仅卸载脚本
|
||||
@Test
|
||||
public void testUnload() {
|
||||
flowExecutor.reloadRule();
|
||||
|
||||
// 获取节点id
|
||||
List<String> nodeIds = scriptExecutor.getNodeIds();
|
||||
Assertions.assertEquals(2, nodeIds.size());
|
||||
Assertions.assertTrue(nodeIds.contains("s1"));
|
||||
Assertions.assertTrue(nodeIds.contains("s2"));
|
||||
|
||||
// 保证脚本可以正常运行
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
Assertions.assertEquals(Integer.valueOf(6), context.getData("s1"));
|
||||
|
||||
// 卸载脚本
|
||||
scriptExecutor.unLoad("s1");
|
||||
response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
Assertions.assertFalse(response.isSuccess());
|
||||
Assertions.assertEquals(ScriptLoadException.class, response.getCause().getClass());
|
||||
Assertions.assertEquals("script for node[s1] is not loaded", response.getMessage());
|
||||
|
||||
// 脚本已卸载
|
||||
Assertions.assertFalse(scriptExecutor.getNodeIds().contains("s1"));
|
||||
}
|
||||
|
||||
// 卸载节点和脚本
|
||||
@Test
|
||||
public void testRemove() {
|
||||
flowExecutor.reloadRule();
|
||||
|
||||
// 保证脚本可以正常运行
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
Assertions.assertEquals(Integer.valueOf(5), context.getData("s2"));
|
||||
|
||||
// 卸载节点
|
||||
FlowBus.removeNode("s2");
|
||||
|
||||
// 旧 chain 报脚本加载错误
|
||||
response = flowExecutor.execute2Resp("chain2", "arg");
|
||||
Assertions.assertEquals(ScriptLoadException.class, response.getCause().getClass());
|
||||
|
||||
// 新 chian 会找不到节点
|
||||
Assertions.assertThrows(ELParseException.class,
|
||||
() -> LiteFlowChainELBuilder.createChain()
|
||||
.setChainId("chain3")
|
||||
.setEL("THEN(s2)")
|
||||
.build());
|
||||
|
||||
// 节点已卸载
|
||||
Assertions.assertFalse(FlowBus.containNode("s2"));
|
||||
// 脚本已卸载
|
||||
Assertions.assertFalse(scriptExecutor.getNodeIds().contains("s2"));
|
||||
}
|
||||
|
||||
// 重载脚本
|
||||
@Test
|
||||
public void testReloadScript() {
|
||||
flowExecutor.reloadRule();
|
||||
String script = " import com.yomahub.liteflow.slot.DefaultContext;\n" +
|
||||
" import com.yomahub.liteflow.script.body.JaninoCommonScriptBody;\n" +
|
||||
" import com.yomahub.liteflow.script.ScriptExecuteWrap;\n" +
|
||||
"\n" +
|
||||
" public class Demo implements JaninoCommonScriptBody {\n" +
|
||||
" public Void body(ScriptExecuteWrap wrap) {\n" +
|
||||
" DefaultContext ctx = (DefaultContext) wrap.getCmp().getFirstContextBean();\n" +
|
||||
" ctx.setData(\"s1\", \"abc\");\n" +
|
||||
" return null;\n" +
|
||||
" }\n" +
|
||||
" }";
|
||||
FlowBus.reloadScript("s1", script);
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
// 执行结果变更
|
||||
Assertions.assertEquals("abc", context.getData("s1"));
|
||||
// 脚本变更
|
||||
Assertions.assertEquals(FlowBus.getNode("s1").getScript(), script);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
liteflow.rule-source=remove/flow.xml
|
||||
@@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<flow>
|
||||
<nodes>
|
||||
<node id="s1" name="普通脚本1" type="script" language="java">
|
||||
<![CDATA[
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import com.yomahub.liteflow.script.body.JaninoCommonScriptBody;
|
||||
import com.yomahub.liteflow.script.ScriptExecuteWrap;
|
||||
|
||||
public class Demo implements JaninoCommonScriptBody {
|
||||
public Void body(ScriptExecuteWrap wrap) {
|
||||
int a = 1;
|
||||
int b = 2;
|
||||
int c = 3;
|
||||
DefaultContext ctx = (DefaultContext) wrap.getCmp().getFirstContextBean();
|
||||
ctx.setData("s1", a + b + c);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</node>
|
||||
|
||||
<node id="s2" name="普通脚本2" type="script" language="java">
|
||||
<![CDATA[
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import com.yomahub.liteflow.script.body.JaninoCommonScriptBody;
|
||||
import com.yomahub.liteflow.script.ScriptExecuteWrap;
|
||||
|
||||
public class Demo implements JaninoCommonScriptBody {
|
||||
public Void body(ScriptExecuteWrap wrap) {
|
||||
int a = 1;
|
||||
int b = 2;
|
||||
int c = 3;
|
||||
DefaultContext ctx = (DefaultContext) wrap.getCmp().getFirstContextBean();
|
||||
ctx.setData("s2", a * b + c);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</node>
|
||||
</nodes>
|
||||
|
||||
<chain name="chain1">
|
||||
THEN(s1);
|
||||
</chain>
|
||||
|
||||
<chain name="chain2">
|
||||
THEN(s2);
|
||||
</chain>
|
||||
</flow>
|
||||
@@ -16,7 +16,6 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
@@ -47,7 +46,7 @@ public class LiteFlowJsScriptRemoveELTest extends BaseTest {
|
||||
|
||||
// 获取节点id
|
||||
List<String> nodeIds = scriptExecutor.getNodeIds();
|
||||
Assertions.assertEquals(nodeIds.size(), 2);
|
||||
Assertions.assertEquals(2, nodeIds.size());
|
||||
Assertions.assertTrue(nodeIds.contains("s1"));
|
||||
Assertions.assertTrue(nodeIds.contains("s2"));
|
||||
|
||||
@@ -55,7 +54,7 @@ public class LiteFlowJsScriptRemoveELTest extends BaseTest {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
Assertions.assertEquals(Integer.valueOf(6), context.getData("s1"));
|
||||
Assertions.assertEquals(Double.valueOf(6), context.getData("s1"));
|
||||
|
||||
// 卸载脚本
|
||||
scriptExecutor.unLoad("s1");
|
||||
@@ -77,7 +76,7 @@ public class LiteFlowJsScriptRemoveELTest extends BaseTest {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
Assertions.assertEquals(Integer.valueOf(5), context.getData("s2"));
|
||||
Assertions.assertEquals(Double.valueOf(5), context.getData("s2"));
|
||||
|
||||
// 卸载节点
|
||||
FlowBus.removeNode("s2");
|
||||
@@ -88,13 +87,28 @@ public class LiteFlowJsScriptRemoveELTest extends BaseTest {
|
||||
|
||||
// 新 chian 会找不到节点
|
||||
Assertions.assertThrows(ELParseException.class,
|
||||
() -> LiteFlowChainELBuilder.createChain().setChainId("chain3").setEL(
|
||||
"THEN(s2)"
|
||||
).build());
|
||||
() -> LiteFlowChainELBuilder.createChain()
|
||||
.setChainId("chain3")
|
||||
.setEL("THEN(s2)")
|
||||
.build());
|
||||
|
||||
// 节点已卸载
|
||||
Assertions.assertFalse(FlowBus.containNode("s2"));
|
||||
// 脚本已卸载
|
||||
Assertions.assertFalse(scriptExecutor.getNodeIds().contains("s2"));
|
||||
}
|
||||
|
||||
// 重载脚本
|
||||
@Test
|
||||
public void testReloadScript() {
|
||||
flowExecutor.reloadRule();
|
||||
String script = "defaultContext.setData(\"s1\",\"abc\");";
|
||||
FlowBus.reloadScript("s1", script);
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
// 执行结果变更
|
||||
Assertions.assertEquals("abc", context.getData("s1"));
|
||||
// 脚本变更
|
||||
Assertions.assertEquals(FlowBus.getNode("s1").getScript(), script);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
package com.yomahub.liteflow.test.script.lua.remove;
|
||||
|
||||
import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder;
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.enums.ScriptTypeEnum;
|
||||
import com.yomahub.liteflow.exception.ELParseException;
|
||||
import com.yomahub.liteflow.flow.FlowBus;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.script.ScriptExecutor;
|
||||
import com.yomahub.liteflow.script.ScriptExecutorFactory;
|
||||
import com.yomahub.liteflow.script.exception.ScriptLoadException;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 测试脚本的卸载和重载功能
|
||||
*
|
||||
* @author DaleLee
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/remove/application.properties")
|
||||
@SpringBootTest(classes = LiteFlowLuaScriptRemoveELTest.class)
|
||||
@EnableAutoConfiguration
|
||||
public class LiteFlowLuaScriptRemoveELTest extends BaseTest {
|
||||
|
||||
@Resource
|
||||
private FlowExecutor flowExecutor;
|
||||
|
||||
private ScriptExecutor scriptExecutor = ScriptExecutorFactory.loadInstance()
|
||||
.getScriptExecutor(ScriptTypeEnum.LUA.getDisplayName());
|
||||
|
||||
// 仅卸载脚本
|
||||
@Test
|
||||
public void testUnload() {
|
||||
flowExecutor.reloadRule();
|
||||
|
||||
// 获取节点id
|
||||
List<String> nodeIds = scriptExecutor.getNodeIds();
|
||||
Assertions.assertEquals(2, nodeIds.size());
|
||||
Assertions.assertTrue(nodeIds.contains("s1"));
|
||||
Assertions.assertTrue(nodeIds.contains("s2"));
|
||||
|
||||
// 保证脚本可以正常运行
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
Assertions.assertEquals(Integer.valueOf(6), context.getData("s1"));
|
||||
|
||||
// 卸载脚本
|
||||
scriptExecutor.unLoad("s1");
|
||||
response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
Assertions.assertFalse(response.isSuccess());
|
||||
Assertions.assertEquals(ScriptLoadException.class, response.getCause().getClass());
|
||||
Assertions.assertEquals("script for node[s1] is not loaded", response.getMessage());
|
||||
|
||||
// 脚本已卸载
|
||||
Assertions.assertFalse(scriptExecutor.getNodeIds().contains("s1"));
|
||||
}
|
||||
|
||||
// 卸载节点和脚本
|
||||
@Test
|
||||
public void testRemove() {
|
||||
flowExecutor.reloadRule();
|
||||
|
||||
// 保证脚本可以正常运行
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
Assertions.assertEquals(Integer.valueOf(5), context.getData("s2"));
|
||||
|
||||
// 卸载节点
|
||||
FlowBus.removeNode("s2");
|
||||
|
||||
// 旧 chain 报脚本加载错误
|
||||
response = flowExecutor.execute2Resp("chain2", "arg");
|
||||
Assertions.assertEquals(ScriptLoadException.class, response.getCause().getClass());
|
||||
|
||||
// 新 chian 会找不到节点
|
||||
Assertions.assertThrows(ELParseException.class,
|
||||
() -> LiteFlowChainELBuilder.createChain()
|
||||
.setChainId("chain3")
|
||||
.setEL("THEN(s2)")
|
||||
.build());
|
||||
|
||||
// 节点已卸载
|
||||
Assertions.assertFalse(FlowBus.containNode("s2"));
|
||||
// 脚本已卸载
|
||||
Assertions.assertFalse(scriptExecutor.getNodeIds().contains("s2"));
|
||||
}
|
||||
|
||||
// 重载脚本
|
||||
@Test
|
||||
public void testReloadScript() {
|
||||
flowExecutor.reloadRule();
|
||||
String script = "defaultContext:setData(\"s1\",\"abc\");";
|
||||
FlowBus.reloadScript("s1", script);
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
// 执行结果变更
|
||||
Assertions.assertEquals("abc", context.getData("s1"));
|
||||
// 脚本变更
|
||||
Assertions.assertEquals(FlowBus.getNode("s1").getScript(), script);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
liteflow.rule-source=remove/flow.xml
|
||||
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<flow>
|
||||
<nodes>
|
||||
<node id="s1" name="普通脚本1" type="script" language = 'lua'>
|
||||
<![CDATA[
|
||||
local a=1;
|
||||
local b=2;
|
||||
local c=3;
|
||||
defaultContext:setData("s1",a+b+c);
|
||||
]]>
|
||||
</node>
|
||||
|
||||
<node id="s2" name="普通脚本2" type="script" language="lua">
|
||||
<![CDATA[
|
||||
local a=1;
|
||||
local b=2;
|
||||
local c=3;
|
||||
defaultContext:setData("s2",a*b+c);
|
||||
]]>
|
||||
</node>
|
||||
</nodes>
|
||||
|
||||
<chain name="chain1">
|
||||
THEN(s1);
|
||||
</chain>
|
||||
|
||||
<chain name="chain2">
|
||||
THEN(s2);
|
||||
</chain>
|
||||
</flow>
|
||||
@@ -0,0 +1,114 @@
|
||||
package com.yomahub.liteflow.test.script.python.remove;
|
||||
|
||||
import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder;
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.enums.ScriptTypeEnum;
|
||||
import com.yomahub.liteflow.exception.ELParseException;
|
||||
import com.yomahub.liteflow.flow.FlowBus;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.script.ScriptExecutor;
|
||||
import com.yomahub.liteflow.script.ScriptExecutorFactory;
|
||||
import com.yomahub.liteflow.script.exception.ScriptLoadException;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 测试脚本的卸载和重载功能
|
||||
*
|
||||
* @author DaleLee
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/remove/application.properties")
|
||||
@SpringBootTest(classes = LiteFlowPythonScriptRemoveELTest.class)
|
||||
@EnableAutoConfiguration
|
||||
public class LiteFlowPythonScriptRemoveELTest extends BaseTest {
|
||||
|
||||
@Resource
|
||||
private FlowExecutor flowExecutor;
|
||||
|
||||
private ScriptExecutor scriptExecutor = ScriptExecutorFactory.loadInstance()
|
||||
.getScriptExecutor(ScriptTypeEnum.PYTHON.getDisplayName());
|
||||
|
||||
// 仅卸载脚本
|
||||
@Test
|
||||
public void testUnload() {
|
||||
flowExecutor.reloadRule();
|
||||
|
||||
// 获取节点id
|
||||
List<String> nodeIds = scriptExecutor.getNodeIds();
|
||||
Assertions.assertEquals(2, nodeIds.size());
|
||||
Assertions.assertTrue(nodeIds.contains("s1"));
|
||||
Assertions.assertTrue(nodeIds.contains("s2"));
|
||||
|
||||
// 保证脚本可以正常运行
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
Assertions.assertEquals(Integer.valueOf(6), context.getData("s1"));
|
||||
|
||||
// 卸载脚本
|
||||
scriptExecutor.unLoad("s1");
|
||||
response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
Assertions.assertFalse(response.isSuccess());
|
||||
Assertions.assertEquals(ScriptLoadException.class, response.getCause().getClass());
|
||||
Assertions.assertEquals("script for node[s1] is not loaded", response.getMessage());
|
||||
|
||||
// 脚本已卸载
|
||||
Assertions.assertFalse(scriptExecutor.getNodeIds().contains("s1"));
|
||||
}
|
||||
|
||||
// 卸载节点和脚本
|
||||
@Test
|
||||
public void testRemove() {
|
||||
flowExecutor.reloadRule();
|
||||
|
||||
// 保证脚本可以正常运行
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
Assertions.assertEquals(Integer.valueOf(5), context.getData("s2"));
|
||||
|
||||
// 卸载节点
|
||||
FlowBus.removeNode("s2");
|
||||
|
||||
// 旧 chain 报脚本加载错误
|
||||
response = flowExecutor.execute2Resp("chain2", "arg");
|
||||
Assertions.assertEquals(ScriptLoadException.class, response.getCause().getClass());
|
||||
|
||||
// 新 chian 会找不到节点
|
||||
Assertions.assertThrows(ELParseException.class,
|
||||
() -> LiteFlowChainELBuilder.createChain()
|
||||
.setChainId("chain3")
|
||||
.setEL("THEN(s2)")
|
||||
.build());
|
||||
|
||||
// 节点已卸载
|
||||
Assertions.assertFalse(FlowBus.containNode("s2"));
|
||||
// 脚本已卸载
|
||||
Assertions.assertFalse(scriptExecutor.getNodeIds().contains("s2"));
|
||||
}
|
||||
|
||||
// 重载脚本
|
||||
@Test
|
||||
public void testReloadScript() {
|
||||
flowExecutor.reloadRule();
|
||||
String script = "defaultContext.setData(\"s1\",\"abc\");";
|
||||
FlowBus.reloadScript("s1", script);
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
// 执行结果变更
|
||||
Assertions.assertEquals("abc", context.getData("s1"));
|
||||
// 脚本变更
|
||||
Assertions.assertEquals(FlowBus.getNode("s1").getScript(), script);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
liteflow.rule-source=remove/flow.xml
|
||||
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<flow>
|
||||
<nodes>
|
||||
<node id="s1" name="普通脚本1" type="script" language="python">
|
||||
<![CDATA[
|
||||
a=1
|
||||
b=2
|
||||
c=3
|
||||
defaultContext.setData("s1",a+b+c)
|
||||
]]>
|
||||
</node>
|
||||
|
||||
<node id="s2" name="普通脚本2" type="script" language="python">
|
||||
<![CDATA[
|
||||
a=1
|
||||
b=2
|
||||
c=3
|
||||
defaultContext.setData("s2",a*b+c)
|
||||
]]>
|
||||
</node>
|
||||
</nodes>
|
||||
|
||||
<chain name="chain1">
|
||||
THEN(s1);
|
||||
</chain>
|
||||
|
||||
<chain name="chain2">
|
||||
THEN(s2);
|
||||
</chain>
|
||||
</flow>
|
||||
@@ -0,0 +1,114 @@
|
||||
package com.yomahub.liteflow.test.script.qlexpress.remove;
|
||||
|
||||
import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder;
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.enums.ScriptTypeEnum;
|
||||
import com.yomahub.liteflow.exception.ELParseException;
|
||||
import com.yomahub.liteflow.flow.FlowBus;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.script.ScriptExecutor;
|
||||
import com.yomahub.liteflow.script.ScriptExecutorFactory;
|
||||
import com.yomahub.liteflow.script.exception.ScriptLoadException;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 测试脚本的卸载和重载功能
|
||||
*
|
||||
* @author DaleLee
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/remove/application.properties")
|
||||
@SpringBootTest(classes = LiteFlowQLExpressScriptRemoveELTest.class)
|
||||
@EnableAutoConfiguration
|
||||
public class LiteFlowQLExpressScriptRemoveELTest extends BaseTest {
|
||||
|
||||
@Resource
|
||||
private FlowExecutor flowExecutor;
|
||||
|
||||
private ScriptExecutor scriptExecutor = ScriptExecutorFactory.loadInstance()
|
||||
.getScriptExecutor(ScriptTypeEnum.QLEXPRESS.getDisplayName());
|
||||
|
||||
// 仅卸载脚本
|
||||
@Test
|
||||
public void testUnload() {
|
||||
flowExecutor.reloadRule();
|
||||
|
||||
// 获取节点id
|
||||
List<String> nodeIds = scriptExecutor.getNodeIds();
|
||||
Assertions.assertEquals(2, nodeIds.size());
|
||||
Assertions.assertTrue(nodeIds.contains("s1"));
|
||||
Assertions.assertTrue(nodeIds.contains("s2"));
|
||||
|
||||
// 保证脚本可以正常运行
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
Assertions.assertEquals(Integer.valueOf(6), context.getData("s1"));
|
||||
|
||||
// 卸载脚本
|
||||
scriptExecutor.unLoad("s1");
|
||||
response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
Assertions.assertFalse(response.isSuccess());
|
||||
Assertions.assertEquals(ScriptLoadException.class, response.getCause().getClass());
|
||||
Assertions.assertEquals("script for node[s1] is not loaded", response.getMessage());
|
||||
|
||||
// 脚本已卸载
|
||||
Assertions.assertFalse(scriptExecutor.getNodeIds().contains("s1"));
|
||||
}
|
||||
|
||||
// 卸载节点和脚本
|
||||
@Test
|
||||
public void testRemove() {
|
||||
flowExecutor.reloadRule();
|
||||
|
||||
// 保证脚本可以正常运行
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
Assertions.assertEquals(Integer.valueOf(5), context.getData("s2"));
|
||||
|
||||
// 卸载节点
|
||||
FlowBus.removeNode("s2");
|
||||
|
||||
// 旧 chain 报脚本加载错误
|
||||
response = flowExecutor.execute2Resp("chain2", "arg");
|
||||
Assertions.assertEquals(ScriptLoadException.class, response.getCause().getClass());
|
||||
|
||||
// 新 chian 会找不到节点
|
||||
Assertions.assertThrows(ELParseException.class,
|
||||
() -> LiteFlowChainELBuilder.createChain()
|
||||
.setChainId("chain3")
|
||||
.setEL("THEN(s2)")
|
||||
.build());
|
||||
|
||||
// 节点已卸载
|
||||
Assertions.assertFalse(FlowBus.containNode("s2"));
|
||||
// 脚本已卸载
|
||||
Assertions.assertFalse(scriptExecutor.getNodeIds().contains("s2"));
|
||||
}
|
||||
|
||||
// 重载脚本
|
||||
@Test
|
||||
public void testReloadScript() {
|
||||
flowExecutor.reloadRule();
|
||||
String script = "defaultContext.setData(\"s1\",\"abc\");";
|
||||
FlowBus.reloadScript("s1", script);
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
// 执行结果变更
|
||||
Assertions.assertEquals("abc", context.getData("s1"));
|
||||
// 脚本变更
|
||||
Assertions.assertEquals(FlowBus.getNode("s1").getScript(), script);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
liteflow.rule-source=remove/flow.xml
|
||||
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<flow>
|
||||
<nodes>
|
||||
<node id="s1" name="普通脚本1" type="script" language="qlexpress">
|
||||
<![CDATA[
|
||||
a=1;
|
||||
b=2;
|
||||
c=3;
|
||||
defaultContext.setData("s1",a+b+c);
|
||||
]]>
|
||||
</node>
|
||||
|
||||
<node id="s2" name="普通脚本2" type="script" language="qlexpress">
|
||||
<![CDATA[
|
||||
a=1;
|
||||
b=2;
|
||||
c=3;
|
||||
defaultContext.setData("s2",a*b+c);
|
||||
]]>
|
||||
</node>
|
||||
</nodes>
|
||||
|
||||
<chain name="chain1">
|
||||
THEN(s1);
|
||||
</chain>
|
||||
|
||||
<chain name="chain2">
|
||||
THEN(s2);
|
||||
</chain>
|
||||
</flow>
|
||||
Reference in New Issue
Block a user