新增部分单元测试

This commit is contained in:
zendwang
2021-04-07 06:08:27 +08:00
parent 2992491e49
commit 0aec022ad8
16 changed files with 145 additions and 32 deletions

View File

@@ -1,7 +1,46 @@
package com.yomahub.liteflow.test.config;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.entity.data.Slot;
import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
@ContextConfiguration("classpath:/parser/application-json.xml")
public class LiteflowConfigSpringTest {
import javax.annotation.Resource;
/**
* spring环境下参数单元测试
* @author zendwang
* @since 2.5.0
*/
@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:/config/application-local.xml")
public class LiteflowConfigSpringTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
@Autowired
private ApplicationContext context;
@Test
public void testConfig() throws Exception {
LiteflowConfig config = context.getBean(LiteflowConfig.class);
LiteflowResponse<Slot> response = flowExecutor.execute("chain1", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("config/flow.json", config.getRuleSource());
Assert.assertEquals(15, config.getWhenMaxWaitSeconds().intValue());
Assert.assertEquals(200, config.getQueueLimit().intValue());
Assert.assertEquals(300000L, config.getDelay().longValue());
Assert.assertEquals(300000L, config.getPeriod().longValue());
Assert.assertFalse(config.getEnableLog());
Assert.assertEquals(Runtime.getRuntime().availableProcessors() * 2, config.getWhenMaxWorkers().longValue());
Assert.assertEquals(512, config.getWhenQueueLimit().longValue());
}
}

View File

@@ -1,4 +1,52 @@
package com.yomahub.liteflow.test.config;
public class LiteflowConfigSpringbootTest {
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.entity.data.Slot;
import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
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 zendwang
* @since 2.5.0
*/
@RunWith(SpringRunner.class)
@TestPropertySource(value = "classpath:/config/application-local.properties")
@SpringBootTest(classes = LiteflowConfigSpringbootTest.class)
@EnableAutoConfiguration
@ComponentScan({"com.yomahub.liteflow.test.config.cmp"})
public class LiteflowConfigSpringbootTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
@Autowired
private ApplicationContext context;
@Test
public void testConfig() throws Exception {
LiteflowConfig config = context.getBean(LiteflowConfig.class);
LiteflowResponse<Slot> response = flowExecutor.execute("chain1", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("config/flow.yml", config.getRuleSource());
Assert.assertEquals(15, config.getWhenMaxWaitSeconds().intValue());
Assert.assertEquals(200, config.getQueueLimit().intValue());
Assert.assertEquals(300000L, config.getDelay().longValue());
Assert.assertEquals(300000L, config.getPeriod().longValue());
Assert.assertFalse(config.getEnableLog());
Assert.assertEquals(4, config.getWhenMaxWorkers().longValue());
Assert.assertEquals(512, config.getWhenQueueLimit().longValue());
}
}

View File

@@ -1,4 +1,4 @@
package com.yomahub.liteflow.test.configsource;
package com.yomahub.liteflow.test.config;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
@@ -29,10 +29,10 @@ import java.util.concurrent.CountDownLatch;
* @since 2.5.0
*/
@RunWith(SpringRunner.class)
@TestPropertySource(value = "classpath:/configsource/application-zk.properties")
@TestPropertySource(value = "classpath:/config/application-zk.properties")
@SpringBootTest(classes = ZkConfigSourceSpringbootTest.class)
@EnableAutoConfiguration
@ComponentScan({"com.yomahub.liteflow.test.configsource.cmp"})
@ComponentScan({"com.yomahub.liteflow.test.config.cmp"})
public class ZkConfigSourceSpringbootTest extends BaseTest {
private static final String ZK_NODE_PATH = "/lite-flow/flow";

View File

@@ -1,4 +1,4 @@
package com.yomahub.liteflow.test.configsource;
package com.yomahub.liteflow.test.config;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
@@ -26,7 +26,7 @@ import java.util.concurrent.CountDownLatch;
* @since 2.5.0
*/
@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:/configsource/application-zk.xml")
@ContextConfiguration("classpath:/config/application-zk.xml")
public class ZkConfigSourceSpringtTest extends BaseTest {
private static final String ZK_NODE_PATH = "/lite-flow/flow";

View File

@@ -5,7 +5,7 @@
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.configsource.cmp;
package com.yomahub.liteflow.test.config.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;

View File

@@ -5,7 +5,7 @@
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.configsource.cmp;
package com.yomahub.liteflow.test.config.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;

View File

@@ -5,7 +5,7 @@
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.configsource.cmp;
package com.yomahub.liteflow.test.config.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;

View File

@@ -6,7 +6,6 @@ import com.yomahub.liteflow.exception.ChainNotFoundException;
import com.yomahub.liteflow.exception.ConfigErrorException;
import com.yomahub.liteflow.exception.FlowExecutorNotInitException;
import com.yomahub.liteflow.exception.FlowSystemException;
import com.yomahub.liteflow.exception.WhenExecuteException;
import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.Assert;
@@ -31,10 +30,10 @@ import javax.annotation.Resource;
*/
@RunWith(SpringRunner.class)
@TestPropertySource(value = "classpath:/exception/application.properties")
@SpringBootTest(classes = FlowExecutorTest.class)
@SpringBootTest(classes = FlowExecutorSpringBootTest.class)
@EnableAutoConfiguration
@ComponentScan({"com.yomahub.liteflow.test.exception.cmp1", "com.yomahub.liteflow.test.exception.cmp2"})
public class FlowExecutorTest extends BaseTest {
@ComponentScan({"com.yomahub.liteflow.test.exception.cmp1"})
public class FlowExecutorSpringBootTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
@@ -77,10 +76,10 @@ public class FlowExecutorTest extends BaseTest {
ReflectionUtils.rethrowException(response.getCause());
}
@Test(expected = WhenExecuteException.class)
public void testWhenExecuteTimeoutException() throws Exception {
LiteflowResponse response = flowExecutor.execute("chain3", "when");
Assert.assertFalse(response.isSuccess());
ReflectionUtils.rethrowException(response.getCause());
}
// @Test(expected = WhenExecuteException.class)
// public void testWhenExecuteTimeoutException() throws Exception {
// LiteflowResponse response = flowExecutor.execute("chain3", "when");
// Assert.assertFalse(response.isSuccess());
// ReflectionUtils.rethrowException(response.getCause());
// }
}

View File

@@ -0,0 +1 @@
liteflow.rule-source=config/flow.yml

View File

@@ -7,7 +7,7 @@
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.configsource.cmp" />
<context:component-scan base-package="com.yomahub.liteflow.test.config.cmp" />
<bean id="springAware" class="com.yomahub.liteflow.util.SpringAware"/>

View File

@@ -1,9 +0,0 @@
liteflow.rule-source=config/flow.xml
liteflow.slot-size=1024
liteflow.when-max-wait-seconds=15
liteflow.when-max-workers=4
liteflow.when-queue-limit=512
liteflow.monitor.enable-log=false
liteflow.monitor.queue-limit=200
liteflow.monitor.delay=300000
liteflow.monitor.period=300000

View File

@@ -0,0 +1,28 @@
{
"flow": {
"nodes": {
"node": [
{
"id": "a",
"class": "com.yomahub.liteflow.test.config.cmp.ACmp"
},
{
"id": "b",
"class": "com.yomahub.liteflow.test.config.cmp.BCmp"
},
{
"id": "c",
"class": "com.yomahub.liteflow.test.config.cmp.CCmp"
}
]
},
"chain": [
{
"name": "chain1",
"condition": [
{"type": "then", "value": "a,b,c"}
]
}
]
}
}

View File

@@ -0,0 +1,6 @@
flow:
chain:
- name: chain1
condition:
- type: then
value: 'a,b,c'

View File

@@ -1 +1,2 @@
liteflow.rule-source=exception/flow.xml
liteflow.rule-source=exception/flow.xml
liteflow.when-max-wait-seconds=1