浏览代码

feature #I51OBD 支持流程的销毁

bryan31 3 年之前
父节点
当前提交
f81e8e0553
共有 24 个文件被更改,包括 446 次插入18 次删除
  1. 11 0
      liteflow-core/src/main/java/com/yomahub/liteflow/flow/FlowBus.java
  2. 2 1
      liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/base/BaseCommonTest.java
  3. 33 0
      liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/removeChain/RemoveChainTest.java
  4. 18 0
      liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/ACmp.java
  5. 19 0
      liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/BCmp.java
  6. 19 0
      liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/CCmp.java
  7. 19 0
      liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/DCmp.java
  8. 21 16
      liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/resizeSlot/ResizeSlotTest.java
  9. 18 0
      liteflow-testcase-nospring/src/test/resources/removeChain/flow.xml
  10. 43 0
      liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/removeChain/RemoveChainSpringbootTest.java
  11. 20 0
      liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/ACmp.java
  12. 21 0
      liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/BCmp.java
  13. 21 0
      liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/CCmp.java
  14. 21 0
      liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/DCmp.java
  15. 0 1
      liteflow-testcase-springboot/src/test/resources/base/flow.xml
  16. 1 0
      liteflow-testcase-springboot/src/test/resources/removeChain/application.properties
  17. 11 0
      liteflow-testcase-springboot/src/test/resources/removeChain/flow.xml
  18. 31 0
      liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/removeChain/RemoveChainSpringTest.java
  19. 20 0
      liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/ACmp.java
  20. 21 0
      liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/BCmp.java
  21. 21 0
      liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/CCmp.java
  22. 21 0
      liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/DCmp.java
  23. 23 0
      liteflow-testcase-springnative/src/test/resources/removeChain/application.xml
  24. 11 0
      liteflow-testcase-springnative/src/test/resources/removeChain/flow.xml

+ 11 - 0
liteflow-core/src/main/java/com/yomahub/liteflow/flow/FlowBus.java

@@ -178,4 +178,15 @@ public class FlowBus {
             new LocalYmlFlowParser().parse(content);
         }
     }
+
+    public static boolean removeChain(String chainId){
+        if (containChain(chainId)){
+            chainMap.remove(chainId);
+            return true;
+        }else{
+            String errMsg = StrUtil.format("cannot find the chain[{}]", chainId);
+            LOG.error(errMsg);
+            return false;
+        }
+    }
 }

+ 2 - 1
liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/base/BaseCommonTest.java

@@ -5,11 +5,12 @@ import com.yomahub.liteflow.core.FlowExecutorHolder;
 import com.yomahub.liteflow.entity.data.DefaultSlot;
 import com.yomahub.liteflow.entity.data.LiteflowResponse;
 import com.yomahub.liteflow.property.LiteflowConfig;
+import com.yomahub.liteflow.test.BaseTest;
 import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
