diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutSpringbootTest1.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutSpringbootTest1.java new file mode 100644 index 000000000..78e6a33cf --- /dev/null +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutSpringbootTest1.java @@ -0,0 +1,45 @@ +package com.yomahub.liteflow.test.whenTimeOut; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.exception.WhenTimeoutException; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +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:/whenTimeOut/application1.properties") +@SpringBootTest(classes = WhenTimeOutSpringbootTest1.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.whenTimeOut.cmp"}) +public class WhenTimeOutSpringbootTest1 extends BaseTest { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + @Resource + private FlowExecutor flowExecutor; + + //其中b和c在when情况下超时,所以抛出了WhenTimeoutException这个错 + @Test + public void testWhenTimeOut() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(WhenTimeoutException.class, response.getCause().getClass()); + } +} diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutSpringbootTest.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutSpringbootTest2.java similarity index 78% rename from liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutSpringbootTest.java rename to liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutSpringbootTest2.java index fc6857e95..eb55d0bcf 100644 --- a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutSpringbootTest.java +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutSpringbootTest2.java @@ -1,9 +1,9 @@ package com.yomahub.liteflow.test.whenTimeOut; import com.yomahub.liteflow.core.FlowExecutor; -import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.entity.data.DefaultSlot; import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.exception.WhenTimeoutException; import com.yomahub.liteflow.test.BaseTest; import org.junit.Assert; import org.junit.Test; @@ -24,23 +24,21 @@ import javax.annotation.Resource; * @since 2.6.4 */ @RunWith(SpringRunner.class) -@TestPropertySource(value = "classpath:/whenTimeOut/application.properties") -@SpringBootTest(classes = WhenTimeOutSpringbootTest.class) +@TestPropertySource(value = "classpath:/whenTimeOut/application2.properties") +@SpringBootTest(classes = WhenTimeOutSpringbootTest2.class) @EnableAutoConfiguration @ComponentScan({"com.yomahub.liteflow.test.whenTimeOut.cmp"}) -public class WhenTimeOutSpringbootTest extends BaseTest { +public class WhenTimeOutSpringbootTest2 extends BaseTest { private final Logger log = LoggerFactory.getLogger(this.getClass()); @Resource private FlowExecutor flowExecutor; + //其中d,e,f都sleep 4秒,其中def是不同的组,超时设置5秒 @Test public void testWhenTimeOut() throws Exception{ LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - if (!response.isSuccess()){ - log.error(response.getMessage(),response.getCause()); - } Assert.assertTrue(response.isSuccess()); } } diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/DCmp.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/DCmp.java new file mode 100644 index 000000000..5f3c4b3fb --- /dev/null +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/DCmp.java @@ -0,0 +1,26 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.whenTimeOut.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +@Component("d") +public class DCmp extends NodeComponent { + + @Override + public void process() { + try { + Thread.sleep(4000); + }catch (Exception ignored){ + + } + System.out.println("DCmp executed!"); + } + +} diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ECmp.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ECmp.java new file mode 100644 index 000000000..0e18aee71 --- /dev/null +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ECmp.java @@ -0,0 +1,26 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.whenTimeOut.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +@Component("e") +public class ECmp extends NodeComponent { + + @Override + public void process() { + try { + Thread.sleep(4000); + }catch (Exception ignored){ + + } + System.out.println("ECmp executed!"); + } + +} diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/FCmp.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/FCmp.java new file mode 100644 index 000000000..fad1d2d66 --- /dev/null +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/FCmp.java @@ -0,0 +1,26 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.whenTimeOut.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +@Component("f") +public class FCmp extends NodeComponent { + + @Override + public void process() { + try { + Thread.sleep(4000); + }catch (Exception ignored){ + + } + System.out.println("FCmp executed!"); + } + +} diff --git a/liteflow-testcase-springboot/src/test/resources/whenTimeOut/application.properties b/liteflow-testcase-springboot/src/test/resources/whenTimeOut/application.properties deleted file mode 100644 index 0cd889306..000000000 --- a/liteflow-testcase-springboot/src/test/resources/whenTimeOut/application.properties +++ /dev/null @@ -1,2 +0,0 @@ -liteflow.rule-source=whenTimeOut/flow.xml -liteflow.when-max-wait-seconds=3 \ No newline at end of file diff --git a/liteflow-testcase-springboot/src/test/resources/whenTimeOut/application1.properties b/liteflow-testcase-springboot/src/test/resources/whenTimeOut/application1.properties new file mode 100644 index 000000000..05eb9ab0e --- /dev/null +++ b/liteflow-testcase-springboot/src/test/resources/whenTimeOut/application1.properties @@ -0,0 +1,2 @@ +liteflow.rule-source=whenTimeOut/flow1.xml +liteflow.when-max-wait-seconds=3 \ No newline at end of file diff --git a/liteflow-testcase-springboot/src/test/resources/whenTimeOut/application2.properties b/liteflow-testcase-springboot/src/test/resources/whenTimeOut/application2.properties new file mode 100644 index 000000000..b90ff9c36 --- /dev/null +++ b/liteflow-testcase-springboot/src/test/resources/whenTimeOut/application2.properties @@ -0,0 +1,2 @@ +liteflow.rule-source=whenTimeOut/flow2.xml +liteflow.when-max-wait-seconds=5 \ No newline at end of file diff --git a/liteflow-testcase-springboot/src/test/resources/whenTimeOut/flow.xml b/liteflow-testcase-springboot/src/test/resources/whenTimeOut/flow1.xml similarity index 65% rename from liteflow-testcase-springboot/src/test/resources/whenTimeOut/flow.xml rename to liteflow-testcase-springboot/src/test/resources/whenTimeOut/flow1.xml index 70e2312d7..657f64cc3 100644 --- a/liteflow-testcase-springboot/src/test/resources/whenTimeOut/flow.xml +++ b/liteflow-testcase-springboot/src/test/resources/whenTimeOut/flow1.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/liteflow-testcase-springboot/src/test/resources/whenTimeOut/flow2.xml b/liteflow-testcase-springboot/src/test/resources/whenTimeOut/flow2.xml new file mode 100644 index 000000000..6586ab0b8 --- /dev/null +++ b/liteflow-testcase-springboot/src/test/resources/whenTimeOut/flow2.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file