Bläddra i källkod

bug #I4GY9L 在启动后马上刷新流程后会有offerSlot的报错

bryan31 3 år sedan
förälder
incheckning
a380c97209

+ 1 - 1
liteflow-core/pom.xml

@@ -9,7 +9,7 @@
     <parent>
 		<groupId>com.yomahub</groupId>
 		<artifactId>liteflow</artifactId>
-		<version>2.6.3</version>
+		<version>2.6.4</version>
 	</parent>
 
 	<dependencies>

+ 7 - 4
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<? extends Slot> slotClazz) {

+ 6 - 0
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();
     }
 }

+ 1 - 1
liteflow-script-common/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>liteflow</artifactId>
         <groupId>com.yomahub</groupId>
-        <version>2.6.3</version>
+        <version>2.6.4</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 1 - 1
liteflow-script-groovy/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>liteflow</artifactId>
         <groupId>com.yomahub</groupId>
-        <version>2.6.3</version>
+        <version>2.6.4</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 1 - 1
liteflow-script-qlexpress/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>liteflow</artifactId>
         <groupId>com.yomahub</groupId>
-        <version>2.6.3</version>
+        <version>2.6.4</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 1 - 1
liteflow-spring-boot-starter/pom.xml

@@ -10,7 +10,7 @@
     <parent>
         <artifactId>liteflow</artifactId>
         <groupId>com.yomahub</groupId>
-        <version>2.6.3</version>
+        <version>2.6.4</version>
     </parent>
 
     <dependencies>

+ 1 - 1
liteflow-testcase-script-groovy/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>liteflow</artifactId>
         <groupId>com.yomahub</groupId>
-        <version>2.6.3</version>
+        <version>2.6.4</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 1 - 1
liteflow-testcase-script-qlexpress/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>liteflow</artifactId>
         <groupId>com.yomahub</groupId>
-        <version>2.6.3</version>
+        <version>2.6.4</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 1 - 1
liteflow-testcase-springboot/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>liteflow</artifactId>
         <groupId>com.yomahub</groupId>
-        <version>2.6.3</version>
+        <version>2.6.4</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 43 - 0
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<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg");
+        Assert.assertTrue(response.isSuccess());
+    }
+}

+ 20 - 0
liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/ACmp.java

@@ -0,0 +1,20 @@
+/**
+ * <p>Title: liteflow</p>
+ * <p>Description: 轻量级的组件式流程框架</p>
+ * @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!");
+	}
+}

+ 21 - 0
liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/BCmp.java

@@ -0,0 +1,21 @@
+/**
+ * <p>Title: liteflow</p>
+ * <p>Description: 轻量级的组件式流程框架</p>
+ * @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!");
+	}
+
+}

+ 21 - 0
liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/CCmp.java

@@ -0,0 +1,21 @@
+/**
+ * <p>Title: liteflow</p>
+ * <p>Description: 轻量级的组件式流程框架</p>
+ * @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!");
+	}
+
+}

+ 2 - 0
liteflow-testcase-springboot/src/test/resources/refreshRule/application.properties

@@ -0,0 +1,2 @@
+liteflow.rule-source=refreshRule/flow.xml
+liteflow.parse-on-start=false

+ 6 - 0
liteflow-testcase-springboot/src/test/resources/refreshRule/flow.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<flow>
+    <chain name="chain1">
+        <then value="a,b,c"/>
+    </chain>
+</flow>

+ 1 - 1
liteflow-testcase-springnative/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>liteflow</artifactId>
         <groupId>com.yomahub</groupId>
-        <version>2.6.3</version>
+        <version>2.6.4</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 1 - 1
pom.xml

@@ -5,7 +5,7 @@
 	<groupId>com.yomahub</groupId>
     <artifactId>liteflow</artifactId>
     <packaging>pom</packaging>
-    <version>2.6.3</version>
+    <version>2.6.4</version>
 	<name>liteflow</name>
 	<description>a lightweight and practical micro-process framework</description>
 	<url>https://github.com/bryan31/liteflow</url>