补充测试用例

This commit is contained in:
bryan31
2022-03-08 01:14:20 +08:00
parent 7435a9742b
commit 7e41ee441d
17 changed files with 347 additions and 50 deletions

View File

@@ -0,0 +1,75 @@
package com.yomahub.liteflow.test.zookeeper;
import cn.hutool.core.io.resource.ResourceUtil;
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.property.LiteflowConfig;
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 java.nio.charset.Charset;
import java.util.concurrent.CountDownLatch;
/**
* springboot环境下的zk配置源功能测试
* ZK节点存储数据的格式为json文件
* @author zendwang
* @since 2.5.0
*/
public class ZkNodeWithJsonTest extends BaseTest {
private static final String ZK_NODE_PATH = "/lite-flow/flow";
private static TestingServer zkServer;
private static FlowExecutor flowExecutor;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
zkServer = new TestingServer(21810);
CountDownLatch latch = new CountDownLatch(1);
new Thread(() -> {
String data = ResourceUtil.readUtf8Str("zookeeper/flow.json");
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();
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("json:127.0.0.1:21810");
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
@Test
public void testZkNodeWithJson() {
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg");
Assert.assertTrue(response.isSuccess());
}
@AfterClass
public static void tearDown() throws Exception {
zkServer.stop();
}
}

View File

@@ -0,0 +1,75 @@
package com.yomahub.liteflow.test.zookeeper;
import cn.hutool.core.io.resource.ResourceUtil;
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.property.LiteflowConfig;
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 java.nio.charset.Charset;
import java.util.concurrent.CountDownLatch;
/**
* springboot环境下的zk配置源功能测试
* ZK节点存储数据的格式为xml文件
* @author zendwang
* @since 2.5.0
*/
public class ZkNodeWithXmlTest extends BaseTest {
private static final String ZK_NODE_PATH = "/lite-flow/flow";
private static TestingServer zkServer;
private static FlowExecutor flowExecutor;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
zkServer = new TestingServer(21810);
CountDownLatch latch = new CountDownLatch(1);
new Thread(() -> {
String data = ResourceUtil.readUtf8Str("zookeeper/flow.xml");
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();
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("xml:127.0.0.1:21810");
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
@Test
public void testZkNodeWithXml() {
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg");
Assert.assertTrue(response.isSuccess());
}
@AfterClass
public static void tearDown() throws Exception {
zkServer.stop();
}
}

View File

@@ -0,0 +1,75 @@
package com.yomahub.liteflow.test.zookeeper;
import cn.hutool.core.io.resource.ResourceUtil;
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.property.LiteflowConfig;
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 java.nio.charset.Charset;
import java.util.concurrent.CountDownLatch;
/**
* springboot环境下的zk配置源功能测试
* ZK节点存储数据的格式为yml文件
* @author zendwang
* @since 2.5.0
*/
public class ZkNodeWithYmlTest extends BaseTest {
private static final String ZK_NODE_PATH = "/lite-flow/flow";
private static TestingServer zkServer;
private static FlowExecutor flowExecutor;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
zkServer = new TestingServer(21810);
CountDownLatch latch = new CountDownLatch(1);
new Thread(() -> {
String data = ResourceUtil.readUtf8Str("zookeeper/flow.yml");
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();
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("yml:127.0.0.1:21810");
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
@Test
public void testZkNodeWithYml() {
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg");
Assert.assertTrue(response.isSuccess());
}
@AfterClass
public static void tearDown() throws Exception {
zkServer.stop();
}
}

View File

@@ -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.zookeeper.cmp;
import com.yomahub.liteflow.core.NodeComponent;
public class ACmp extends NodeComponent {
@Override
public void process() {
System.out.println("ACmp executed!");
}
}

View File

@@ -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.zookeeper.cmp;
import com.yomahub.liteflow.core.NodeComponent;
public class BCmp extends NodeComponent {
@Override
public void process() {
System.out.println("BCmp executed!");
}
}

View File

@@ -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.zookeeper.cmp;
import com.yomahub.liteflow.core.NodeComponent;
public class CCmp extends NodeComponent {
@Override
public void process() {
System.out.println("CCmp executed!");
}
}

View 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"}
]
}
]
}
}

View File

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

View File

@@ -0,0 +1,14 @@
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'

View File

@@ -1,5 +1,6 @@
package com.yomahub.liteflow.test.zookeeper; package com.yomahub.liteflow.test.zookeeper;
import cn.hutool.core.io.resource.ResourceUtil;
import com.yomahub.liteflow.core.FlowExecutor; import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.entity.data.DefaultSlot; import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse; import com.yomahub.liteflow.entity.data.LiteflowResponse;
@@ -48,7 +49,7 @@ public class ZkNodeWithJsonSpringbootTest extends BaseTest {
zkServer = new TestingServer(21810); zkServer = new TestingServer(21810);
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
new Thread(() -> { new Thread(() -> {
String data = "{\"flow\":{\"chain\":[{\"name\":\"chain1\",\"condition\":[{\"type\":\"then\",\"value\":\"a,b,c\"}]}]}}"; String data = ResourceUtil.readUtf8Str("zookeeper/flow.json");
ZkClient zkClient = new ZkClient("127.0.0.1:21810"); ZkClient zkClient = new ZkClient("127.0.0.1:21810");
zkClient.setZkSerializer(new ZkSerializer() { zkClient.setZkSerializer(new ZkSerializer() {
@Override @Override

View File

@@ -1,5 +1,6 @@
package com.yomahub.liteflow.test.zookeeper; package com.yomahub.liteflow.test.zookeeper;
import cn.hutool.core.io.resource.ResourceUtil;
import com.yomahub.liteflow.core.FlowExecutor; import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.entity.data.DefaultSlot; import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse; import com.yomahub.liteflow.entity.data.LiteflowResponse;
@@ -48,7 +49,7 @@ public class ZkNodeWithXmlSpringbootTest extends BaseTest {
zkServer = new TestingServer(21810); zkServer = new TestingServer(21810);
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
new Thread(() -> { new Thread(() -> {
String data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><flow><chain name=\"chain1\"><then value=\"a,b,c\"/></chain></flow>"; String data = ResourceUtil.readUtf8Str("zookeeper/flow.xml");
ZkClient zkClient = new ZkClient("127.0.0.1:21810"); ZkClient zkClient = new ZkClient("127.0.0.1:21810");
zkClient.setZkSerializer(new ZkSerializer() { zkClient.setZkSerializer(new ZkSerializer() {
@Override @Override

View File

@@ -1,5 +1,6 @@
package com.yomahub.liteflow.test.zookeeper; package com.yomahub.liteflow.test.zookeeper;
import cn.hutool.core.io.resource.ResourceUtil;
import com.yomahub.liteflow.core.FlowExecutor; import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.entity.data.DefaultSlot; import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse; import com.yomahub.liteflow.entity.data.LiteflowResponse;
@@ -48,13 +49,7 @@ public class ZkNodeWithYmlSpringbootTest extends BaseTest {
zkServer = new TestingServer(21810); zkServer = new TestingServer(21810);
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
new Thread(() -> { new Thread(() -> {
StringBuilder data = new StringBuilder() String data = ResourceUtil.readUtf8Str("zookeeper/flow.yml");
.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 zkClient = new ZkClient("127.0.0.1:21810");
zkClient.setZkSerializer(new ZkSerializer() { zkClient.setZkSerializer(new ZkSerializer() {
@Override @Override

View File

@@ -1,21 +1,5 @@
{ {
"flow": { "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": [ "chain": [
{ {
"name": "chain1", "name": "chain1",

View File

@@ -1,5 +1,6 @@
package com.yomahub.liteflow.test.zookeeper; package com.yomahub.liteflow.test.zookeeper;
import cn.hutool.core.io.resource.ResourceUtil;
import com.yomahub.liteflow.core.FlowExecutor; import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.entity.data.DefaultSlot; import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse; import com.yomahub.liteflow.entity.data.LiteflowResponse;
@@ -42,7 +43,7 @@ public class ZkNodeWithJsonSpringTest extends BaseTest {
zkServer = new TestingServer(21810); zkServer = new TestingServer(21810);
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
new Thread(() -> { new Thread(() -> {
String data = "{\"flow\":{\"chain\":[{\"name\":\"chain1\",\"condition\":[{\"type\":\"then\",\"value\":\"a,b,c\"}]}]}}"; String data = ResourceUtil.readUtf8Str("zookeeper/flow.json");
ZkClient zkClient = new ZkClient("127.0.0.1:21810"); ZkClient zkClient = new ZkClient("127.0.0.1:21810");
zkClient.setZkSerializer(new ZkSerializer() { zkClient.setZkSerializer(new ZkSerializer() {
@Override @Override

View File

@@ -1,5 +1,6 @@
package com.yomahub.liteflow.test.zookeeper; package com.yomahub.liteflow.test.zookeeper;
import cn.hutool.core.io.resource.ResourceUtil;
import com.yomahub.liteflow.core.FlowExecutor; import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.entity.data.DefaultSlot; import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse; import com.yomahub.liteflow.entity.data.LiteflowResponse;
@@ -42,7 +43,7 @@ public class ZkNodeWithXmlSpringTest extends BaseTest {
zkServer = new TestingServer(21810); zkServer = new TestingServer(21810);
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
new Thread(() -> { new Thread(() -> {
String data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><flow><chain name=\"chain1\"><then value=\"a,b,c\"/></chain></flow>"; String data = ResourceUtil.readUtf8Str("zookeeper/flow.xml");
ZkClient zkClient = new ZkClient("127.0.0.1:21810"); ZkClient zkClient = new ZkClient("127.0.0.1:21810");
zkClient.setZkSerializer(new ZkSerializer() { zkClient.setZkSerializer(new ZkSerializer() {
@Override @Override

View File

@@ -1,5 +1,6 @@
package com.yomahub.liteflow.test.zookeeper; package com.yomahub.liteflow.test.zookeeper;
import cn.hutool.core.io.resource.ResourceUtil;
import com.yomahub.liteflow.core.FlowExecutor; import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.entity.data.DefaultSlot; import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse; import com.yomahub.liteflow.entity.data.LiteflowResponse;
@@ -42,13 +43,7 @@ public class ZkNodeWithYmlSpringTest extends BaseTest {
zkServer = new TestingServer(21810); zkServer = new TestingServer(21810);
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
new Thread(() -> { new Thread(() -> {
StringBuilder data = new StringBuilder() String data = ResourceUtil.readUtf8Str("zookeeper/flow.yml");
.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 zkClient = new ZkClient("127.0.0.1:21810");
zkClient.setZkSerializer(new ZkSerializer() { zkClient.setZkSerializer(new ZkSerializer() {
@Override @Override

View File

@@ -1,21 +1,5 @@
{ {
"flow": { "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": [ "chain": [
{ {
"name": "chain1", "name": "chain1",