From 775f5ec791eef00cab8ef4f4a5f8d3d3d2f9cd77 Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Mon, 20 Mar 2023 22:18:21 +0800 Subject: [PATCH] =?UTF-8?q?feat=20#I6O2YE=20zk=20=E5=A4=96=E7=BD=AE?= =?UTF-8?q?=E5=AD=98=E5=82=A8=E6=94=AF=E6=8C=81=E5=A4=9A=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E6=B7=B7=E5=90=88=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../parser/zk/util/ZkParserHelper.java | 19 ++++++++++++++++-- .../pom.xml | 7 +++++++ .../ZkClusterWithXmlELSpringbootTest.java | 14 ++++++------- .../ZkNodeWithXmlELSpringbootTest.java | 20 ++++++++++++------- 4 files changed, 44 insertions(+), 16 deletions(-) diff --git a/liteflow-rule-plugin/liteflow-rule-zk/src/main/java/com/yomahub/liteflow/parser/zk/util/ZkParserHelper.java b/liteflow-rule-plugin/liteflow-rule-zk/src/main/java/com/yomahub/liteflow/parser/zk/util/ZkParserHelper.java index 00874a018..3620c1c08 100644 --- a/liteflow-rule-plugin/liteflow-rule-zk/src/main/java/com/yomahub/liteflow/parser/zk/util/ZkParserHelper.java +++ b/liteflow-rule-plugin/liteflow-rule-zk/src/main/java/com/yomahub/liteflow/parser/zk/util/ZkParserHelper.java @@ -19,6 +19,7 @@ import org.apache.curator.framework.recipes.cache.CuratorCacheListener; import org.apache.curator.retry.RetryNTimes; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -35,7 +36,7 @@ public class ZkParserHelper { private final String NODE_XML_PATTERN = "{}"; - private final String NODE_ITEM_XML_PATTERN = ""; + private final String NODE_ITEM_XML_PATTERN = ""; private final String XML_PATTERN = "{}{}"; @@ -92,7 +93,7 @@ public class ZkParserHelper { .forPath(StrUtil.format("{}/{}", zkParserVO.getScriptPath(), scriptNodeValue))); scriptItemContentList.add(StrUtil.format(NODE_ITEM_XML_PATTERN, nodeSimpleVO.getNodeId(), - nodeSimpleVO.getName(), nodeSimpleVO.getType(), scriptData)); + nodeSimpleVO.getName(), nodeSimpleVO.getType(), nodeSimpleVO.getLanguage(), scriptData)); } scriptAllContent = StrUtil.format(NODE_XML_PATTERN, @@ -203,6 +204,10 @@ public class ZkParserHelper { nodeSimpleVO.setName(matchItemList.get(2)); } + if (matchItemList.size() > 3) { + nodeSimpleVO.setLanguage(matchItemList.get(3)); + } + return nodeSimpleVO; } @@ -214,6 +219,8 @@ public class ZkParserHelper { private String name = ""; + private String language; + public String getNodeId() { return nodeId; } @@ -238,6 +245,14 @@ public class ZkParserHelper { this.name = name; } + public String getLanguage() { + return language; + } + + public void setLanguage(String language) { + this.language = language; + } + } } 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 18261781f..65228a046 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/pom.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/pom.xml @@ -32,6 +32,13 @@ ${revision} + + com.yomahub + liteflow-script-javascript + ${revision} + test + + 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 1944ec534..ebcfd24c2 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 @@ -1,7 +1,5 @@ package com.yomahub.liteflow.test.zookeeper; -import cn.hutool.core.io.FileUtil; -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; @@ -11,7 +9,6 @@ import org.I0Itec.zkclient.exception.ZkMarshallingError; import org.I0Itec.zkclient.serialize.ZkSerializer; import org.apache.curator.test.InstanceSpec; import org.apache.curator.test.TestingCluster; -import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; @@ -23,8 +20,6 @@ import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; -import java.io.File; -import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; /** @@ -71,12 +66,16 @@ public class ZkClusterWithXmlELSpringbootTest extends BaseTest { String chain1Path = ZK_CHAIN_PATH + "/chain1"; zkClient.createPersistent(chain1Path, true); - zkClient.writeData(chain1Path, "THEN(a, b, c, s1);"); + zkClient.writeData(chain1Path, "THEN(a, b, c, s1, s2);"); - String script1Path = ZK_SCRIPT_PATH + "/s1:script:脚本s1"; + String script1Path = ZK_SCRIPT_PATH + "/s1:script:脚本s1:groovy"; zkClient.createPersistent(script1Path, true); zkClient.writeData(script1Path, "defaultContext.setData(\"test\",\"hello\");"); + String script2Path = ZK_SCRIPT_PATH + "/s2:script:脚本s2:js"; + zkClient.createPersistent(script2Path, true); + zkClient.writeData(script2Path, "defaultContext.setData(\"test1\",\"hello\");"); + Thread.sleep(2000L); } @@ -86,6 +85,7 @@ public class ZkClusterWithXmlELSpringbootTest extends BaseTest { DefaultContext context = response.getFirstContextBean(); Assert.assertTrue(response.isSuccess()); Assert.assertEquals("hello", context.getData("test")); + Assert.assertEquals("hello", context.getData("test1")); } } 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 da0bccd8f..8cf6f71b0 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 @@ -1,8 +1,8 @@ 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; @@ -20,8 +20,7 @@ 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; +import java.nio.charset.StandardCharsets; /** * springboot环境下的zk配置源功能测试 ZK节点存储数据的格式为xml文件 @@ -52,27 +51,34 @@ public class ZkNodeWithXmlELSpringbootTest extends BaseTest { zkClient.setZkSerializer(new ZkSerializer() { @Override public byte[] serialize(final Object o) throws ZkMarshallingError { - return o.toString().getBytes(Charset.forName("UTF-8")); + return o.toString().getBytes(StandardCharsets.UTF_8); } @Override public Object deserialize(final byte[] bytes) throws ZkMarshallingError { - return new String(bytes, Charset.forName("UTF-8")); + return new String(bytes, StandardCharsets.UTF_8); } }); String chain1Path = ZK_CHAIN_PATH + "/chain1"; zkClient.createPersistent(chain1Path, true); - zkClient.writeData(chain1Path, "THEN(a, b, c, s1);"); + zkClient.writeData(chain1Path, "THEN(a, b, c, s1, s2);"); - String script1Path = ZK_SCRIPT_PATH + "/s1:script:脚本s1"; + String script1Path = ZK_SCRIPT_PATH + "/s1:script:脚本s1:groovy"; zkClient.createPersistent(script1Path, true); zkClient.writeData(script1Path, "defaultContext.setData(\"test\",\"hello\");"); + + String script2Path = ZK_SCRIPT_PATH + "/s2:script:脚本s2:js"; + zkClient.createPersistent(script2Path, true); + zkClient.writeData(script2Path, "defaultContext.setData(\"test1\",\"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")); + Assert.assertEquals("hello", context.getData("test1")); } @AfterClass