-public class BaseCommonTest {
+public class BaseCommonTest extends BaseTest{
 
     private static FlowExecutor flowExecutor;
 

+ 33 - 0
liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/removeChain/RemoveChainTest.java

@@ -0,0 +1,33 @@
+package com.yomahub.liteflow.test.removeChain;
+
+import com.yomahub.liteflow.core.FlowExecutor;
+import com.yomahub.liteflow.core.FlowExecutorHolder;
+import com.yomahub.liteflow.entity.data.DefaultSlot;
+import com.yomahub.liteflow.entity.data.LiteflowResponse;
+import com.yomahub.liteflow.flow.FlowBus;
+import com.yomahub.liteflow.property.LiteflowConfig;
+import com.yomahub.liteflow.test.BaseTest;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class RemoveChainTest extends BaseTest{
+
+    private static FlowExecutor flowExecutor;
+
+    @BeforeClass
+    public static void init(){
+        LiteflowConfig config = new LiteflowConfig();
+        config.setRuleSource("removeChain/flow.xml");
+        flowExecutor = FlowExecutorHolder.loadInstance(config);
+    }
+
+    @Test
+    public void testRemoveChain(){
+        LiteflowResponse<DefaultSlot> response1 = flowExecutor.execute2Resp("chain1", "arg");
+        Assert.assertTrue(response1.isSuccess());
+        FlowBus.removeChain("chain1");
+        LiteflowResponse<DefaultSlot> response2 = flowExecutor.execute2Resp("chain1", "arg");
+        Assert.assertFalse(response2.isSuccess());
+    }
+}

+ 18 - 0
liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/ACmp.java

@@ -0,0 +1,18 @@
+/**
+ * <p>Title: liteflow</p>
+ * <p>Description: 轻量级的组件式流程框架</p>
+ * @author Bryan.Zhang
+ * @email weenyc31@163.com
+ * @Date 2020/4/1
+ */
+package com.yomahub.liteflow.test.removeChain.cmp;
+
+import com.yomahub.liteflow.core.NodeComponent;
+
+public class ACmp extends NodeComponent {
+
+	@Override
+	public void process() {
+		System.out.println("ACmp executed!");
+	}
+}

+ 19 - 0
liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/BCmp.java

@@ -0,0 +1,19 @@
+/**
+ * <p>Title: liteflow</p>
+ * <p>Description: 轻量级的组件式流程框架</p>
+ * @author Bryan.Zhang
+ * @email weenyc31@163.com
+ * @Date 2020/4/1
+ */
+package com.yomahub.liteflow.test.removeChain.cmp;
+
+import com.yomahub.liteflow.core.NodeComponent;
+
+public class BCmp extends NodeComponent {
+
+	@Override
+	public void process() {
+		System.out.println("BCmp executed!");
+	}
+
+}

+ 19 - 0
liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/CCmp.java

@@ -0,0 +1,19 @@
+/**
+ * <p>Title: liteflow</p>
+ * <p>Description: 轻量级的组件式流程框架</p>
+ * @author Bryan.Zhang
+ * @email weenyc31@163.com
+ * @Date 2020/4/1
+ */
+package com.yomahub.liteflow.test.removeChain.cmp;
+
+import com.yomahub.liteflow.core.NodeComponent;
+
+public class CCmp extends NodeComponent {
+
+	@Override
+	public void process() {
+		System.out.println("CCmp executed!");
+	}
+
+}

+ 19 - 0
liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/DCmp.java

@@ -0,0 +1,19 @@
+/**
+ * <p>Title: liteflow</p>
+ * <p>Description: 轻量级的组件式流程框架</p>
+ * @author Bryan.Zhang
+ * @email weenyc31@163.com
+ * @Date 2020/4/1
+ */
+package com.yomahub.liteflow.test.removeChain.cmp;
+
+import com.yomahub.liteflow.core.NodeComponent;
+
+public class DCmp extends NodeComponent {
+
+	@Override
+	public void process() {
+		System.out.println("CCmp executed!");
+	}
+
+}

+ 21 - 16
liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/resizeSlot/ResizeSlotTest.java

@@ -38,25 +38,30 @@ public class ResizeSlotTest extends BaseTest {
 
     @Test
     public void testResize() throws Exception{
-        ExecutorService pool = Executors.newCachedThreadPool();
+        try{
+            ExecutorService pool = Executors.newCachedThreadPool();
 
-        List<Future<LiteflowResponse<DefaultSlot>>> futureList = new ArrayList<>();
-        for (int i = 0; i < 100; i++) {
-            Future<LiteflowResponse<DefaultSlot>> future = pool.submit(() -> flowExecutor.execute2Resp("chain1", "arg"));
-            futureList.add(future);
-        }
+            List<Future<LiteflowResponse<DefaultSlot>>> futureList = new ArrayList<>();
+            for (int i = 0; i < 100; i++) {
+                Future<LiteflowResponse<DefaultSlot>> future = pool.submit(() -> flowExecutor.execute2Resp("chain1", "arg"));
+                futureList.add(future);
+            }
 
-        for(Future<LiteflowResponse<DefaultSlot>> future : futureList){
-            Assert.assertTrue(future.get().isSuccess());
-        }
+            for(Future<LiteflowResponse<DefaultSlot>> future : futureList){
+                Assert.assertTrue(future.get().isSuccess());
+            }
 
-        //取到static的对象QUEUE
-        Field field = ReflectUtil.getField(DataBus.class, "QUEUE");
-        ConcurrentLinkedQueue<Integer> queue = (ConcurrentLinkedQueue<Integer>) ReflectUtil.getStaticFieldValue(field);
+            //取到static的对象QUEUE
+            Field field = ReflectUtil.getField(DataBus.class, "QUEUE");
+            ConcurrentLinkedQueue<Integer> queue = (ConcurrentLinkedQueue<Integer>) ReflectUtil.getStaticFieldValue(field);
+
+            //因为初始slotSize是4,按照0.75的扩容比,要满足100个线程,应该扩容5~6次,5次=65,6次=114
+            //为什么不是直接114呢?
+            //因为在单测中根据机器的性能,在多线程情况下,有些机器跑的慢一点,也就是说65个就足够了。有些机器跑的快一点,是能真正扩容到114个的
+            Assert.assertTrue(queue.size() > 4);
+        }catch (Exception e){
+            e.printStackTrace();
+        }
 
-        //因为初始slotSize是4,按照0.75的扩容比,要满足100个线程,应该扩容5~6次,5次=65,6次=114
-        //为什么不是直接114呢?
-        //因为在单测中根据机器的性能,在多线程情况下,有些机器跑的慢一点,也就是说65个就足够了。有些机器跑的快一点,是能真正扩容到114个的
-        Assert.assertTrue(queue.size() > 4);
     }
 }

+ 18 - 0
liteflow-testcase-nospring/src/test/resources/removeChain/flow.xml

@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<flow>
+    <nodes>
+        <node id="a" class="com.yomahub.liteflow.test.removeChain.cmp.ACmp"/>
+        <node id="b" class="com.yomahub.liteflow.test.removeChain.cmp.BCmp"/>
+        <node id="c" class="com.yomahub.liteflow.test.removeChain.cmp.CCmp"/>
+        <node id="d" class="com.yomahub.liteflow.test.removeChain.cmp.DCmp"/>
+    </nodes>
+
+    <chain name="chain1">
+        <then value="a,b"/>
+        <when value="c,d"/>
+    </chain>
+
+    <chain name="chain2">
+        <then value="a,b,c,d"/>
+    </chain>
+</flow>

+ 43 - 0
liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/removeChain/RemoveChainSpringbootTest.java

@@ -0,0 +1,43 @@
+package com.yomahub.liteflow.test.removeChain;
+
+import com.yomahub.liteflow.core.FlowExecutor;
+import com.yomahub.liteflow.entity.data.DefaultSlot;
+import com.yomahub.liteflow.entity.data.LiteflowResponse;
+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:/removeChain/application.properties")
+@SpringBootTest(classes = RemoveChainSpringbootTest.class)
+@EnableAutoConfiguration
+@ComponentScan({"com.yomahub.liteflow.test.removeChain.cmp"})
+public class RemoveChainSpringbootTest extends BaseTest {
+
+    @Resource
+    private FlowExecutor flowExecutor;
+
+    @Test
+    public void testRemoveChain() throws Exception{
+        LiteflowResponse<DefaultSlot> response1 = flowExecutor.execute2Resp("chain1", "arg");
+        Assert.assertTrue(response1.isSuccess());
+        FlowBus.removeChain("chain1");
+        LiteflowResponse<DefaultSlot> response2 = flowExecutor.execute2Resp("chain1", "arg");
+        Assert.assertFalse(response2.isSuccess());
+    }
+
+}

+ 20 - 0
liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/removeChain/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.removeChain.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/removeChain/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.removeChain.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/removeChain/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.removeChain.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-springboot/src/test/java/com/yomahub/liteflow/test/removeChain/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.removeChain.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!");
+	}
+
+}

