mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-06-12 09:41:04 +08:00
Merge remote-tracking branch 'origin/v2.5.0-SNAPSHOT' into v2.5.0-SNAPSHOT
This commit is contained in:
@@ -61,6 +61,7 @@
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.curator</groupId>
|
||||
@@ -84,5 +85,15 @@
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>transmittable-thread-local</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.curator</groupId>
|
||||
<artifactId>curator-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.101tec</groupId>
|
||||
<artifactId>zkclient</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -102,7 +102,6 @@ public class Chain implements Executable {
|
||||
}
|
||||
}
|
||||
} else if (condition instanceof WhenCondition) {
|
||||
|
||||
executeAsyncCondition((WhenCondition) condition, slotIndex, slot.getRequestId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ public abstract class YmlFlowParser extends JsonFlowParser{
|
||||
parse(ruleObject.toJSONString());
|
||||
}
|
||||
|
||||
private JSONObject convertToJson(String yamlString) {
|
||||
protected JSONObject convertToJson(String yamlString) {
|
||||
Yaml yaml= new Yaml();
|
||||
Map<String, Object> map = yaml.load(yamlString);
|
||||
JSONObject jsonObject = new JSONObject(map);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.yomahub.liteflow.parser;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.yomahub.liteflow.exception.ParseException;
|
||||
import org.apache.curator.framework.CuratorFramework;
|
||||
import org.apache.curator.framework.CuratorFrameworkFactory;
|
||||
@@ -45,12 +46,14 @@ public class ZookeeperYmlFlowParser extends YmlFlowParser{
|
||||
|
||||
String content = new String(client.getData().forPath(nodePath));
|
||||
|
||||
|
||||
if (StrUtil.isBlank(content)) {
|
||||
String error = MessageFormat.format("the node[{0}] value is empty", nodePath);
|
||||
throw new ParseException(error);
|
||||
}
|
||||
parse(content);
|
||||
|
||||
JSONObject ruleObject = convertToJson(content);
|
||||
|
||||
parse(ruleObject.toJSONString());
|
||||
|
||||
|
||||
final NodeCache cache = new NodeCache(client,nodePath);
|
||||
@@ -61,7 +64,8 @@ public class ZookeeperYmlFlowParser extends YmlFlowParser{
|
||||
public void nodeChanged() throws Exception {
|
||||
String content = new String(cache.getCurrentData().getData());
|
||||
LOG.info("stating load flow config....");
|
||||
parse(content);
|
||||
JSONObject ruleObject = convertToJson(content);
|
||||
parse(ruleObject.toJSONString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ public class LiteflowConfig {
|
||||
|
||||
public Integer getWhenQueueLimit() {
|
||||
if (ObjectUtil.isNull(whenQueueLimit)){
|
||||
return 512;
|
||||
return 100;
|
||||
}else{
|
||||
return whenQueueLimit;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class LiteflowConfigNoSpringTest extends BaseTest {
|
||||
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());
|
||||
Assert.assertEquals(100, config.getWhenQueueLimit().longValue());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -41,6 +41,6 @@ public class LiteflowConfigSpringTest extends BaseTest {
|
||||
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());
|
||||
Assert.assertEquals(100, config.getWhenQueueLimit().longValue());
|
||||
}
|
||||
}
|
||||
@@ -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.config.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!");
|
||||
}
|
||||
}
|
||||
@@ -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.config.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!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.config.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!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.yomahub.liteflow.test.zookeeper;
|
||||
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.entity.data.LiteflowResponse;
|
||||
import com.yomahub.liteflow.entity.data.Slot;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.I0Itec.zkclient.ZkClient;
|
||||
import org.I0Itec.zkclient.exception.ZkMarshallingError;
|
||||
import org.I0Itec.zkclient.serialize.ZkSerializer;
|
||||
import org.apache.curator.test.TestingServer;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
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;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
/**
|
||||
* spring环境下的zk配置源功能测试
|
||||
* ZK节点存储数据的格式为json文件
|
||||
* @author zendwang
|
||||
* @since 2.5.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration("classpath:/zookeeper/application-json.xml")
|
||||
public class ZkNodeWithJsonSpringTest extends BaseTest {
|
||||
|
||||
private static final String ZK_NODE_PATH = "/lite-flow/flow";
|
||||
|
||||
private static TestingServer zkServer;
|
||||
|
||||
@Resource
|
||||
private FlowExecutor flowExecutor;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
zkServer = new TestingServer(21810);
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
new Thread(() -> {
|
||||
String data = "{\"flow\":{\"chain\":[{\"name\":\"chain1\",\"condition\":[{\"type\":\"then\",\"value\":\"a,b,c\"}]}]}}";
|
||||
ZkClient zkClient = new ZkClient("127.0.0.1:21810");
|
||||
zkClient.setZkSerializer(new ZkSerializer() {
|
||||
@Override
|
||||
public byte[] serialize(final Object o) throws ZkMarshallingError {
|
||||
return o.toString().getBytes(Charset.forName("UTF-8"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object deserialize(final byte[] bytes) throws ZkMarshallingError {
|
||||
return new String(bytes, Charset.forName("UTF-8"));
|
||||
}
|
||||
});
|
||||
zkClient.createPersistent(ZK_NODE_PATH, true);
|
||||
zkClient.writeData(ZK_NODE_PATH, data);
|
||||
zkClient.close();
|
||||
latch.countDown();
|
||||
}).start();
|
||||
latch.await();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() throws Exception{
|
||||
LiteflowResponse<Slot> response = flowExecutor.execute("chain1", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertEquals("a==>b==>c", response.getData().printStep());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDown() throws Exception {
|
||||
zkServer.stop();
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.test.config;
|
||||
package com.yomahub.liteflow.test.zookeeper;
|
||||
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.entity.data.LiteflowResponse;
|
||||
@@ -22,12 +22,13 @@ import java.util.concurrent.CountDownLatch;
|
||||
|
||||
/**
|
||||
* spring环境下的zk配置源功能测试
|
||||
* ZK节点存储数据的格式为xml文件
|
||||
* @author zendwang
|
||||
* @since 2.5.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration("classpath:/config/application-zk.xml")
|
||||
public class ZkConfigSourceSpringtTest extends BaseTest {
|
||||
@ContextConfiguration("classpath:/zookeeper/application-xml.xml")
|
||||
public class ZkNodeWithXmlSpringTest extends BaseTest {
|
||||
|
||||
private static final String ZK_NODE_PATH = "/lite-flow/flow";
|
||||
|
||||
@@ -66,6 +67,7 @@ public class ZkConfigSourceSpringtTest extends BaseTest {
|
||||
public void test() throws Exception{
|
||||
LiteflowResponse<Slot> response = flowExecutor.execute("chain1", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertEquals("a==>b==>c", response.getData().printStep());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.yomahub.liteflow.test.zookeeper;
|
||||
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.entity.data.LiteflowResponse;
|
||||
import com.yomahub.liteflow.entity.data.Slot;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.I0Itec.zkclient.ZkClient;
|
||||
import org.I0Itec.zkclient.exception.ZkMarshallingError;
|
||||
import org.I0Itec.zkclient.serialize.ZkSerializer;
|
||||
import org.apache.curator.test.TestingServer;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
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;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
/**
|
||||
* spring环境下的zk配置源功能测试
|
||||
* ZK节点存储数据的格式为yml文件
|
||||
* @author zendwang
|
||||
* @since 2.5.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration("classpath:/zookeeper/application-yml.xml")
|
||||
public class ZkNodeWithYmlSpringTest extends BaseTest {
|
||||
|
||||
private static final String ZK_NODE_PATH = "/lite-flow/flow";
|
||||
|
||||
private static TestingServer zkServer;
|
||||
|
||||
@Resource
|
||||
private FlowExecutor flowExecutor;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
zkServer = new TestingServer(21810);
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
new Thread(() -> {
|
||||
StringBuilder data = new StringBuilder()
|
||||
.append("flow:\n")
|
||||
.append(" chain:\n")
|
||||
.append(" - name: chain1\n")
|
||||
.append(" condition:\n")
|
||||
.append(" - type: then\n")
|
||||
.append(" value: 'a,b,c'");
|
||||
ZkClient zkClient = new ZkClient("127.0.0.1:21810");
|
||||
zkClient.setZkSerializer(new ZkSerializer() {
|
||||
@Override
|
||||
public byte[] serialize(final Object o) throws ZkMarshallingError {
|
||||
return o.toString().getBytes(Charset.forName("UTF-8"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object deserialize(final byte[] bytes) throws ZkMarshallingError {
|
||||
return new String(bytes, Charset.forName("UTF-8"));
|
||||
}
|
||||
});
|
||||
zkClient.createPersistent(ZK_NODE_PATH, true);
|
||||
zkClient.writeData(ZK_NODE_PATH, data);
|
||||
zkClient.close();
|
||||
latch.countDown();
|
||||
}).start();
|
||||
latch.await();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() throws Exception{
|
||||
LiteflowResponse<Slot> response = flowExecutor.execute("chain1", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertEquals("a==>b==>c", response.getData().printStep());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDown() throws Exception {
|
||||
zkServer.stop();
|
||||
}
|
||||
}
|
||||
@@ -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.zookeeper.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!");
|
||||
}
|
||||
}
|
||||
@@ -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.zookeeper.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!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.zookeeper.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!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.zookeeper.cmp" />
|
||||
|
||||
<bean id="springAware" class="com.yomahub.liteflow.util.SpringAware"/>
|
||||
|
||||
<bean class="com.yomahub.liteflow.spring.ComponentScanner"/>
|
||||
|
||||
<bean id="liteflowConfig" class="com.yomahub.liteflow.property.LiteflowConfig">
|
||||
<property name="ruleSource" value="json:127.0.0.1:21810"/>
|
||||
</bean>
|
||||
|
||||
<bean id="flowExecutor" class="com.yomahub.liteflow.core.FlowExecutor">
|
||||
<property name="liteflowConfig" ref="liteflowConfig"/>
|
||||
</bean>
|
||||
</beans>
|
||||
@@ -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.config.cmp" />
|
||||
<context:component-scan base-package="com.yomahub.liteflow.test.zookeeper.cmp" />
|
||||
|
||||
<bean id="springAware" class="com.yomahub.liteflow.util.SpringAware"/>
|
||||
|
||||
@@ -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.zookeeper.cmp" />
|
||||
|
||||
<bean id="springAware" class="com.yomahub.liteflow.util.SpringAware"/>
|
||||
|
||||
<bean class="com.yomahub.liteflow.spring.ComponentScanner"/>
|
||||
|
||||
<bean id="liteflowConfig" class="com.yomahub.liteflow.property.LiteflowConfig">
|
||||
<property name="ruleSource" value="yml:127.0.0.1:21810"/>
|
||||
</bean>
|
||||
|
||||
<bean id="flowExecutor" class="com.yomahub.liteflow.core.FlowExecutor">
|
||||
<property name="liteflowConfig" ref="liteflowConfig"/>
|
||||
</bean>
|
||||
</beans>
|
||||
28
liteflow-core/src/test/resources/zookeeper/flow.json
Normal file
28
liteflow-core/src/test/resources/zookeeper/flow.json
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"flow": {
|
||||
"nodes": {
|
||||
"node": [
|
||||
{
|
||||
"id": "a",
|
||||
"class": "com.yomahub.liteflow.test.zookeeper.cmp.ACmp"
|
||||
},
|
||||
{
|
||||
"id": "b",
|
||||
"class": "com.yomahub.liteflow.test.zookeeper.cmp.BCmp"
|
||||
},
|
||||
{
|
||||
"id": "c",
|
||||
"class": "com.yomahub.liteflow.test.zookeeper.cmp.CCmp"
|
||||
}
|
||||
]
|
||||
},
|
||||
"chain": [
|
||||
{
|
||||
"name": "chain1",
|
||||
"condition": [
|
||||
{"type": "then", "value": "a,b,c"}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
6
liteflow-core/src/test/resources/zookeeper/flow.yml
Normal file
6
liteflow-core/src/test/resources/zookeeper/flow.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
flow:
|
||||
chain:
|
||||
- name: chain1
|
||||
condition:
|
||||
- type: then
|
||||
value: 'a,b,c'
|
||||
@@ -29,8 +29,6 @@
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<version>${springboot.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
@@ -46,13 +44,11 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.curator</groupId>
|
||||
<artifactId>curator-test</artifactId>
|
||||
<version>5.1.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.101tec</groupId>
|
||||
<artifactId>zkclient</artifactId>
|
||||
<version>0.10</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.yomahub.liteflow.test.zookeeper;
|
||||
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.entity.data.LiteflowResponse;
|
||||
import com.yomahub.liteflow.entity.data.Slot;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.I0Itec.zkclient.ZkClient;
|
||||
import org.I0Itec.zkclient.exception.ZkMarshallingError;
|
||||
import org.I0Itec.zkclient.serialize.ZkSerializer;
|
||||
import org.apache.curator.test.TestingServer;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
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;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
/**
|
||||
* springboot环境下的zk配置源功能测试
|
||||
* ZK节点存储数据的格式为json文件
|
||||
* @author zendwang
|
||||
* @since 2.5.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@TestPropertySource(value = "classpath:/zookeeper/application-json.properties")
|
||||
@SpringBootTest(classes = ZkNodeWithJsonSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan({"com.yomahub.liteflow.test.zookeeper.cmp"})
|
||||
public class ZkNodeWithJsonSpringbootTest extends BaseTest {
|
||||
|
||||
private static final String ZK_NODE_PATH = "/lite-flow/flow";
|
||||
|
||||
private static TestingServer zkServer;
|
||||
|
||||
@Resource
|
||||
private FlowExecutor flowExecutor;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
zkServer = new TestingServer(21810);
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
new Thread(() -> {
|
||||
String data = "{\"flow\":{\"chain\":[{\"name\":\"chain1\",\"condition\":[{\"type\":\"then\",\"value\":\"a,b,c\"}]}]}}";
|
||||
ZkClient zkClient = new ZkClient("127.0.0.1:21810");
|
||||
zkClient.setZkSerializer(new ZkSerializer() {
|
||||
@Override
|
||||
public byte[] serialize(final Object o) throws ZkMarshallingError {
|
||||
return o.toString().getBytes(Charset.forName("UTF-8"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object deserialize(final byte[] bytes) throws ZkMarshallingError {
|
||||
return new String(bytes, Charset.forName("UTF-8"));
|
||||
}
|
||||
});
|
||||
zkClient.createPersistent(ZK_NODE_PATH, true);
|
||||
zkClient.writeData(ZK_NODE_PATH, data);
|
||||
zkClient.close();
|
||||
latch.countDown();
|
||||
}).start();
|
||||
latch.await();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
LiteflowResponse<Slot> response = flowExecutor.execute("chain1", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDown() throws Exception {
|
||||
zkServer.stop();
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.test.config;
|
||||
package com.yomahub.liteflow.test.zookeeper;
|
||||
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.entity.data.LiteflowResponse;
|
||||
@@ -25,15 +25,16 @@ import java.util.concurrent.CountDownLatch;
|
||||
|
||||
/**
|
||||
* springboot环境下的zk配置源功能测试
|
||||
* ZK节点存储数据的格式为xml文件
|
||||
* @author zendwang
|
||||
* @since 2.5.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@TestPropertySource(value = "classpath:/config/application-zk.properties")
|
||||
@SpringBootTest(classes = ZkConfigSourceSpringbootTest.class)
|
||||
@TestPropertySource(value = "classpath:/zookeeper/application-xml.properties")
|
||||
@SpringBootTest(classes = ZkNodeWithXmlSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan({"com.yomahub.liteflow.test.config.cmp"})
|
||||
public class ZkConfigSourceSpringbootTest extends BaseTest {
|
||||
@ComponentScan({"com.yomahub.liteflow.test.zookeeper.cmp"})
|
||||
public class ZkNodeWithXmlSpringbootTest extends BaseTest {
|
||||
|
||||
private static final String ZK_NODE_PATH = "/lite-flow/flow";
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.yomahub.liteflow.test.zookeeper;
|
||||
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.entity.data.LiteflowResponse;
|
||||
import com.yomahub.liteflow.entity.data.Slot;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.I0Itec.zkclient.ZkClient;
|
||||
import org.I0Itec.zkclient.exception.ZkMarshallingError;
|
||||
import org.I0Itec.zkclient.serialize.ZkSerializer;
|
||||
import org.apache.curator.test.TestingServer;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
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;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
/**
|
||||
* springboot环境下的zk配置源功能测试
|
||||
* ZK节点存储数据的格式为yml文件
|
||||
* @author zendwang
|
||||
* @since 2.5.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@TestPropertySource(value = "classpath:/zookeeper/application-yml.properties")
|
||||
@SpringBootTest(classes = ZkNodeWithYmlSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan({"com.yomahub.liteflow.test.zookeeper.cmp"})
|
||||
public class ZkNodeWithYmlSpringbootTest extends BaseTest {
|
||||
|
||||
private static final String ZK_NODE_PATH = "/lite-flow/flow";
|
||||
|
||||
private static TestingServer zkServer;
|
||||
|
||||
@Resource
|
||||
private FlowExecutor flowExecutor;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
zkServer = new TestingServer(21810);
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
new Thread(() -> {
|
||||
StringBuilder data = new StringBuilder()
|
||||
.append("flow:\n")
|
||||
.append(" chain:\n")
|
||||
.append(" - name: chain1\n")
|
||||
.append(" condition:\n")
|
||||
.append(" - type: then\n")
|
||||
.append(" value: 'a,b,c'");
|
||||
ZkClient zkClient = new ZkClient("127.0.0.1:21810");
|
||||
zkClient.setZkSerializer(new ZkSerializer() {
|
||||
@Override
|
||||
public byte[] serialize(final Object o) throws ZkMarshallingError {
|
||||
return o.toString().getBytes(Charset.forName("UTF-8"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object deserialize(final byte[] bytes) throws ZkMarshallingError {
|
||||
return new String(bytes, Charset.forName("UTF-8"));
|
||||
}
|
||||
});
|
||||
zkClient.createPersistent(ZK_NODE_PATH, true);
|
||||
zkClient.writeData(ZK_NODE_PATH, data);
|
||||
zkClient.close();
|
||||
latch.countDown();
|
||||
}).start();
|
||||
latch.await();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
LiteflowResponse<Slot> response = flowExecutor.execute("chain1", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDown() throws Exception {
|
||||
zkServer.stop();
|
||||
}
|
||||
}
|
||||
@@ -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.zookeeper.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!");
|
||||
}
|
||||
}
|
||||
@@ -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.zookeeper.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!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.zookeeper.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!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -37,23 +37,23 @@
|
||||
- [x] Yml方式在spring环境下测试
|
||||
- [] Yml方式在springboot环境下测试
|
||||
|
||||
- [ ] 参数测试(只测到参数是不是被总的LiteFlowConfig加载到即可)
|
||||
- [ ] 非spring环境下的参数测试,必要参数测试,非必须参数的默认值测试。
|
||||
- [ ] spring环境下的参数测试,必要参数测试,非必须参数的默认值测试。
|
||||
- [ ] springboot环境下的参数测试,必要参数测试,非必须参数的默认值测试。
|
||||
- [ ] zk配置源的功能测试(zk请自己本地安装提供)
|
||||
- [ ] spring环境下的zk配置源功能测试
|
||||
- [ ] springboot环境下的zk配置源功能测试
|
||||
- [ ] 自定义源的功能测试
|
||||
- [ ] spring环境下的自定义配置源功能测试
|
||||
- [ ] springboot环境下的自定义配置源功能测试
|
||||
- [ ] 组件功能点测试(基于springboot环境即可)
|
||||
- [ ] isAccess方法的功能测试
|
||||
- [ ] 组件抛错的功能点测试
|
||||
- [ ] isContinueOnError方法的功能点测试
|
||||
- [ ] isEnd方法和this.setIsEnd(true)的功能点测试
|
||||
- [ ] 条件组件功能点测试(基于springboot环境)
|
||||
- [ ] 条件组件的功能点测试
|
||||
- [x] 参数测试(只测到参数是不是被总的LiteFlowConfig加载到即可)
|
||||
- [x] 非spring环境下的参数测试,必要参数测试,非必须参数的默认值测试。
|
||||
- [x] spring环境下的参数测试,必要参数测试,非必须参数的默认值测试。
|
||||
- [x] springboot环境下的参数测试,必要参数测试,非必须参数的默认值测试。
|
||||
- [x] zk配置源的功能测试(zk请自己本地安装提供)
|
||||
- [x] spring环境下的zk配置源功能测试
|
||||
- [x] springboot环境下的zk配置源功能测试
|
||||
- [x] 自定义源的功能测试
|
||||
- [x] spring环境下的自定义配置源功能测试
|
||||
- [x] springboot环境下的自定义配置源功能测试
|
||||
- [x] 组件功能点测试(基于springboot环境即可)
|
||||
- [x] isAccess方法的功能测试
|
||||
- [x] 组件抛错的功能点测试
|
||||
- [x] isContinueOnError方法的功能点测试
|
||||
- [x] isEnd方法和this.setIsEnd(true)的功能点测试
|
||||
- [x] 条件组件功能点测试(基于springboot环境)
|
||||
- [x] 条件组件的功能点测试
|
||||
- [x] 显式子流程测试(基于springboot环境)
|
||||
- [x] 子流程功能点测试,是否能进入子流程
|
||||
- [x] 多个子流程是否能串联衔接
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
liteflow.rule-source=json:127.0.0.1:21810
|
||||
@@ -0,0 +1 @@
|
||||
liteflow.rule-source=yml:127.0.0.1:21810
|
||||
@@ -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"}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<flow>
|
||||
<chain name="chain1">
|
||||
<then value="a,b,c"/>
|
||||
</chain>
|
||||
</flow>
|
||||
@@ -0,0 +1,6 @@
|
||||
flow:
|
||||
chain:
|
||||
- name: chain1
|
||||
condition:
|
||||
- type: then
|
||||
value: 'a,b,c'
|
||||
12
pom.xml
12
pom.xml
@@ -54,6 +54,8 @@
|
||||
<junit.version>4.12</junit.version>
|
||||
<hutool-core.version>5.3.10</hutool-core.version>
|
||||
<transmittable-thread-local.version>2.12.1</transmittable-thread-local.version>
|
||||
<curator-test.version>5.1.0</curator-test.version>
|
||||
<zkclient.version>0.10</zkclient.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
@@ -138,6 +140,16 @@
|
||||
<artifactId>transmittable-thread-local</artifactId>
|
||||
<version>${transmittable-thread-local.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.curator</groupId>
|
||||
<artifactId>curator-test</artifactId>
|
||||
<version>${curator-test.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.101tec</groupId>
|
||||
<artifactId>zkclient</artifactId>
|
||||
<version>${zkclient.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user