From a380c972095b8c890768dc85aa025bd2cfda76c0 Mon Sep 17 00:00:00 2001 From: bryan31 Date: Thu, 4 Nov 2021 19:11:18 +0800 Subject: [PATCH] =?UTF-8?q?bug=20#I4GY9L=20=E5=9C=A8=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E5=90=8E=E9=A9=AC=E4=B8=8A=E5=88=B7=E6=96=B0=E6=B5=81=E7=A8=8B?= =?UTF-8?q?=E5=90=8E=E4=BC=9A=E6=9C=89offerSlot=E7=9A=84=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- liteflow-core/pom.xml | 2 +- .../yomahub/liteflow/entity/data/DataBus.java | 11 +++-- .../com/yomahub/liteflow/flow/FlowBus.java | 6 +++ liteflow-script-common/pom.xml | 2 +- liteflow-script-groovy/pom.xml | 2 +- liteflow-script-qlexpress/pom.xml | 2 +- liteflow-spring-boot-starter/pom.xml | 2 +- liteflow-testcase-script-groovy/pom.xml | 2 +- liteflow-testcase-script-qlexpress/pom.xml | 2 +- liteflow-testcase-springboot/pom.xml | 2 +- .../RefreshRuleSpringbootTest.java | 43 +++++++++++++++++++ .../liteflow/test/refreshRule/cmp/ACmp.java | 20 +++++++++ .../liteflow/test/refreshRule/cmp/BCmp.java | 21 +++++++++ .../liteflow/test/refreshRule/cmp/CCmp.java | 21 +++++++++ .../refreshRule/application.properties | 2 + .../src/test/resources/refreshRule/flow.xml | 6 +++ liteflow-testcase-springnative/pom.xml | 2 +- pom.xml | 2 +- 18 files changed, 136 insertions(+), 14 deletions(-) create mode 100644 liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleSpringbootTest.java create mode 100644 liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/ACmp.java create mode 100644 liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/BCmp.java create mode 100644 liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/CCmp.java create mode 100644 liteflow-testcase-springboot/src/test/resources/refreshRule/application.properties create mode 100644 liteflow-testcase-springboot/src/test/resources/refreshRule/flow.xml diff --git a/liteflow-core/pom.xml b/liteflow-core/pom.xml index c001fdcab..dd00d8cfb 100644 --- a/liteflow-core/pom.xml +++ b/liteflow-core/pom.xml @@ -9,7 +9,7 @@ com.yomahub liteflow - 2.6.3 + 2.6.4 diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/entity/data/DataBus.java b/liteflow-core/src/main/java/com/yomahub/liteflow/entity/data/DataBus.java index 4630e48d7..5a7baf157 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/entity/data/DataBus.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/entity/data/DataBus.java @@ -7,6 +7,7 @@ */ package com.yomahub.liteflow.entity.data; +import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.ObjectUtil; import com.yomahub.liteflow.property.LiteflowConfig; import com.yomahub.liteflow.property.LiteflowConfigGetter; @@ -44,11 +45,13 @@ public class DataBus { //因为单元测试中所有的一起跑,jvm是不退出的,所以如果是static块的话,跑多个testsuite只会执行一次。 //而由FlowExecutor中的init去调用,是会被执行多次的。保证了每个单元测试都能初始化一遍 public static void init() { - LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - currentIndexMaxValue = liteflowConfig.getSlotSize(); + if (MapUtil.isEmpty(SLOTS)){ + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + currentIndexMaxValue = liteflowConfig.getSlotSize(); - SLOTS = new ConcurrentHashMap<>(); - QUEUE = IntStream.range(0, currentIndexMaxValue).boxed().collect(Collectors.toCollection(ConcurrentLinkedQueue::new)); + SLOTS = new ConcurrentHashMap<>(); + QUEUE = IntStream.range(0, currentIndexMaxValue).boxed().collect(Collectors.toCollection(ConcurrentLinkedQueue::new)); + } } public static int offerSlot(Class slotClazz) { diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/FlowBus.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/FlowBus.java index ecf031a94..5afeb34ff 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/FlowBus.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/FlowBus.java @@ -15,6 +15,7 @@ import com.yomahub.liteflow.core.ComponentInitializer; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.core.ScriptComponent; import com.yomahub.liteflow.core.ScriptCondComponent; +import com.yomahub.liteflow.entity.data.DataBus; import com.yomahub.liteflow.entity.flow.Chain; import com.yomahub.liteflow.entity.flow.Node; import com.yomahub.liteflow.enums.FlowParserTypeEnum; @@ -167,5 +168,10 @@ public class FlowBus { } else if (type.equals(FlowParserTypeEnum.TYPE_YML)) { new LocalYmlFlowParser().parse(content); } + + //这里是一个防御性策略,在parse-on-start参数为false的时候 + //启动时马上刷新流程规则,这时DataBus还未init,所以这时需要init一下 + //在DataBus里对init有判断,所以init不会执行多遍 + DataBus.init(); } } diff --git a/liteflow-script-common/pom.xml b/liteflow-script-common/pom.xml index c089b6fea..ccbcc25cb 100644 --- a/liteflow-script-common/pom.xml +++ b/liteflow-script-common/pom.xml @@ -5,7 +5,7 @@ liteflow com.yomahub - 2.6.3 + 2.6.4 4.0.0 diff --git a/liteflow-script-groovy/pom.xml b/liteflow-script-groovy/pom.xml index 37b061e46..40de32182 100644 --- a/liteflow-script-groovy/pom.xml +++ b/liteflow-script-groovy/pom.xml @@ -5,7 +5,7 @@ liteflow com.yomahub - 2.6.3 + 2.6.4 4.0.0 diff --git a/liteflow-script-qlexpress/pom.xml b/liteflow-script-qlexpress/pom.xml index df1658f58..b69f9fd59 100644 --- a/liteflow-script-qlexpress/pom.xml +++ b/liteflow-script-qlexpress/pom.xml @@ -5,7 +5,7 @@ liteflow com.yomahub - 2.6.3 + 2.6.4 4.0.0 diff --git a/liteflow-spring-boot-starter/pom.xml b/liteflow-spring-boot-starter/pom.xml index cfb8d2869..a266bebce 100644 --- a/liteflow-spring-boot-starter/pom.xml +++ b/liteflow-spring-boot-starter/pom.xml @@ -10,7 +10,7 @@ liteflow com.yomahub - 2.6.3 + 2.6.4 diff --git a/liteflow-testcase-script-groovy/pom.xml b/liteflow-testcase-script-groovy/pom.xml index a2578edbb..8becb3774 100644 --- a/liteflow-testcase-script-groovy/pom.xml +++ b/liteflow-testcase-script-groovy/pom.xml @@ -5,7 +5,7 @@ liteflow com.yomahub - 2.6.3 + 2.6.4 4.0.0 diff --git a/liteflow-testcase-script-qlexpress/pom.xml b/liteflow-testcase-script-qlexpress/pom.xml index 5794557cd..7ac6c522d 100644 --- a/liteflow-testcase-script-qlexpress/pom.xml +++ b/liteflow-testcase-script-qlexpress/pom.xml @@ -5,7 +5,7 @@ liteflow com.yomahub - 2.6.3 + 2.6.4 4.0.0 diff --git a/liteflow-testcase-springboot/pom.xml b/liteflow-testcase-springboot/pom.xml index 46d24561b..78df5437c 100644 --- a/liteflow-testcase-springboot/pom.xml +++ b/liteflow-testcase-springboot/pom.xml @@ -5,7 +5,7 @@ liteflow com.yomahub - 2.6.3 + 2.6.4 4.0.0 diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleSpringbootTest.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleSpringbootTest.java new file mode 100644 index 000000000..3a4e073b7 --- /dev/null +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleSpringbootTest.java @@ -0,0 +1,43 @@ +package com.yomahub.liteflow.test.refreshRule; + +import cn.hutool.core.io.resource.ResourceUtil; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.enums.FlowParserTypeEnum; +import com.yomahub.liteflow.flow.FlowBus; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +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; + +/** + * springboot环境下重新加载规则测试 + * @author Bryan.Zhang + * @since 2.6.4 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/refreshRule/application.properties") +@SpringBootTest(classes = RefreshRuleSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.refreshRule.cmp"}) +public class RefreshRuleSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testRefresh() throws Exception{ + String content = ResourceUtil.readUtf8Str("classpath: /refreshRule/flow.xml"); + FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_XML, content); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/ACmp.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/ACmp.java new file mode 100644 index 000000000..96d599a5b --- /dev/null +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/ACmp.java @@ -0,0 +1,20 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.refreshRule.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +@Component("a") +public class ACmp extends NodeComponent { + + @Override + public void process() { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/BCmp.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/BCmp.java new file mode 100644 index 000000000..8930ff9d0 --- /dev/null +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/BCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.refreshRule.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +@Component("b") +public class BCmp extends NodeComponent { + + @Override + public void process() { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/CCmp.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/CCmp.java new file mode 100644 index 000000000..b15889a00 --- /dev/null +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/CCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.refreshRule.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +@Component("c") +public class CCmp extends NodeComponent { + + @Override + public void process() { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-springboot/src/test/resources/refreshRule/application.properties b/liteflow-testcase-springboot/src/test/resources/refreshRule/application.properties new file mode 100644 index 000000000..27387bc18 --- /dev/null +++ b/liteflow-testcase-springboot/src/test/resources/refreshRule/application.properties @@ -0,0 +1,2 @@ +liteflow.rule-source=refreshRule/flow.xml +liteflow.parse-on-start=false \ No newline at end of file diff --git a/liteflow-testcase-springboot/src/test/resources/refreshRule/flow.xml b/liteflow-testcase-springboot/src/test/resources/refreshRule/flow.xml new file mode 100644 index 000000000..22870d94f --- /dev/null +++ b/liteflow-testcase-springboot/src/test/resources/refreshRule/flow.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-springnative/pom.xml b/liteflow-testcase-springnative/pom.xml index 120e9bf0f..76dc7a855 100644 --- a/liteflow-testcase-springnative/pom.xml +++ b/liteflow-testcase-springnative/pom.xml @@ -5,7 +5,7 @@ liteflow com.yomahub - 2.6.3 + 2.6.4 4.0.0 diff --git a/pom.xml b/pom.xml index 89989a71e..a199bc53a 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.yomahub liteflow pom - 2.6.3 + 2.6.4 liteflow a lightweight and practical micro-process framework https://github.com/bryan31/liteflow