From 6df9e9bc027afd58d2fff3564a2389ec60be4dd6 Mon Sep 17 00:00:00 2001 From: "dongguo.tao" Date: Wed, 7 Apr 2021 19:21:20 +0800 Subject: [PATCH 1/7] =?UTF-8?q?update=20liteflow=E5=8D=95=E6=B5=8B.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/test/resources/liteflow单测.md | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/liteflow-spring-boot-starter/src/test/resources/liteflow单测.md b/liteflow-spring-boot-starter/src/test/resources/liteflow单测.md index f250dc397..72c536c9a 100644 --- a/liteflow-spring-boot-starter/src/test/resources/liteflow单测.md +++ b/liteflow-spring-boot-starter/src/test/resources/liteflow单测.md @@ -44,16 +44,16 @@ - [ ] zk配置源的功能测试(zk请自己本地安装提供) - [ ] spring环境下的zk配置源功能测试 - [ ] springboot环境下的zk配置源功能测试 -- [ ] 自定义源的功能测试 - - [ ] spring环境下的自定义配置源功能测试 - - [ ] springboot环境下的自定义配置源功能测试 -- [ ] 组件功能点测试(基于springboot环境即可) - - [ ] isAccess方法的功能测试 - - [ ] 组件抛错的功能点测试 - - [ ] isContinueOnError方法的功能点测试 - - [ ] isEnd方法和this.setIsEnd(true)的功能点测试 -- [ ] 条件组件功能点测试(基于springboot环境) - - [ ] 条件组件的功能点测试 +- [x] 自定义源的功能测试 + - [x] spring环境下的自定义配置源功能测试 + - [x] springboot环境下的自定义配置源功能测试 +- [x] 组件功能点测试(基于springboot环境即可) + - [x] isAccess方法的功能测试 + - [x] 组件抛错的功能点测试 + - [x] isContinueOnError方法的功能点测试 + - [x] isEnd方法和this.setIsEnd(true)的功能点测试 +- [x] 条件组件功能点测试(基于springboot环境) + - [x] 条件组件的功能点测试 - [x] 显式子流程测试(基于springboot环境) - [x] 子流程功能点测试,是否能进入子流程 - [x] 多个子流程是否能串联衔接 From 9809a6ae98eac47f8ee4054e5e34d713bb27f424 Mon Sep 17 00:00:00 2001 From: bryan31 Date: Thu, 8 Apr 2021 10:46:57 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E5=BC=82=E6=AD=A5=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?=E7=AD=89=E5=BE=85=E9=98=9F=E5=88=97=E9=BB=98=E8=AE=A4=E5=A4=A7?= =?UTF-8?q?=E5=B0=8F=E6=94=B9=E4=B8=BA100?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/yomahub/liteflow/property/LiteflowConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; } From e1e50c526f45840c32609c7a59b5b273156647f6 Mon Sep 17 00:00:00 2001 From: bryan31 Date: Thu, 8 Apr 2021 10:57:31 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../liteflow/test/config/LiteflowConfigNoSpringTest.java | 2 +- .../yomahub/liteflow/test/config/LiteflowConfigSpringTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/config/LiteflowConfigNoSpringTest.java b/liteflow-spring-boot-starter/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-spring-boot-starter/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-spring-boot-starter/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-spring-boot-starter/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()); } } From 28afb47497a87b5dcfa1a3e73e2380160e425d36 Mon Sep 17 00:00:00 2001 From: zendwang Date: Thu, 8 Apr 2021 11:11:23 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E8=B0=83=E6=95=B4zk=E3=80=81config?= =?UTF-8?q?=E9=83=A8=E5=88=86=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- liteflow-core/pom.xml | 11 +++ .../config/LiteflowConfigNoSpringTest.java | 0 .../test/config/LiteflowConfigSpringTest.java | 0 .../liteflow/test/config/cmp/ACmp.java | 20 +++++ .../liteflow/test/config/cmp/BCmp.java | 21 +++++ .../liteflow/test/config/cmp/CCmp.java | 21 +++++ .../zookeeper/ZkNodeWithJsonSpringTest.java | 77 ++++++++++++++++ .../zookeeper/ZkNodeWithXmlSpringTest.java | 8 +- .../zookeeper/ZkNodeWithYmlSpringTest.java | 83 +++++++++++++++++ .../liteflow/test/zookeeper/cmp/ACmp.java | 20 +++++ .../liteflow/test/zookeeper/cmp/BCmp.java | 21 +++++ .../liteflow/test/zookeeper/cmp/CCmp.java | 21 +++++ .../resources/config/application-local.xml | 0 .../src/test/resources/config/flow.json | 0 .../resources/zookeeper/application-json.xml | 23 +++++ .../resources/zookeeper/application-xml.xml | 2 +- .../resources/zookeeper/application-yml.xml | 23 +++++ .../src/test/resources/zookeeper/flow.json | 28 ++++++ .../src/test/resources/zookeeper}/flow.xml | 0 .../src/test/resources/zookeeper/flow.yml | 6 ++ liteflow-spring-boot-starter/pom.xml | 4 - .../ZkNodeWithJsonSpringbootTest.java | 82 +++++++++++++++++ .../ZkNodeWithXmlSpringbootTest.java} | 11 +-- .../ZkNodeWithYmlSpringbootTest.java | 88 +++++++++++++++++++ .../liteflow/test/zookeeper/cmp/ACmp.java | 20 +++++ .../liteflow/test/zookeeper/cmp/BCmp.java | 21 +++++ .../liteflow/test/zookeeper/cmp/CCmp.java | 21 +++++ .../src/test/resources/liteflow单测.md | 14 +-- .../zookeeper/application-json.properties | 1 + .../application-xml.properties} | 0 .../zookeeper/application-yml.properties | 1 + .../src/test/resources/zookeeper/flow.json | 28 ++++++ .../src/test/resources/zookeeper/flow.xml | 6 ++ .../src/test/resources/zookeeper/flow.yml | 6 ++ pom.xml | 12 +++ 35 files changed, 680 insertions(+), 20 deletions(-) rename {liteflow-spring-boot-starter => liteflow-core}/src/test/java/com/yomahub/liteflow/test/config/LiteflowConfigNoSpringTest.java (100%) rename {liteflow-spring-boot-starter => liteflow-core}/src/test/java/com/yomahub/liteflow/test/config/LiteflowConfigSpringTest.java (100%) create mode 100644 liteflow-core/src/test/java/com/yomahub/liteflow/test/config/cmp/ACmp.java create mode 100644 liteflow-core/src/test/java/com/yomahub/liteflow/test/config/cmp/BCmp.java create mode 100644 liteflow-core/src/test/java/com/yomahub/liteflow/test/config/cmp/CCmp.java create mode 100644 liteflow-core/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithJsonSpringTest.java rename liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/config/ZkConfigSourceSpringtTest.java => liteflow-core/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithXmlSpringTest.java (89%) create mode 100644 liteflow-core/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithYmlSpringTest.java create mode 100644 liteflow-core/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/ACmp.java create mode 100644 liteflow-core/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/BCmp.java create mode 100644 liteflow-core/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/CCmp.java rename {liteflow-spring-boot-starter => liteflow-core}/src/test/resources/config/application-local.xml (100%) rename {liteflow-spring-boot-starter => liteflow-core}/src/test/resources/config/flow.json (100%) create mode 100644 liteflow-core/src/test/resources/zookeeper/application-json.xml rename liteflow-spring-boot-starter/src/test/resources/config/application-zk.xml => liteflow-core/src/test/resources/zookeeper/application-xml.xml (97%) create mode 100644 liteflow-core/src/test/resources/zookeeper/application-yml.xml create mode 100644 liteflow-core/src/test/resources/zookeeper/flow.json rename {liteflow-spring-boot-starter/src/test/resources/config => liteflow-core/src/test/resources/zookeeper}/flow.xml (100%) create mode 100644 liteflow-core/src/test/resources/zookeeper/flow.yml create mode 100644 liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithJsonSpringbootTest.java rename liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/{config/ZkConfigSourceSpringbootTest.java => zookeeper/ZkNodeWithXmlSpringbootTest.java} (88%) create mode 100644 liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithYmlSpringbootTest.java create mode 100644 liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/ACmp.java create mode 100644 liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/BCmp.java create mode 100644 liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/CCmp.java create mode 100644 liteflow-spring-boot-starter/src/test/resources/zookeeper/application-json.properties rename liteflow-spring-boot-starter/src/test/resources/{config/application-zk.properties => zookeeper/application-xml.properties} (100%) create mode 100644 liteflow-spring-boot-starter/src/test/resources/zookeeper/application-yml.properties create mode 100644 liteflow-spring-boot-starter/src/test/resources/zookeeper/flow.json create mode 100644 liteflow-spring-boot-starter/src/test/resources/zookeeper/flow.xml create mode 100644 liteflow-spring-boot-starter/src/test/resources/zookeeper/flow.yml 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-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 100% 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 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 100% 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 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 72c536c9a..bf959734e 100644 --- a/liteflow-spring-boot-starter/src/test/resources/liteflow单测.md +++ b/liteflow-spring-boot-starter/src/test/resources/liteflow单测.md @@ -37,13 +37,13 @@ - [x] Yml方式在spring环境下测试 - [] Yml方式在springboot环境下测试 -- [ ] 参数测试(只测到参数是不是被总的LiteFlowConfig加载到即可) - - [ ] 非spring环境下的参数测试,必要参数测试,非必须参数的默认值测试。 - - [ ] spring环境下的参数测试,必要参数测试,非必须参数的默认值测试。 - - [ ] springboot环境下的参数测试,必要参数测试,非必须参数的默认值测试。 -- [ ] zk配置源的功能测试(zk请自己本地安装提供) - - [ ] spring环境下的zk配置源功能测试 - - [ ] springboot环境下的zk配置源功能测试 +- [x] 参数测试(只测到参数是不是被总的LiteFlowConfig加载到即可) + - [x] 非spring环境下的参数测试,必要参数测试,非必须参数的默认值测试。 + - [x] spring环境下的参数测试,必要参数测试,非必须参数的默认值测试。 + - [x] springboot环境下的参数测试,必要参数测试,非必须参数的默认值测试。 +- [x] zk配置源的功能测试(zk请自己本地安装提供) + - [x] spring环境下的zk配置源功能测试 + - [x] springboot环境下的zk配置源功能测试 - [x] 自定义源的功能测试 - [x] spring环境下的自定义配置源功能测试 - [x] springboot环境下的自定义配置源功能测试 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} + From 7bc9c7d1bbcad021db449dbedae32319d496c5bf Mon Sep 17 00:00:00 2001 From: bryan31 Date: Thu, 8 Apr 2021 11:37:32 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E8=A7=A3=E5=86=B3zkYml=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/yomahub/liteflow/parser/YmlFlowParser.java | 2 +- .../yomahub/liteflow/parser/ZookeeperYmlFlowParser.java | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) 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..9295c4474 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); From 469ff01ace546ce6e6f25696ba6458406e7c4fa2 Mon Sep 17 00:00:00 2001 From: bryan31 Date: Thu, 8 Apr 2021 11:44:33 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E8=A7=A3=E5=86=B3zkYml=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yomahub/liteflow/parser/ZookeeperYmlFlowParser.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 9295c4474..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 @@ -64,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()); } }); } From 62ecb922c668b407f0539b1cf7c52c2361ee0157 Mon Sep 17 00:00:00 2001 From: bryan31 Date: Thu, 8 Apr 2021 11:56:47 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/yomahub/liteflow/entity/flow/Chain.java | 1 - 1 file changed, 1 deletion(-) 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()); } }