From b05aba0e1d099922e9a7017034b7ff5a6ce8fdd7 Mon Sep 17 00:00:00 2001 From: zendwang Date: Mon, 7 Nov 2022 22:51:47 +0800 Subject: [PATCH] =?UTF-8?q?enhancement=20=20=E6=94=AF=E6=8C=81etcd?= =?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 --- .../parser/etcd/util/EtcdParserHelper.java | 28 ++++++++----------- .../etcd/EtcdWithXmlELSpringbootTest.java | 13 ++++++--- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/liteflow-rule-plugin/liteflow-rule-etcd/src/main/java/com/yomahub/liteflow/parser/etcd/util/EtcdParserHelper.java b/liteflow-rule-plugin/liteflow-rule-etcd/src/main/java/com/yomahub/liteflow/parser/etcd/util/EtcdParserHelper.java index 89e4a9798..45b378fc1 100644 --- a/liteflow-rule-plugin/liteflow-rule-etcd/src/main/java/com/yomahub/liteflow/parser/etcd/util/EtcdParserHelper.java +++ b/liteflow-rule-plugin/liteflow-rule-etcd/src/main/java/com/yomahub/liteflow/parser/etcd/util/EtcdParserHelper.java @@ -68,11 +68,6 @@ public class EtcdParserHelper { public String getContent(){ try{ - //检查zk上有没有chainPath节点 -// if (client.get(etcdParserVO.getChainPath()) == null) { -// throw new EtcdException(StrUtil.format("etcd node[{}] is not exist", etcdParserVO.getChainPath())); -// } - //检查chainPath路径下有没有子节点 List chainNameList = client.getChildrenKeys(etcdParserVO.getChainPath(), SEPARATOR); if (CollectionUtil.isEmpty(chainNameList)){ @@ -128,11 +123,6 @@ public class EtcdParserHelper { } try{ - //配置了,但是不存在这个节点 -// if (client.get(etcdParserVO.getScriptPath()) == null){ -// return false; -// } - //存在这个节点,但是子节点不存在 List chainNameList = client.getChildrenKeys(etcdParserVO.getScriptPath(), SEPARATOR); if (CollUtil.isEmpty(chainNameList)){ @@ -151,13 +141,19 @@ public class EtcdParserHelper { */ public void listen(Consumer parseConsumer) { this.client.watchChildChange(this.etcdParserVO.getChainPath(), (updatePath, updateValue) -> { - LOG.info("starting load flow config...."); - parseConsumer.accept(updateValue); - }, null); + LOG.info("update path={} value={},starting reload flow config...", updatePath, updateValue); + parseConsumer.accept(getContent()); + }, (deletePath) -> { + LOG.info("delete path={},starting reload flow config...", deletePath); + parseConsumer.accept(getContent()); + }); this.client.watchChildChange(this.etcdParserVO.getScriptPath(), (updatePath, updateValue) -> { - LOG.info("starting load flow config...."); - parseConsumer.accept(updateValue); - }, null); + LOG.info("update path={} value={},starting reload flow config...", updatePath, updateValue); + parseConsumer.accept(getContent()); + }, (deletePath) -> { + LOG.info("delete path={},starting reload flow config....", deletePath); + parseConsumer.accept(getContent()); + }); } public NodeSimpleVO convert(String str){ diff --git a/liteflow-testcase-el/liteflow-testcase-el-etcd-springboot/src/test/java/com/yomahub/liteflow/test/etcd/EtcdWithXmlELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-etcd-springboot/src/test/java/com/yomahub/liteflow/test/etcd/EtcdWithXmlELSpringbootTest.java index 05adea606..082e36f10 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-etcd-springboot/src/test/java/com/yomahub/liteflow/test/etcd/EtcdWithXmlELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-etcd-springboot/src/test/java/com/yomahub/liteflow/test/etcd/EtcdWithXmlELSpringbootTest.java @@ -1,5 +1,6 @@ package com.yomahub.liteflow.test.etcd; +import cn.hutool.core.lang.Console; import cn.hutool.core.util.ReflectUtil; import com.yomahub.liteflow.core.FlowExecutor; import com.yomahub.liteflow.enums.FlowParserTypeEnum; @@ -65,7 +66,7 @@ public class EtcdWithXmlELSpringbootTest extends BaseTest { LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); DefaultContext context = response.getFirstContextBean(); Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>c==>s1[脚本s1]", response.getExecuteStepStr()); + Assert.assertEquals("a==>b==>s1[脚本s1]", response.getExecuteStepStr()); Assert.assertEquals("hello", context.getData("test")); } @@ -77,13 +78,17 @@ public class EtcdWithXmlELSpringbootTest extends BaseTest { // LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>c==>s1[脚本s1]", response.getExecuteStepStr()); + Assert.assertEquals("a==>b==>s1[脚本s1]", response.getExecuteStepStr()); + int i=0; + while (i <= 100000) { + i++; + } // 手动触发一次 模拟节点数据变更 //FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML,changedFlowXml); - Thread.sleep(9000); + LiteflowResponse response2 = flowExecutor.execute2Resp("chain1", "arg"); Assert.assertTrue(response2.isSuccess()); - Assert.assertEquals("a==>b==>s1[脚本s1]", response2.getExecuteStepStr()); + Assert.assertEquals("a==>b==>c==>s1[脚本s1]", response.getExecuteStepStr()); } }