Bladeren bron

添加常量 调整测试用例

jay li 6 maanden geleden
bovenliggende
commit
ae85d90e5e

+ 3 - 1
liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java

@@ -33,6 +33,8 @@ import java.io.File;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import static com.yomahub.liteflow.common.ChainConstant.NODE_INSTANCE_PATH;
+import static com.yomahub.liteflow.common.ChainConstant.USER_DIR;
 import static com.yomahub.liteflow.util.JsonUtil.*;
 import static com.yomahub.liteflow.util.SerialsUtil.generateShortUUID;
 
@@ -244,7 +246,7 @@ public class LiteFlowChainELBuilder {
 	}
 
     private void setNodesInstanceId(Condition condition) {
-        File nodeDir = new File(System.getProperty("user.dir")+  File.separator + ".node_instance_id" + File.separator + this.chain.getChainId());
+        File nodeDir = new File(System.getProperty(USER_DIR)+  File.separator + NODE_INSTANCE_PATH + File.separator + this.chain.getChainId());
         String elMd5 = MD5.create().digestHex(chain.getEl());
 
         // 如果文件不存在,或者文件内容不是当前el,则写入

+ 3 - 0
liteflow-core/src/main/java/com/yomahub/liteflow/common/ChainConstant.java

@@ -106,4 +106,7 @@ public interface ChainConstant {
 
 	String RETRY = "retry";
 
+	String NODE_INSTANCE_PATH = ".node_instance_id";
+
+	String USER_DIR = "user.dir";
 }

+ 15 - 0
liteflow-rule-plugin/liteflow-rule-redis/pom.xml

@@ -21,9 +21,24 @@
             <scope>provided</scope>
         </dependency>
 
+        <dependency>
+            <groupId>com.fasterxml.jackson.core</groupId>
+            <artifactId>jackson-databind</artifactId>
+        </dependency>
+
         <dependency>
             <groupId>org.redisson</groupId>
             <artifactId>redisson</artifactId>
+            <exclusions>
+                <exclusion>
+                    <groupId>com.fasterxml.jackson.core</groupId>
+                    <artifactId>jackson-databind</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>com.fasterxml.jackson.core</groupId>
+                    <artifactId>jackson-core</artifactId>
+                </exclusion>
+            </exclusions>
         </dependency>
 
         <dependency>

+ 80 - 0
liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/instanceIds/InstanceIdELSpringTest.java

@@ -0,0 +1,80 @@
+package com.yomahub.liteflow.test.instanceIds;
+
+import com.yomahub.liteflow.core.FlowExecutor;
+import com.yomahub.liteflow.flow.LiteflowResponse;
+import com.yomahub.liteflow.test.BaseTest;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+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 javax.annotation.Resource;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * 测试生成 instanceId
+ * @author Jay li
+ */
+@TestPropertySource(value = "classpath:/instanceIds/application.properties")
+@SpringBootTest(classes = InstanceIdELSpringTest.class)
+@EnableAutoConfiguration
+@ComponentScan({ "com.yomahub.liteflow.test.instanceIds.cmp" })
+public class InstanceIdELSpringTest extends BaseTest {
+
+	@Resource
+	private FlowExecutor flowExecutor;
+
+    // 文件保存实例id
+	@Test
+	public void testInstanceIds1() {
+		LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
+		Assertions.assertTrue(response.isSuccess());
+		Assertions.assertEquals("a==>a==>a==>a", response.getExecuteStepStr());
+
+		String executeStepStrWithInstanceId = response.getExecuteStepStrWithInstanceId();
+		Set<String> strings = extractValues(executeStepStrWithInstanceId);
+		System.out.println(executeStepStrWithInstanceId);
+		Assertions.assertEquals(strings.size(), 4);
+	}
+
+	// 重复调用实例id不变
+	@Test
+	public void testInstanceIds2() {
+		LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
+		Assertions.assertTrue(response.isSuccess());
+		Assertions.assertEquals("a==>a==>a==>a", response.getExecuteStepStr());
+
+		String executeStepStrWithInstanceId = response.getExecuteStepStrWithInstanceId();
+		Set<String> set1 = extractValues(executeStepStrWithInstanceId);
+		System.out.println(executeStepStrWithInstanceId);
+
+		Assertions.assertEquals(set1.size(), 4);
+
+		response = flowExecutor.execute2Resp("chain2", "arg");
+		Assertions.assertTrue(response.isSuccess());
+		Assertions.assertEquals("a==>a==>a==>a", response.getExecuteStepStr());
+
+		executeStepStrWithInstanceId = response.getExecuteStepStrWithInstanceId();
+		Set<String> set2 = extractValues(executeStepStrWithInstanceId);
+		System.out.println(executeStepStrWithInstanceId);
+
+		Assertions.assertEquals(set2.size(), 4);
+		Assertions.assertEquals(set1, set2);
+	}
+
+	public static Set<String> extractValues(String input) {
+		Set<String> values = new HashSet<>();
+		Pattern pattern = Pattern.compile("\\[(.*?)]");
+		Matcher matcher = pattern.matcher(input);
+		while (matcher.find()) {
+			values.add(matcher.group(1));
+		}
+		return values;
+	}
+
+}

+ 21 - 0
liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/instanceIds/cmp/ACmp.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.instanceIds.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-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/instanceIds/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.instanceIds.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-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/instanceIds/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.instanceIds.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!");
+	}
+
+}

+ 21 - 0
liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/instanceIds/cmp/DCmp.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.instanceIds.cmp;
+
+import com.yomahub.liteflow.core.NodeComponent;
+import org.springframework.stereotype.Component;
+
+@Component("d")
+public class DCmp extends NodeComponent {
+
+	@Override
+	public void process() {
+		System.out.println("CCmp executed!");
+	}
+
+}

+ 1 - 0
liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/instanceIds/application.properties

@@ -0,0 +1 @@
+liteflow.rule-source=instanceIds/flow.el.xml

+ 10 - 0
liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/instanceIds/flow.el.xml

@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<flow>
+    <chain name="chain1">
+        THEN(a,b,c,d);
+    </chain>
+
+    <chain name="chain2">
+        THEN(a,a,a,a);
+    </chain>
+</flow>