Forráskód Böngészése

enhancement #I5ZLH6 支持zk分离chain以及脚本的存储结构

everywhere.z 2 éve
szülő
commit
741f18dca0

+ 6 - 0
liteflow-testcase-el/liteflow-testcase-el-zk-springboot/pom.xml

@@ -26,6 +26,12 @@
             <scope>test</scope>
         </dependency>
 
+        <dependency>
+            <groupId>com.yomahub</groupId>
+            <artifactId>liteflow-script-groovy</artifactId>
+            <version>${revision}</version>
+        </dependency>
+
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-test</artifactId>

+ 14 - 4
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

+ 22 - 22
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"));
+            }
+        });
+        String chain1Path = ZK_CHAIN_PATH+"/chain1";
+        zkClient.createPersistent(chain1Path, true);
+        zkClient.writeData(chain1Path, "THEN(a, b, c, s1);");
 
-                @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();
+        String script1Path = ZK_SCRIPT_PATH+"/s1:script:脚本s1";
+        zkClient.createPersistent(script1Path, true);
+        zkClient.writeData(script1Path, "defaultContext.setData(\"test\",\"hello\");");
     }
     
     @Test

+ 5 - 1
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"}
+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"\
+  }

+ 5 - 1
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"}
+liteflow.rule-source-ext-data={\
+  "connectStr":"127.0.0.1:21810",\
+  "chainPath": "/liteflow/chain",\
+  "scriptPath": "/liteflow/script"\
+  }