diff --git a/liteflow-core/pom.xml b/liteflow-core/pom.xml
index 8dab334f8..00fd1021b 100644
--- a/liteflow-core/pom.xml
+++ b/liteflow-core/pom.xml
@@ -61,6 +61,7 @@
junit
junit
+ test
org.apache.curator
@@ -84,5 +85,15 @@
com.alibaba
transmittable-thread-local
+
+ org.apache.curator
+ curator-test
+ test
+
+
+ com.101tec
+ zkclient
+ test
+
diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/entity/flow/Chain.java b/liteflow-core/src/main/java/com/yomahub/liteflow/entity/flow/Chain.java
index 50ee5fef4..c61b4330b 100644
--- a/liteflow-core/src/main/java/com/yomahub/liteflow/entity/flow/Chain.java
+++ b/liteflow-core/src/main/java/com/yomahub/liteflow/entity/flow/Chain.java
@@ -102,7 +102,6 @@ public class Chain implements Executable {
}
}
} else if (condition instanceof WhenCondition) {
-
executeAsyncCondition((WhenCondition) condition, slotIndex, slot.getRequestId());
}
}
diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/YmlFlowParser.java b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/YmlFlowParser.java
index ddd9ff7e7..ab611b34f 100644
--- a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/YmlFlowParser.java
+++ b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/YmlFlowParser.java
@@ -24,7 +24,7 @@ public abstract class YmlFlowParser extends JsonFlowParser{
parse(ruleObject.toJSONString());
}
- private JSONObject convertToJson(String yamlString) {
+ protected JSONObject convertToJson(String yamlString) {
Yaml yaml= new Yaml();
Map map = yaml.load(yamlString);
JSONObject jsonObject = new JSONObject(map);
diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/ZookeeperYmlFlowParser.java b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/ZookeeperYmlFlowParser.java
index 2f79bd6ac..a5fc3b826 100644
--- a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/ZookeeperYmlFlowParser.java
+++ b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/ZookeeperYmlFlowParser.java
@@ -1,6 +1,7 @@
package com.yomahub.liteflow.parser;
import cn.hutool.core.util.StrUtil;
+import com.alibaba.fastjson.JSONObject;
import com.yomahub.liteflow.exception.ParseException;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
@@ -45,12 +46,14 @@ public class ZookeeperYmlFlowParser extends YmlFlowParser{
String content = new String(client.getData().forPath(nodePath));
-
if (StrUtil.isBlank(content)) {
String error = MessageFormat.format("the node[{0}] value is empty", nodePath);
throw new ParseException(error);
}
- parse(content);
+
+ JSONObject ruleObject = convertToJson(content);
+
+ parse(ruleObject.toJSONString());
final NodeCache cache = new NodeCache(client,nodePath);
@@ -61,7 +64,8 @@ public class ZookeeperYmlFlowParser extends YmlFlowParser{
public void nodeChanged() throws Exception {
String content = new String(cache.getCurrentData().getData());
LOG.info("stating load flow config....");
- parse(content);
+ JSONObject ruleObject = convertToJson(content);
+ parse(ruleObject.toJSONString());
}
});
}
diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java b/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java
index 736d2678d..d18231e27 100644
--- a/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java
+++ b/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java
@@ -139,7 +139,7 @@ public class LiteflowConfig {
public Integer getWhenQueueLimit() {
if (ObjectUtil.isNull(whenQueueLimit)){
- return 512;
+ return 100;
}else{
return whenQueueLimit;
}
diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/config/LiteflowConfigNoSpringTest.java b/liteflow-core/src/test/java/com/yomahub/liteflow/test/config/LiteflowConfigNoSpringTest.java
similarity index 96%
rename from liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/config/LiteflowConfigNoSpringTest.java
rename to liteflow-core/src/test/java/com/yomahub/liteflow/test/config/LiteflowConfigNoSpringTest.java
index d8a0eb830..8ed342422 100644
--- a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/config/LiteflowConfigNoSpringTest.java
+++ b/liteflow-core/src/test/java/com/yomahub/liteflow/test/config/LiteflowConfigNoSpringTest.java
@@ -37,7 +37,7 @@ public class LiteflowConfigNoSpringTest extends BaseTest {
Assert.assertEquals(300000L, config.getPeriod().longValue());
Assert.assertFalse(config.getEnableLog());
Assert.assertEquals(Runtime.getRuntime().availableProcessors() * 2, config.getWhenMaxWorkers().longValue());
- Assert.assertEquals(512, config.getWhenQueueLimit().longValue());
+ Assert.assertEquals(100, config.getWhenQueueLimit().longValue());
}
}
diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/config/LiteflowConfigSpringTest.java b/liteflow-core/src/test/java/com/yomahub/liteflow/test/config/LiteflowConfigSpringTest.java
similarity index 96%
rename from liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/config/LiteflowConfigSpringTest.java
rename to liteflow-core/src/test/java/com/yomahub/liteflow/test/config/LiteflowConfigSpringTest.java
index d9178341e..eb7704c45 100644
--- a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/config/LiteflowConfigSpringTest.java
+++ b/liteflow-core/src/test/java/com/yomahub/liteflow/test/config/LiteflowConfigSpringTest.java
@@ -41,6 +41,6 @@ public class LiteflowConfigSpringTest extends BaseTest {
Assert.assertEquals(300000L, config.getPeriod().longValue());
Assert.assertFalse(config.getEnableLog());
Assert.assertEquals(Runtime.getRuntime().availableProcessors() * 2, config.getWhenMaxWorkers().longValue());
- Assert.assertEquals(512, config.getWhenQueueLimit().longValue());
+ Assert.assertEquals(100, config.getWhenQueueLimit().longValue());
}
}
diff --git a/liteflow-core/src/test/java/com/yomahub/liteflow/test/config/cmp/ACmp.java b/liteflow-core/src/test/java/com/yomahub/liteflow/test/config/cmp/ACmp.java
new file mode 100644
index 000000000..89be97ac8
--- /dev/null
+++ b/liteflow-core/src/test/java/com/yomahub/liteflow/test/config/cmp/ACmp.java
@@ -0,0 +1,20 @@
+/**
+ * Title: liteflow
+ * Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang
+ * @email weenyc31@163.com
+ * @Date 2020/4/1
+ */
+package com.yomahub.liteflow.test.config.cmp;
+
+import com.yomahub.liteflow.core.NodeComponent;
+import org.springframework.stereotype.Component;
+
+@Component("a")
+public class ACmp extends NodeComponent {
+
+ @Override
+ public void process() {
+ System.out.println("ACmp executed!");
+ }
+}
diff --git a/liteflow-core/src/test/java/com/yomahub/liteflow/test/config/cmp/BCmp.java b/liteflow-core/src/test/java/com/yomahub/liteflow/test/config/cmp/BCmp.java
new file mode 100644
index 000000000..86bf75320
--- /dev/null
+++ b/liteflow-core/src/test/java/com/yomahub/liteflow/test/config/cmp/BCmp.java
@@ -0,0 +1,21 @@
+/**
+ * Title: liteflow
+ * Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang
+ * @email weenyc31@163.com
+ * @Date 2020/4/1
+ */
+package com.yomahub.liteflow.test.config.cmp;
+
+import com.yomahub.liteflow.core.NodeComponent;
+import org.springframework.stereotype.Component;
+
+@Component("b")
+public class BCmp extends NodeComponent {
+
+ @Override
+ public void process() {
+ System.out.println("BCmp executed!");
+ }
+
+}
diff --git a/liteflow-core/src/test/java/com/yomahub/liteflow/test/config/cmp/CCmp.java b/liteflow-core/src/test/java/com/yomahub/liteflow/test/config/cmp/CCmp.java
new file mode 100644
index 000000000..9867bac45
--- /dev/null
+++ b/liteflow-core/src/test/java/com/yomahub/liteflow/test/config/cmp/CCmp.java
@@ -0,0 +1,21 @@
+/**
+ * Title: liteflow
+ * Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang
+ * @email weenyc31@163.com
+ * @Date 2020/4/1
+ */
+package com.yomahub.liteflow.test.config.cmp;
+
+import com.yomahub.liteflow.core.NodeComponent;
+import org.springframework.stereotype.Component;
+
+@Component("c")
+public class CCmp extends NodeComponent {
+
+ @Override
+ public void process() {
+ System.out.println("CCmp executed!");
+ }
+
+}
diff --git a/liteflow-core/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithJsonSpringTest.java b/liteflow-core/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithJsonSpringTest.java
new file mode 100644
index 000000000..f890d0de1
--- /dev/null
+++ b/liteflow-core/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithJsonSpringTest.java
@@ -0,0 +1,77 @@
+package com.yomahub.liteflow.test.zookeeper;
+
+import com.yomahub.liteflow.core.FlowExecutor;
+import com.yomahub.liteflow.entity.data.LiteflowResponse;
+import com.yomahub.liteflow.entity.data.Slot;
+import com.yomahub.liteflow.test.BaseTest;
+import org.I0Itec.zkclient.ZkClient;
+import org.I0Itec.zkclient.exception.ZkMarshallingError;
+import org.I0Itec.zkclient.serialize.ZkSerializer;
+import org.apache.curator.test.TestingServer;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import javax.annotation.Resource;
+import java.nio.charset.Charset;
+import java.util.concurrent.CountDownLatch;
+
+/**
+ * spring环境下的zk配置源功能测试
+ * ZK节点存储数据的格式为json文件
+ * @author zendwang
+ * @since 2.5.0
+ */
+@RunWith(SpringRunner.class)
+@ContextConfiguration("classpath:/zookeeper/application-json.xml")
+public class ZkNodeWithJsonSpringTest extends BaseTest {
+
+ private static final String ZK_NODE_PATH = "/lite-flow/flow";
+
+ private static TestingServer zkServer;
+
+ @Resource
+ private FlowExecutor flowExecutor;
+
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ zkServer = new TestingServer(21810);
+ CountDownLatch latch = new CountDownLatch(1);
+ new Thread(() -> {
+ String data = "{\"flow\":{\"chain\":[{\"name\":\"chain1\",\"condition\":[{\"type\":\"then\",\"value\":\"a,b,c\"}]}]}}";
+ ZkClient zkClient = new ZkClient("127.0.0.1:21810");
+ zkClient.setZkSerializer(new ZkSerializer() {
+ @Override
+ public byte[] serialize(final Object o) throws ZkMarshallingError {
+ return o.toString().getBytes(Charset.forName("UTF-8"));
+ }
+
+ @Override
+ public Object deserialize(final byte[] bytes) throws ZkMarshallingError {
+ return new String(bytes, Charset.forName("UTF-8"));
+ }
+ });
+ zkClient.createPersistent(ZK_NODE_PATH, true);
+ zkClient.writeData(ZK_NODE_PATH, data);
+ zkClient.close();
+ latch.countDown();
+ }).start();
+ latch.await();
+ }
+
+ @Test
+ public void test() throws Exception{
+ LiteflowResponse response = flowExecutor.execute("chain1", "arg");
+ Assert.assertTrue(response.isSuccess());
+ Assert.assertEquals("a==>b==>c", response.getData().printStep());
+ }
+
+ @AfterClass
+ public static void tearDown() throws Exception {
+ zkServer.stop();
+ }
+}
diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/config/ZkConfigSourceSpringtTest.java b/liteflow-core/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithXmlSpringTest.java
similarity index 89%
rename from liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/config/ZkConfigSourceSpringtTest.java
rename to liteflow-core/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithXmlSpringTest.java
index db498217e..844e0cd87 100644
--- a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/config/ZkConfigSourceSpringtTest.java
+++ b/liteflow-core/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithXmlSpringTest.java
@@ -1,4 +1,4 @@
-package com.yomahub.liteflow.test.config;
+package com.yomahub.liteflow.test.zookeeper;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
@@ -22,12 +22,13 @@ import java.util.concurrent.CountDownLatch;
/**
* spring环境下的zk配置源功能测试
+ * ZK节点存储数据的格式为xml文件
* @author zendwang
* @since 2.5.0
*/
@RunWith(SpringRunner.class)
-@ContextConfiguration("classpath:/config/application-zk.xml")
-public class ZkConfigSourceSpringtTest extends BaseTest {
+@ContextConfiguration("classpath:/zookeeper/application-xml.xml")
+public class ZkNodeWithXmlSpringTest extends BaseTest {
private static final String ZK_NODE_PATH = "/lite-flow/flow";
@@ -66,6 +67,7 @@ public class ZkConfigSourceSpringtTest extends BaseTest {
public void test() throws Exception{
LiteflowResponse response = flowExecutor.execute("chain1", "arg");
Assert.assertTrue(response.isSuccess());
+ Assert.assertEquals("a==>b==>c", response.getData().printStep());
}
@AfterClass
diff --git a/liteflow-core/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithYmlSpringTest.java b/liteflow-core/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithYmlSpringTest.java
new file mode 100644
index 000000000..b12309b78
--- /dev/null
+++ b/liteflow-core/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithYmlSpringTest.java
@@ -0,0 +1,83 @@
+package com.yomahub.liteflow.test.zookeeper;
+
+import com.yomahub.liteflow.core.FlowExecutor;
+import com.yomahub.liteflow.entity.data.LiteflowResponse;
+import com.yomahub.liteflow.entity.data.Slot;
+import com.yomahub.liteflow.test.BaseTest;
+import org.I0Itec.zkclient.ZkClient;
+import org.I0Itec.zkclient.exception.ZkMarshallingError;
+import org.I0Itec.zkclient.serialize.ZkSerializer;
+import org.apache.curator.test.TestingServer;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import javax.annotation.Resource;
+import java.nio.charset.Charset;
+import java.util.concurrent.CountDownLatch;
+
+/**
+ * spring环境下的zk配置源功能测试
+ * ZK节点存储数据的格式为yml文件
+ * @author zendwang
+ * @since 2.5.0
+ */
+@RunWith(SpringRunner.class)
+@ContextConfiguration("classpath:/zookeeper/application-yml.xml")
+public class ZkNodeWithYmlSpringTest extends BaseTest {
+
+ private static final String ZK_NODE_PATH = "/lite-flow/flow";
+
+ private static TestingServer zkServer;
+
+ @Resource
+ private FlowExecutor flowExecutor;
+
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ zkServer = new TestingServer(21810);
+ CountDownLatch latch = new CountDownLatch(1);
+ new Thread(() -> {
+ StringBuilder data = new StringBuilder()
+ .append("flow:\n")
+ .append(" chain:\n")
+ .append(" - name: chain1\n")
+ .append(" condition:\n")
+ .append(" - type: then\n")
+ .append(" value: 'a,b,c'");
+ ZkClient zkClient = new ZkClient("127.0.0.1:21810");
+ zkClient.setZkSerializer(new ZkSerializer() {
+ @Override
+ public byte[] serialize(final Object o) throws ZkMarshallingError {
+ return o.toString().getBytes(Charset.forName("UTF-8"));
+ }
+
+ @Override
+ public Object deserialize(final byte[] bytes) throws ZkMarshallingError {
+ return new String(bytes, Charset.forName("UTF-8"));
+ }
+ });
+ zkClient.createPersistent(ZK_NODE_PATH, true);
+ zkClient.writeData(ZK_NODE_PATH, data);
+ zkClient.close();
+ latch.countDown();
+ }).start();
+ latch.await();
+ }
+
+ @Test
+ public void test() throws Exception{
+ LiteflowResponse response = flowExecutor.execute("chain1", "arg");
+ Assert.assertTrue(response.isSuccess());
+ Assert.assertEquals("a==>b==>c", response.getData().printStep());
+ }
+
+ @AfterClass
+ public static void tearDown() throws Exception {
+ zkServer.stop();
+ }
+}
diff --git a/liteflow-core/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/ACmp.java b/liteflow-core/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/ACmp.java
new file mode 100644
index 000000000..f4fcf186d
--- /dev/null
+++ b/liteflow-core/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/ACmp.java
@@ -0,0 +1,20 @@
+/**
+ * Title: liteflow
+ * Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang
+ * @email weenyc31@163.com
+ * @Date 2020/4/1
+ */
+package com.yomahub.liteflow.test.zookeeper.cmp;
+
+import com.yomahub.liteflow.core.NodeComponent;
+import org.springframework.stereotype.Component;
+
+@Component("a")
+public class ACmp extends NodeComponent {
+
+ @Override
+ public void process() {
+ System.out.println("ACmp executed!");
+ }
+}
diff --git a/liteflow-core/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/BCmp.java b/liteflow-core/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/BCmp.java
new file mode 100644
index 000000000..e621cd1a0
--- /dev/null
+++ b/liteflow-core/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/BCmp.java
@@ -0,0 +1,21 @@
+/**
+ * Title: liteflow
+ * Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang
+ * @email weenyc31@163.com
+ * @Date 2020/4/1
+ */
+package com.yomahub.liteflow.test.zookeeper.cmp;
+
+import com.yomahub.liteflow.core.NodeComponent;
+import org.springframework.stereotype.Component;
+
+@Component("b")
+public class BCmp extends NodeComponent {
+
+ @Override
+ public void process() {
+ System.out.println("BCmp executed!");
+ }
+
+}
diff --git a/liteflow-core/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/CCmp.java b/liteflow-core/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/CCmp.java
new file mode 100644
index 000000000..f428f348b
--- /dev/null
+++ b/liteflow-core/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/CCmp.java
@@ -0,0 +1,21 @@
+/**
+ * Title: liteflow
+ * Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang
+ * @email weenyc31@163.com
+ * @Date 2020/4/1
+ */
+package com.yomahub.liteflow.test.zookeeper.cmp;
+
+import com.yomahub.liteflow.core.NodeComponent;
+import org.springframework.stereotype.Component;
+
+@Component("c")
+public class CCmp extends NodeComponent {
+
+ @Override
+ public void process() {
+ System.out.println("CCmp executed!");
+ }
+
+}
diff --git a/liteflow-spring-boot-starter/src/test/resources/config/application-local.xml b/liteflow-core/src/test/resources/config/application-local.xml
similarity index 100%
rename from liteflow-spring-boot-starter/src/test/resources/config/application-local.xml
rename to liteflow-core/src/test/resources/config/application-local.xml
diff --git a/liteflow-spring-boot-starter/src/test/resources/config/flow.json b/liteflow-core/src/test/resources/config/flow.json
similarity index 100%
rename from liteflow-spring-boot-starter/src/test/resources/config/flow.json
rename to liteflow-core/src/test/resources/config/flow.json
diff --git a/liteflow-core/src/test/resources/zookeeper/application-json.xml b/liteflow-core/src/test/resources/zookeeper/application-json.xml
new file mode 100644
index 000000000..8ee24176c
--- /dev/null
+++ b/liteflow-core/src/test/resources/zookeeper/application-json.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/liteflow-spring-boot-starter/src/test/resources/config/application-zk.xml b/liteflow-core/src/test/resources/zookeeper/application-xml.xml
similarity index 97%
rename from liteflow-spring-boot-starter/src/test/resources/config/application-zk.xml
rename to liteflow-core/src/test/resources/zookeeper/application-xml.xml
index 65e656bd0..71b8230ee 100644
--- a/liteflow-spring-boot-starter/src/test/resources/config/application-zk.xml
+++ b/liteflow-core/src/test/resources/zookeeper/application-xml.xml
@@ -7,7 +7,7 @@
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd">
-
+
diff --git a/liteflow-core/src/test/resources/zookeeper/application-yml.xml b/liteflow-core/src/test/resources/zookeeper/application-yml.xml
new file mode 100644
index 000000000..a282d0023
--- /dev/null
+++ b/liteflow-core/src/test/resources/zookeeper/application-yml.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/liteflow-core/src/test/resources/zookeeper/flow.json b/liteflow-core/src/test/resources/zookeeper/flow.json
new file mode 100644
index 000000000..097d548c5
--- /dev/null
+++ b/liteflow-core/src/test/resources/zookeeper/flow.json
@@ -0,0 +1,28 @@
+{
+ "flow": {
+ "nodes": {
+ "node": [
+ {
+ "id": "a",
+ "class": "com.yomahub.liteflow.test.zookeeper.cmp.ACmp"
+ },
+ {
+ "id": "b",
+ "class": "com.yomahub.liteflow.test.zookeeper.cmp.BCmp"
+ },
+ {
+ "id": "c",
+ "class": "com.yomahub.liteflow.test.zookeeper.cmp.CCmp"
+ }
+ ]
+ },
+ "chain": [
+ {
+ "name": "chain1",
+ "condition": [
+ {"type": "then", "value": "a,b,c"}
+ ]
+ }
+ ]
+ }
+}
\ No newline at end of file
diff --git a/liteflow-spring-boot-starter/src/test/resources/config/flow.xml b/liteflow-core/src/test/resources/zookeeper/flow.xml
similarity index 100%
rename from liteflow-spring-boot-starter/src/test/resources/config/flow.xml
rename to liteflow-core/src/test/resources/zookeeper/flow.xml
diff --git a/liteflow-core/src/test/resources/zookeeper/flow.yml b/liteflow-core/src/test/resources/zookeeper/flow.yml
new file mode 100644
index 000000000..3cdaced3e
--- /dev/null
+++ b/liteflow-core/src/test/resources/zookeeper/flow.yml
@@ -0,0 +1,6 @@
+flow:
+ chain:
+ - name: chain1
+ condition:
+ - type: then
+ value: 'a,b,c'
diff --git a/liteflow-spring-boot-starter/pom.xml b/liteflow-spring-boot-starter/pom.xml
index 009c45778..d8823a211 100644
--- a/liteflow-spring-boot-starter/pom.xml
+++ b/liteflow-spring-boot-starter/pom.xml
@@ -29,8 +29,6 @@
spring-boot-configuration-processor
${springboot.version}
-
-
org.springframework.boot
spring-boot-starter-test
@@ -46,13 +44,11 @@
org.apache.curator
curator-test
- 5.1.0
test
com.101tec
zkclient
- 0.10
test
diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithJsonSpringbootTest.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithJsonSpringbootTest.java
new file mode 100644
index 000000000..f7ac182cc
--- /dev/null
+++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithJsonSpringbootTest.java
@@ -0,0 +1,82 @@
+package com.yomahub.liteflow.test.zookeeper;
+
+import com.yomahub.liteflow.core.FlowExecutor;
+import com.yomahub.liteflow.entity.data.LiteflowResponse;
+import com.yomahub.liteflow.entity.data.Slot;
+import com.yomahub.liteflow.test.BaseTest;
+import org.I0Itec.zkclient.ZkClient;
+import org.I0Itec.zkclient.exception.ZkMarshallingError;
+import org.I0Itec.zkclient.serialize.ZkSerializer;
+import org.apache.curator.test.TestingServer;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+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.junit4.SpringRunner;
+
+import javax.annotation.Resource;
+import java.nio.charset.Charset;
+import java.util.concurrent.CountDownLatch;
+
+/**
+ * springboot环境下的zk配置源功能测试
+ * ZK节点存储数据的格式为json文件
+ * @author zendwang
+ * @since 2.5.0
+ */
+@RunWith(SpringRunner.class)
+@TestPropertySource(value = "classpath:/zookeeper/application-json.properties")
+@SpringBootTest(classes = ZkNodeWithJsonSpringbootTest.class)
+@EnableAutoConfiguration
+@ComponentScan({"com.yomahub.liteflow.test.zookeeper.cmp"})
+public class ZkNodeWithJsonSpringbootTest extends BaseTest {
+
+ private static final String ZK_NODE_PATH = "/lite-flow/flow";
+
+ private static TestingServer zkServer;
+
+ @Resource
+ private FlowExecutor flowExecutor;
+
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ zkServer = new TestingServer(21810);
+ CountDownLatch latch = new CountDownLatch(1);
+ new Thread(() -> {
+ String data = "{\"flow\":{\"chain\":[{\"name\":\"chain1\",\"condition\":[{\"type\":\"then\",\"value\":\"a,b,c\"}]}]}}";
+ ZkClient zkClient = new ZkClient("127.0.0.1:21810");
+ zkClient.setZkSerializer(new ZkSerializer() {
+ @Override
+ public byte[] serialize(final Object o) throws ZkMarshallingError {
+ return o.toString().getBytes(Charset.forName("UTF-8"));
+ }
+
+ @Override
+ public Object deserialize(final byte[] bytes) throws ZkMarshallingError {
+ return new String(bytes, Charset.forName("UTF-8"));
+ }
+ });
+ zkClient.createPersistent(ZK_NODE_PATH, true);
+ zkClient.writeData(ZK_NODE_PATH, data);
+ zkClient.close();
+ latch.countDown();
+ }).start();
+ latch.await();
+ }
+
+ @Test
+ public void test() throws Exception {
+ LiteflowResponse response = flowExecutor.execute("chain1", "arg");
+ Assert.assertTrue(response.isSuccess());
+ }
+
+ @AfterClass
+ public static void tearDown() throws Exception {
+ zkServer.stop();
+ }
+}
diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/config/ZkConfigSourceSpringbootTest.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithXmlSpringbootTest.java
similarity index 88%
rename from liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/config/ZkConfigSourceSpringbootTest.java
rename to liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithXmlSpringbootTest.java
index 9e9e02a87..bc8120282 100644
--- a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/config/ZkConfigSourceSpringbootTest.java
+++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithXmlSpringbootTest.java
@@ -1,4 +1,4 @@
-package com.yomahub.liteflow.test.config;
+package com.yomahub.liteflow.test.zookeeper;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
@@ -25,15 +25,16 @@ import java.util.concurrent.CountDownLatch;
/**
* springboot环境下的zk配置源功能测试
+ * ZK节点存储数据的格式为xml文件
* @author zendwang
* @since 2.5.0
*/
@RunWith(SpringRunner.class)
-@TestPropertySource(value = "classpath:/config/application-zk.properties")
-@SpringBootTest(classes = ZkConfigSourceSpringbootTest.class)
+@TestPropertySource(value = "classpath:/zookeeper/application-xml.properties")
+@SpringBootTest(classes = ZkNodeWithXmlSpringbootTest.class)
@EnableAutoConfiguration
-@ComponentScan({"com.yomahub.liteflow.test.config.cmp"})
-public class ZkConfigSourceSpringbootTest extends BaseTest {
+@ComponentScan({"com.yomahub.liteflow.test.zookeeper.cmp"})
+public class ZkNodeWithXmlSpringbootTest extends BaseTest {
private static final String ZK_NODE_PATH = "/lite-flow/flow";
diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithYmlSpringbootTest.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithYmlSpringbootTest.java
new file mode 100644
index 000000000..ee9a8388d
--- /dev/null
+++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithYmlSpringbootTest.java
@@ -0,0 +1,88 @@
+package com.yomahub.liteflow.test.zookeeper;
+
+import com.yomahub.liteflow.core.FlowExecutor;
+import com.yomahub.liteflow.entity.data.LiteflowResponse;
+import com.yomahub.liteflow.entity.data.Slot;
+import com.yomahub.liteflow.test.BaseTest;
+import org.I0Itec.zkclient.ZkClient;
+import org.I0Itec.zkclient.exception.ZkMarshallingError;
+import org.I0Itec.zkclient.serialize.ZkSerializer;
+import org.apache.curator.test.TestingServer;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+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.junit4.SpringRunner;
+
+import javax.annotation.Resource;
+import java.nio.charset.Charset;
+import java.util.concurrent.CountDownLatch;
+
+/**
+ * springboot环境下的zk配置源功能测试
+ * ZK节点存储数据的格式为yml文件
+ * @author zendwang
+ * @since 2.5.0
+ */
+@RunWith(SpringRunner.class)
+@TestPropertySource(value = "classpath:/zookeeper/application-yml.properties")
+@SpringBootTest(classes = ZkNodeWithYmlSpringbootTest.class)
+@EnableAutoConfiguration
+@ComponentScan({"com.yomahub.liteflow.test.zookeeper.cmp"})
+public class ZkNodeWithYmlSpringbootTest extends BaseTest {
+
+ private static final String ZK_NODE_PATH = "/lite-flow/flow";
+
+ private static TestingServer zkServer;
+
+ @Resource
+ private FlowExecutor flowExecutor;
+
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ zkServer = new TestingServer(21810);
+ CountDownLatch latch = new CountDownLatch(1);
+ new Thread(() -> {
+ StringBuilder data = new StringBuilder()
+ .append("flow:\n")
+ .append(" chain:\n")
+ .append(" - name: chain1\n")
+ .append(" condition:\n")
+ .append(" - type: then\n")
+ .append(" value: 'a,b,c'");
+ ZkClient zkClient = new ZkClient("127.0.0.1:21810");
+ zkClient.setZkSerializer(new ZkSerializer() {
+ @Override
+ public byte[] serialize(final Object o) throws ZkMarshallingError {
+ return o.toString().getBytes(Charset.forName("UTF-8"));
+ }
+
+ @Override
+ public Object deserialize(final byte[] bytes) throws ZkMarshallingError {
+ return new String(bytes, Charset.forName("UTF-8"));
+ }
+ });
+ zkClient.createPersistent(ZK_NODE_PATH, true);
+ zkClient.writeData(ZK_NODE_PATH, data);
+ zkClient.close();
+ latch.countDown();
+ }).start();
+ latch.await();
+ }
+
+ @Test
+ public void test() throws Exception {
+ LiteflowResponse response = flowExecutor.execute("chain1", "arg");
+ Assert.assertTrue(response.isSuccess());
+ }
+
+ @AfterClass
+ public static void tearDown() throws Exception {
+ zkServer.stop();
+ }
+}
diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/ACmp.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/ACmp.java
new file mode 100644
index 000000000..f4fcf186d
--- /dev/null
+++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/ACmp.java
@@ -0,0 +1,20 @@
+/**
+ * Title: liteflow
+ * Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang
+ * @email weenyc31@163.com
+ * @Date 2020/4/1
+ */
+package com.yomahub.liteflow.test.zookeeper.cmp;
+
+import com.yomahub.liteflow.core.NodeComponent;
+import org.springframework.stereotype.Component;
+
+@Component("a")
+public class ACmp extends NodeComponent {
+
+ @Override
+ public void process() {
+ System.out.println("ACmp executed!");
+ }
+}
diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/BCmp.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/BCmp.java
new file mode 100644
index 000000000..e621cd1a0
--- /dev/null
+++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/BCmp.java
@@ -0,0 +1,21 @@
+/**
+ * Title: liteflow
+ * Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang
+ * @email weenyc31@163.com
+ * @Date 2020/4/1
+ */
+package com.yomahub.liteflow.test.zookeeper.cmp;
+
+import com.yomahub.liteflow.core.NodeComponent;
+import org.springframework.stereotype.Component;
+
+@Component("b")
+public class BCmp extends NodeComponent {
+
+ @Override
+ public void process() {
+ System.out.println("BCmp executed!");
+ }
+
+}
diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/CCmp.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/CCmp.java
new file mode 100644
index 000000000..f428f348b
--- /dev/null
+++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/CCmp.java
@@ -0,0 +1,21 @@
+/**
+ * Title: liteflow
+ * Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang
+ * @email weenyc31@163.com
+ * @Date 2020/4/1
+ */
+package com.yomahub.liteflow.test.zookeeper.cmp;
+
+import com.yomahub.liteflow.core.NodeComponent;
+import org.springframework.stereotype.Component;
+
+@Component("c")
+public class CCmp extends NodeComponent {
+
+ @Override
+ public void process() {
+ System.out.println("CCmp executed!");
+ }
+
+}
diff --git a/liteflow-spring-boot-starter/src/test/resources/liteflow单测.md b/liteflow-spring-boot-starter/src/test/resources/liteflow单测.md
index f250dc397..bf959734e 100644
--- a/liteflow-spring-boot-starter/src/test/resources/liteflow单测.md
+++ b/liteflow-spring-boot-starter/src/test/resources/liteflow单测.md
@@ -37,23 +37,23 @@
- [x] Yml方式在spring环境下测试
- [] Yml方式在springboot环境下测试
-- [ ] 参数测试(只测到参数是不是被总的LiteFlowConfig加载到即可)
- - [ ] 非spring环境下的参数测试,必要参数测试,非必须参数的默认值测试。
- - [ ] spring环境下的参数测试,必要参数测试,非必须参数的默认值测试。
- - [ ] springboot环境下的参数测试,必要参数测试,非必须参数的默认值测试。
-- [ ] zk配置源的功能测试(zk请自己本地安装提供)
- - [ ] spring环境下的zk配置源功能测试
- - [ ] springboot环境下的zk配置源功能测试
-- [ ] 自定义源的功能测试
- - [ ] spring环境下的自定义配置源功能测试
- - [ ] springboot环境下的自定义配置源功能测试
-- [ ] 组件功能点测试(基于springboot环境即可)
- - [ ] isAccess方法的功能测试
- - [ ] 组件抛错的功能点测试
- - [ ] isContinueOnError方法的功能点测试
- - [ ] isEnd方法和this.setIsEnd(true)的功能点测试
-- [ ] 条件组件功能点测试(基于springboot环境)
- - [ ] 条件组件的功能点测试
+- [x] 参数测试(只测到参数是不是被总的LiteFlowConfig加载到即可)
+ - [x] 非spring环境下的参数测试,必要参数测试,非必须参数的默认值测试。
+ - [x] spring环境下的参数测试,必要参数测试,非必须参数的默认值测试。
+ - [x] springboot环境下的参数测试,必要参数测试,非必须参数的默认值测试。
+- [x] zk配置源的功能测试(zk请自己本地安装提供)
+ - [x] spring环境下的zk配置源功能测试
+ - [x] springboot环境下的zk配置源功能测试
+- [x] 自定义源的功能测试
+ - [x] spring环境下的自定义配置源功能测试
+ - [x] springboot环境下的自定义配置源功能测试
+- [x] 组件功能点测试(基于springboot环境即可)
+ - [x] isAccess方法的功能测试
+ - [x] 组件抛错的功能点测试
+ - [x] isContinueOnError方法的功能点测试
+ - [x] isEnd方法和this.setIsEnd(true)的功能点测试
+- [x] 条件组件功能点测试(基于springboot环境)
+ - [x] 条件组件的功能点测试
- [x] 显式子流程测试(基于springboot环境)
- [x] 子流程功能点测试,是否能进入子流程
- [x] 多个子流程是否能串联衔接
diff --git a/liteflow-spring-boot-starter/src/test/resources/zookeeper/application-json.properties b/liteflow-spring-boot-starter/src/test/resources/zookeeper/application-json.properties
new file mode 100644
index 000000000..50d6ddca7
--- /dev/null
+++ b/liteflow-spring-boot-starter/src/test/resources/zookeeper/application-json.properties
@@ -0,0 +1 @@
+liteflow.rule-source=json:127.0.0.1:21810
\ No newline at end of file
diff --git a/liteflow-spring-boot-starter/src/test/resources/config/application-zk.properties b/liteflow-spring-boot-starter/src/test/resources/zookeeper/application-xml.properties
similarity index 100%
rename from liteflow-spring-boot-starter/src/test/resources/config/application-zk.properties
rename to liteflow-spring-boot-starter/src/test/resources/zookeeper/application-xml.properties
diff --git a/liteflow-spring-boot-starter/src/test/resources/zookeeper/application-yml.properties b/liteflow-spring-boot-starter/src/test/resources/zookeeper/application-yml.properties
new file mode 100644
index 000000000..9c88b3fd3
--- /dev/null
+++ b/liteflow-spring-boot-starter/src/test/resources/zookeeper/application-yml.properties
@@ -0,0 +1 @@
+liteflow.rule-source=yml:127.0.0.1:21810
\ No newline at end of file
diff --git a/liteflow-spring-boot-starter/src/test/resources/zookeeper/flow.json b/liteflow-spring-boot-starter/src/test/resources/zookeeper/flow.json
new file mode 100644
index 000000000..c3a7a8763
--- /dev/null
+++ b/liteflow-spring-boot-starter/src/test/resources/zookeeper/flow.json
@@ -0,0 +1,28 @@
+{
+ "flow": {
+ "nodes": {
+ "node": [
+ {
+ "id": "a",
+ "class": "com.yomahub.liteflow.test.config.cmp.ACmp"
+ },
+ {
+ "id": "b",
+ "class": "com.yomahub.liteflow.test.config.cmp.BCmp"
+ },
+ {
+ "id": "c",
+ "class": "com.yomahub.liteflow.test.config.cmp.CCmp"
+ }
+ ]
+ },
+ "chain": [
+ {
+ "name": "chain1",
+ "condition": [
+ {"type": "then", "value": "a,b,c"}
+ ]
+ }
+ ]
+ }
+}
\ No newline at end of file
diff --git a/liteflow-spring-boot-starter/src/test/resources/zookeeper/flow.xml b/liteflow-spring-boot-starter/src/test/resources/zookeeper/flow.xml
new file mode 100644
index 000000000..22870d94f
--- /dev/null
+++ b/liteflow-spring-boot-starter/src/test/resources/zookeeper/flow.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/liteflow-spring-boot-starter/src/test/resources/zookeeper/flow.yml b/liteflow-spring-boot-starter/src/test/resources/zookeeper/flow.yml
new file mode 100644
index 000000000..3cdaced3e
--- /dev/null
+++ b/liteflow-spring-boot-starter/src/test/resources/zookeeper/flow.yml
@@ -0,0 +1,6 @@
+flow:
+ chain:
+ - name: chain1
+ condition:
+ - type: then
+ value: 'a,b,c'
diff --git a/pom.xml b/pom.xml
index 967e4453c..d67f7eb01 100644
--- a/pom.xml
+++ b/pom.xml
@@ -54,6 +54,8 @@
4.12
5.3.10
2.12.1
+ 5.1.0
+ 0.10
@@ -138,6 +140,16 @@
transmittable-thread-local
${transmittable-thread-local.version}
+
+ org.apache.curator
+ curator-test
+ ${curator-test.version}
+
+
+ com.101tec
+ zkclient
+ ${zkclient.version}
+