From 741f18dca0e1deb9de9fca4d9adad2c9006033fb Mon Sep 17 00:00:00 2001 From: "everywhere.z" Date: Sat, 5 Nov 2022 12:01:28 +0800 Subject: [PATCH] =?UTF-8?q?enhancement=20#I5ZLH6=20=E6=94=AF=E6=8C=81zk?= =?UTF-8?q?=E5=88=86=E7=A6=BBchain=E4=BB=A5=E5=8F=8A=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E7=9A=84=E5=AD=98=E5=82=A8=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pom.xml | 6 +++ .../ZkClusterWithXmlELSpringbootTest.java | 18 ++++++-- .../ZkNodeWithXmlELSpringbootTest.java | 44 +++++++++---------- .../application-xml-cluster.properties | 6 ++- .../zookeeper/application-xml.properties | 6 ++- 5 files changed, 52 insertions(+), 28 deletions(-) diff --git a/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/pom.xml b/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/pom.xml index 979f105ff..18261781f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/pom.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/pom.xml @@ -26,6 +26,12 @@ test + + com.yomahub + liteflow-script-groovy + ${revision} + + org.springframework.boot spring-boot-starter-test diff --git a/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkClusterWithXmlELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkClusterWithXmlELSpringbootTest.java index d1ff5c361..ad00fedb2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkClusterWithXmlELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkClusterWithXmlELSpringbootTest.java @@ -3,6 +3,7 @@ package com.yomahub.liteflow.test.zookeeper; import cn.hutool.core.io.resource.ResourceUtil; import com.yomahub.liteflow.core.FlowExecutor; import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.slot.DefaultContext; import com.yomahub.liteflow.test.BaseTest; import org.I0Itec.zkclient.ZkClient; import org.I0Itec.zkclient.exception.ZkMarshallingError; @@ -34,7 +35,9 @@ import java.nio.charset.StandardCharsets; @ComponentScan({"com.yomahub.liteflow.test.zookeeper.cmp"}) public class ZkClusterWithXmlELSpringbootTest extends BaseTest { - private static final String ZK_NODE_PATH = "/lite-flow/flow"; + private static final String ZK_CHAIN_PATH = "/liteflow/chain"; + + private static final String ZK_SCRIPT_PATH = "/liteflow/script"; private static TestingCluster zkCluster; @@ -50,7 +53,6 @@ public class ZkClusterWithXmlELSpringbootTest extends BaseTest { zkCluster.start(); String connectStr = zkCluster.getConnectString(); - String data = ResourceUtil.readUtf8Str("zookeeper/flow.xml"); ZkClient zkClient = new ZkClient(connectStr); zkClient.setZkSerializer(new ZkSerializer() { @Override @@ -63,14 +65,22 @@ public class ZkClusterWithXmlELSpringbootTest extends BaseTest { return new String(bytes, StandardCharsets.UTF_8); } }); - zkClient.createPersistent(ZK_NODE_PATH, true); - zkClient.writeData(ZK_NODE_PATH, data); + + String chain1Path = ZK_CHAIN_PATH+"/chain1"; + zkClient.createPersistent(chain1Path, true); + zkClient.writeData(chain1Path, "THEN(a, b, c, s1);"); + + String script1Path = ZK_SCRIPT_PATH+"/s1:script:脚本s1"; + zkClient.createPersistent(script1Path, true); + zkClient.writeData(script1Path, "defaultContext.setData(\"test\",\"hello\");"); } @Test public void testZkNodeWithXml() { LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("hello", context.getData("test")); } @AfterClass diff --git a/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithXmlELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithXmlELSpringbootTest.java index 58c477223..9dc234fd2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithXmlELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithXmlELSpringbootTest.java @@ -35,8 +35,10 @@ import java.util.concurrent.CountDownLatch; @EnableAutoConfiguration @ComponentScan({"com.yomahub.liteflow.test.zookeeper.cmp"}) public class ZkNodeWithXmlELSpringbootTest extends BaseTest { - - private static final String ZK_NODE_PATH = "/lite-flow/flow"; + + private static final String ZK_CHAIN_PATH = "/liteflow/chain"; + + private static final String ZK_SCRIPT_PATH = "/liteflow/script"; private static TestingServer zkServer; @@ -46,27 +48,25 @@ public class ZkNodeWithXmlELSpringbootTest extends BaseTest { @BeforeClass public static void setUpBeforeClass() throws Exception { zkServer = new TestingServer(21810); - CountDownLatch latch = new CountDownLatch(1); - new Thread(() -> { - String data = ResourceUtil.readUtf8Str("zookeeper/flow.xml"); - 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")); - } + 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(); + @Override + public Object deserialize(final byte[] bytes) throws ZkMarshallingError { + return new String(bytes, Charset.forName("UTF-8")); + } + }); + String chain1Path = ZK_CHAIN_PATH+"/chain1"; + zkClient.createPersistent(chain1Path, true); + zkClient.writeData(chain1Path, "THEN(a, b, c, s1);"); + + String script1Path = ZK_SCRIPT_PATH+"/s1:script:脚本s1"; + zkClient.createPersistent(script1Path, true); + zkClient.writeData(script1Path, "defaultContext.setData(\"test\",\"hello\");"); } @Test diff --git a/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/src/test/resources/zookeeper/application-xml-cluster.properties b/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/src/test/resources/zookeeper/application-xml-cluster.properties index 377abc1ac..cd0267a3b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/src/test/resources/zookeeper/application-xml-cluster.properties +++ b/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/src/test/resources/zookeeper/application-xml-cluster.properties @@ -1 +1,5 @@ -liteflow.rule-source-ext-data={"connectStr":"127.0.0.1:21810,127.0.0.1:21811,127.0.0.1:21812"} \ No newline at end of file +liteflow.rule-source-ext-data={\ + "connectStr":"127.0.0.1:21810,127.0.0.1:21811,127.0.0.1:21812",\ + "chainPath": "/liteflow/chain",\ + "scriptPath": "/liteflow/script"\ + } \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/src/test/resources/zookeeper/application-xml.properties b/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/src/test/resources/zookeeper/application-xml.properties index a1ca68fd0..f57c8d76e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/src/test/resources/zookeeper/application-xml.properties +++ b/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/src/test/resources/zookeeper/application-xml.properties @@ -1 +1,5 @@ -liteflow.rule-source-ext-data={"connectStr":"127.0.0.1:21810"} \ No newline at end of file +liteflow.rule-source-ext-data={\ + "connectStr":"127.0.0.1:21810",\ + "chainPath": "/liteflow/chain",\ + "scriptPath": "/liteflow/script"\ + } \ No newline at end of file