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 d5636da1d..99b1a4d99 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 @@ -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; + } + } } diff --git a/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/base/BaseCommonTest.java b/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/base/BaseCommonTest.java index 25b806846..c2c10e524 100644 --- a/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/base/BaseCommonTest.java +++ b/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; diff --git a/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/removeChain/RemoveChainTest.java b/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/removeChain/RemoveChainTest.java new file mode 100644 index 000000000..4fe71572c --- /dev/null +++ b/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 response1 = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response1.isSuccess()); + FlowBus.removeChain("chain1"); + LiteflowResponse response2 = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertFalse(response2.isSuccess()); + } +} diff --git a/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/ACmp.java b/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/ACmp.java new file mode 100644 index 000000000..a193745c4 --- /dev/null +++ b/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/ACmp.java @@ -0,0 +1,18 @@ +/** + *

Title: liteflow

+ *

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

+ * @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!"); + } +} diff --git a/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/BCmp.java b/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/BCmp.java new file mode 100644 index 000000000..40f9a2e44 --- /dev/null +++ b/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/BCmp.java @@ -0,0 +1,19 @@ +/** + *

Title: liteflow

+ *

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

+ * @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!"); + } + +} diff --git a/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/CCmp.java b/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/CCmp.java new file mode 100644 index 000000000..cabdd1527 --- /dev/null +++ b/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/CCmp.java @@ -0,0 +1,19 @@ +/** + *

Title: liteflow

+ *

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

+ * @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!"); + } + +} diff --git a/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/DCmp.java b/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/DCmp.java new file mode 100644 index 000000000..804407438 --- /dev/null +++ b/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/DCmp.java @@ -0,0 +1,19 @@ +/** + *

Title: liteflow

+ *

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

+ * @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!"); + } + +} diff --git a/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/resizeSlot/ResizeSlotTest.java b/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/resizeSlot/ResizeSlotTest.java index 50010378e..7df51cd44 100644 --- a/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/resizeSlot/ResizeSlotTest.java +++ b/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>> futureList = new ArrayList<>(); - for (int i = 0; i < 100; i++) { - Future> future = pool.submit(() -> flowExecutor.execute2Resp("chain1", "arg")); - futureList.add(future); + List>> futureList = new ArrayList<>(); + for (int i = 0; i < 100; i++) { + Future> future = pool.submit(() -> flowExecutor.execute2Resp("chain1", "arg")); + futureList.add(future); + } + + for(Future> future : futureList){ + Assert.assertTrue(future.get().isSuccess()); + } + + //取到static的对象QUEUE + Field field = ReflectUtil.getField(DataBus.class, "QUEUE"); + ConcurrentLinkedQueue queue = (ConcurrentLinkedQueue) 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(); } - for(Future> future : futureList){ - Assert.assertTrue(future.get().isSuccess()); - } - - //取到static的对象QUEUE - Field field = ReflectUtil.getField(DataBus.class, "QUEUE"); - ConcurrentLinkedQueue queue = (ConcurrentLinkedQueue) ReflectUtil.getStaticFieldValue(field); - - //因为初始slotSize是4,按照0.75的扩容比,要满足100个线程,应该扩容5~6次,5次=65,6次=114 - //为什么不是直接114呢? - //因为在单测中根据机器的性能,在多线程情况下,有些机器跑的慢一点,也就是说65个就足够了。有些机器跑的快一点,是能真正扩容到114个的 - Assert.assertTrue(queue.size() > 4); } } diff --git a/liteflow-testcase-nospring/src/test/resources/removeChain/flow.xml b/liteflow-testcase-nospring/src/test/resources/removeChain/flow.xml new file mode 100644 index 000000000..c8bd6b3b2 --- /dev/null +++ b/liteflow-testcase-nospring/src/test/resources/removeChain/flow.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/removeChain/RemoveChainSpringbootTest.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/removeChain/RemoveChainSpringbootTest.java new file mode 100644 index 000000000..c4694585d --- /dev/null +++ b/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 response1 = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response1.isSuccess()); + FlowBus.removeChain("chain1"); + LiteflowResponse response2 = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertFalse(response2.isSuccess()); + } + +} diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/ACmp.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/ACmp.java new file mode 100644 index 000000000..8640323d1 --- /dev/null +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/removeChain/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.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!"); + } +} diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/BCmp.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/BCmp.java new file mode 100644 index 000000000..3a81b5a66 --- /dev/null +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/removeChain/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.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!"); + } + +} diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/CCmp.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/CCmp.java new file mode 100644 index 000000000..e6ef9f22d --- /dev/null +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/removeChain/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.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!"); + } + +} diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/DCmp.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/DCmp.java new file mode 100644 index 000000000..51f9407fe --- /dev/null +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/DCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

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

+ * @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!"); + } + +} diff --git a/liteflow-testcase-springboot/src/test/resources/base/flow.xml b/liteflow-testcase-springboot/src/test/resources/base/flow.xml index a7517a2cf..7068d6cee 100644 --- a/liteflow-testcase-springboot/src/test/resources/base/flow.xml +++ b/liteflow-testcase-springboot/src/test/resources/base/flow.xml @@ -4,5 +4,4 @@ - \ No newline at end of file diff --git a/liteflow-testcase-springboot/src/test/resources/removeChain/application.properties b/liteflow-testcase-springboot/src/test/resources/removeChain/application.properties new file mode 100644 index 000000000..729879505 --- /dev/null +++ b/liteflow-testcase-springboot/src/test/resources/removeChain/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=removeChain/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-springboot/src/test/resources/removeChain/flow.xml b/liteflow-testcase-springboot/src/test/resources/removeChain/flow.xml new file mode 100644 index 000000000..c89c44473 --- /dev/null +++ b/liteflow-testcase-springboot/src/test/resources/removeChain/flow.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/removeChain/RemoveChainSpringTest.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/removeChain/RemoveChainSpringTest.java new file mode 100644 index 000000000..1308b5b15 --- /dev/null +++ b/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 response1 = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response1.isSuccess()); + FlowBus.removeChain("chain1"); + LiteflowResponse response2 = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertFalse(response2.isSuccess()); + } +} diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/ACmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/ACmp.java new file mode 100644 index 000000000..8640323d1 --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/removeChain/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.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!"); + } +} diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/BCmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/BCmp.java new file mode 100644 index 000000000..3a81b5a66 --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/removeChain/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.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!"); + } + +} diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/CCmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/CCmp.java new file mode 100644 index 000000000..e6ef9f22d --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/removeChain/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.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!"); + } + +} diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/DCmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/DCmp.java new file mode 100644 index 000000000..51f9407fe --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/DCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

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

+ * @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!"); + } + +} diff --git a/liteflow-testcase-springnative/src/test/resources/removeChain/application.xml b/liteflow-testcase-springnative/src/test/resources/removeChain/application.xml new file mode 100644 index 000000000..4ea254e65 --- /dev/null +++ b/liteflow-testcase-springnative/src/test/resources/removeChain/application.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-springnative/src/test/resources/removeChain/flow.xml b/liteflow-testcase-springnative/src/test/resources/removeChain/flow.xml new file mode 100644 index 000000000..c89c44473 --- /dev/null +++ b/liteflow-testcase-springnative/src/test/resources/removeChain/flow.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file