From b9dd5e7eafbdd1623a73d3d6685a9f38324bcdb4 Mon Sep 17 00:00:00 2001 From: "everywhere.z" Date: Tue, 23 Aug 2022 00:41:28 +0800 Subject: [PATCH] =?UTF-8?q?bug=20#I5NFV3=20=E5=9C=A8zk=E9=9B=86=E7=BE=A4?= =?UTF-8?q?=E4=B8=AD=E5=A4=9A=E4=B8=AAzk=E5=9C=B0=E5=9D=80=E4=B8=8D?= =?UTF-8?q?=E7=94=9F=E6=95=88=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yomahub/liteflow/core/FlowExecutor.java | 9 ++- .../ZkClusterWithXmlELSpringbootTest.java | 80 +++++++++++++++++++ .../application-xml-cluster.properties | 1 + 3 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkClusterWithXmlELSpringbootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/zookeeper/application-xml-cluster.properties diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java index 7d482cb2c..c126950b6 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java @@ -90,7 +90,14 @@ public class FlowExecutor { return; } - List sourceRulePathList = ListUtil.toList(liteflowConfig.getRuleSource().split(",|;")); + //如果有前缀的,则不需要再进行分割了,说明是一个整体 + //如果没有前缀,说明是本地文件,可能配置多个,所以需要分割 + List sourceRulePathList; + if (ReUtil.contains(PREFIX_FORMAT_CONFIG_REGEX, liteflowConfig.getRuleSource())){ + sourceRulePathList = ListUtil.toList(liteflowConfig.getRuleSource()); + }else{ + sourceRulePathList = ListUtil.toList(liteflowConfig.getRuleSource().split(",|;")); + } FlowParser parser = null; Set parserNameSet = new HashSet<>(); diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkClusterWithXmlELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkClusterWithXmlELSpringbootTest.java new file mode 100644 index 000000000..52f9e8ce3 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkClusterWithXmlELSpringbootTest.java @@ -0,0 +1,80 @@ +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.test.BaseTest; +import org.I0Itec.zkclient.ZkClient; +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.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 cluster的测试 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/zookeeper/application-xml-cluster.properties") +@SpringBootTest(classes = ZkClusterWithXmlELSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.zookeeper.cmp"}) +public class ZkClusterWithXmlELSpringbootTest extends BaseTest { + + private static final String ZK_NODE_PATH = "/lite-flow/flow"; + + private static TestingCluster zkCluster; + + @Resource + private FlowExecutor flowExecutor; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + zkCluster = new TestingCluster(new InstanceSpec(null, 21810, -1, -1, true, -1, -1, -1), + new InstanceSpec(null, 21811, -1, -1, true, -1, -1, -1), + new InstanceSpec(null, 21812, -1, -1, true, -1, -1, -1)); + zkCluster.start(); + String connectStr = zkCluster.getConnectString(); + + String data = ResourceUtil.readUtf8Str("zookeeper/flow.xml"); + ZkClient zkClient = new ZkClient(connectStr); + 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); + } + + @Test + public void testZkNodeWithXml() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } + +// @AfterClass + public static void tearDown() throws Exception { + zkCluster.stop(); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/zookeeper/application-xml-cluster.properties b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/zookeeper/application-xml-cluster.properties new file mode 100644 index 000000000..5a92f38d8 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/zookeeper/application-xml-cluster.properties @@ -0,0 +1 @@ +liteflow.rule-source=el_xml:127.0.0.1:21810,127.0.0.1:21811,127.0.0.1:21812 \ No newline at end of file