+ 0 - 1
liteflow-testcase-springboot/src/test/resources/base/flow.xml

@@ -4,5 +4,4 @@
         <then value="a,b"/>
         <when value="c,d"/>
     </chain>
-
 </flow>

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

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

+ 11 - 0
liteflow-testcase-springboot/src/test/resources/removeChain/flow.xml

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

+ 31 - 0
liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/removeChain/RemoveChainSpringTest.java

@@ -0,0 +1,31 @@
+package com.yomahub.liteflow.test.removeChain;
+
+import com.yomahub.liteflow.core.FlowExecutor;
+import com.yomahub.liteflow.entity.data.DefaultSlot;
+import com.yomahub.liteflow.entity.data.LiteflowResponse;
+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.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import javax.annotation.Resource;
+
+@RunWith(SpringRunner.class)
+@ContextConfiguration("classpath:/removeChain/application.xml")
+public class RemoveChainSpringTest extends BaseTest {
+
+    @Resource
+    private FlowExecutor flowExecutor;
+
+    @Test
+    public void testRemoveChain(){
+        LiteflowResponse<DefaultSlot> response1 = flowExecutor.execute2Resp("chain1", "arg");
+        Assert.assertTrue(response1.isSuccess());
+        FlowBus.removeChain("chain1");
+        LiteflowResponse<DefaultSlot> response2 = flowExecutor.execute2Resp("chain1", "arg");
+        Assert.assertFalse(response2.isSuccess());
+    }
+}

+ 20 - 0
liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/removeChain/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.removeChain.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-springnative/src/test/java/com/yomahub/liteflow/test/removeChain/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.removeChain.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-springnative/src/test/java/com/yomahub/liteflow/test/removeChain/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.removeChain.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-springnative/src/test/java/com/yomahub/liteflow/test/removeChain/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.removeChain.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!");
+	}
+
+}

+ 23 - 0
liteflow-testcase-springnative/src/test/resources/removeChain/application.xml

@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns="http://www.springframework.org/schema/beans"
+       xmlns:context="http://www.springframework.org/schema/context"
+       xsi:schemaLocation="http://www.springframework.org/schema/beans
+       http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
+       http://www.springframework.org/schema/context
+       http://www.springframework.org/schema/context/spring-context-4.0.xsd">
+
+    <context:component-scan base-package="com.yomahub.liteflow.test.removeChain.cmp" />
+
+    <bean id="springAware" class="com.yomahub.liteflow.spi.spring.SpringAware"/>
+
+    <bean class="com.yomahub.liteflow.spring.ComponentScanner"/>
+
+    <bean id="liteflowConfig" class="com.yomahub.liteflow.property.LiteflowConfig">
+        <property name="ruleSource" value="removeChain/flow.xml"/>
+    </bean>
+
+    <bean id="flowExecutor" class="com.yomahub.liteflow.core.FlowExecutor">
+        <constructor-arg name="liteflowConfig" ref="liteflowConfig"/>
+    </bean>
+</beans>

+ 11 - 0
liteflow-testcase-springnative/src/test/resources/removeChain/flow.xml

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