mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-15 04:22:09 +08:00
add poll test
This commit is contained in:
@@ -20,7 +20,7 @@ import java.util.List;
|
||||
|
||||
public interface RedisParserHelper {
|
||||
|
||||
LFLog LOG = LFLoggerManager.getLogger(FlowExecutor.class);
|
||||
LFLog LOG = LFLoggerManager.getLogger(RedisParserHelper.class);
|
||||
|
||||
String REDIS_URL_PATTERN = "redis://{}:{}";
|
||||
|
||||
|
||||
@@ -1,16 +1,22 @@
|
||||
package com.yomahub.liteflow.test.redis;
|
||||
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.core.FlowInitHook;
|
||||
import com.yomahub.liteflow.flow.FlowBus;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.parser.redis.vo.RedisParserVO;
|
||||
import com.yomahub.liteflow.property.LiteflowConfig;
|
||||
import com.yomahub.liteflow.property.LiteflowConfigGetter;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import com.yomahub.liteflow.spi.holder.SpiFactoryCleaner;
|
||||
import com.yomahub.liteflow.spring.ComponentScanner;
|
||||
import com.yomahub.liteflow.thread.ExecutorHelper;
|
||||
import com.yomahub.liteflow.util.JsonUtil;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.redisson.api.RMapCache;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
@@ -42,18 +48,18 @@ public class RedisWithXmlELPollSpringbootTest {
|
||||
public static void setUpBeforeClass() {
|
||||
jedis = new Jedis("localhost", 6379);
|
||||
jedis.select(1);
|
||||
jedis.hset("pollScriptKey", "s1:script:脚本s1:groovy", "defaultContext.setData(\"test1\",\"hello s1\");");
|
||||
jedis.hset("pollScriptKey", "s2:script:脚本s2:js", "defaultContext.setData(\"test2\",\"hello s2\");");
|
||||
jedis.hset("pollScriptKey", "s3:script:脚本s3", "defaultContext.setData(\"test3\",\"hello s3\");");
|
||||
jedis.hset("pollScriptKey", "s11:script:脚本s11:groovy", "defaultContext.setData(\"test11\",\"hello s11\");");
|
||||
jedis.hset("pollScriptKey", "s22:script:脚本s22:js", "defaultContext.setData(\"test22\",\"hello s22\");");
|
||||
jedis.hset("pollScriptKey", "s33:script:脚本s33", "defaultContext.setData(\"test33\",\"hello s33\");");
|
||||
|
||||
jedis.hset("pollChainKey", "chain1", "THEN(a, b, c);");
|
||||
jedis.hset("pollChainKey", "chain2", "THEN(a, b, c, s3);");
|
||||
jedis.hset("pollChainKey", "chain3", "THEN(a, b, c, s1, s2);");
|
||||
jedis.hset("pollChainKey", "chain11", "THEN(a, b, c);");
|
||||
jedis.hset("pollChainKey", "chain22", "THEN(a, b, c, s33);");
|
||||
jedis.hset("pollChainKey", "chain33", "THEN(a, b, c, s11, s22);");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPollWithXml() throws InterruptedException {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain11", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("a==>b==>c", response.getExecuteStepStr());
|
||||
|
||||
@@ -62,23 +68,42 @@ public class RedisWithXmlELPollSpringbootTest {
|
||||
changeXMLData();
|
||||
//重新加载规则 定时任务1分钟后开始第一次轮询 所以这里休眠1分钟
|
||||
Thread.sleep(65000);
|
||||
Assertions.assertEquals("a==>c==>b", flowExecutor.execute2Resp("chain1", "arg").getExecuteStepStr());
|
||||
Assertions.assertEquals("a==>c==>b", flowExecutor.execute2Resp("chain11", "arg").getExecuteStepStr());
|
||||
|
||||
//删除redis中规则
|
||||
deleteXMLData();
|
||||
//重新加载规则
|
||||
Thread.sleep(5000);
|
||||
response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
Thread.sleep(1000);
|
||||
response = flowExecutor.execute2Resp("chain11", "arg");
|
||||
Assertions.assertTrue(!response.isSuccess());
|
||||
response = flowExecutor.execute2Resp("chain2", "arg");
|
||||
response = flowExecutor.execute2Resp("chain22", "arg");
|
||||
Assertions.assertTrue(!response.isSuccess());
|
||||
|
||||
|
||||
//添加redis中规则
|
||||
addXMLData();
|
||||
//重新加载规则
|
||||
Thread.sleep(5000);
|
||||
Assertions.assertEquals("b==>c", flowExecutor.execute2Resp("chain4", "arg").getExecuteStepStr());
|
||||
Thread.sleep(1000);
|
||||
Assertions.assertEquals("b==>c", flowExecutor.execute2Resp("chain44", "arg").getExecuteStepStr());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPollWithScriptXml() throws InterruptedException {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain33", "arg");
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("hello s11", context.getData("test11"));
|
||||
Assertions.assertEquals("a==>b==>c==>s11[脚本s11]==>s22[脚本s22]", response.getExecuteStepStrWithoutTime());
|
||||
|
||||
//添加和删除脚本
|
||||
//重新加载脚本 定时任务1分钟后开始第一次轮询 所以这里休眠1分钟
|
||||
addAndDeleteScriptData();
|
||||
Thread.sleep(62000);
|
||||
//修改redis脚本
|
||||
changeScriptData();
|
||||
Thread.sleep(1000);
|
||||
context = flowExecutor.execute2Resp("chain33", "arg").getFirstContextBean();
|
||||
Assertions.assertEquals("hello s11 version2", context.getData("test11"));
|
||||
}
|
||||
|
||||
|
||||
@@ -88,7 +113,7 @@ public class RedisWithXmlELPollSpringbootTest {
|
||||
public void changeXMLData() {
|
||||
LiteflowConfig liteflowConfig = LiteflowConfigGetter.get();
|
||||
RedisParserVO redisParserVO = JsonUtil.parseObject(liteflowConfig.getRuleSourceExtData(), RedisParserVO.class);
|
||||
jedis.hset(redisParserVO.getChainKey(), "chain1", "THEN(a, c, b);");
|
||||
jedis.hset(redisParserVO.getChainKey(), "chain11", "THEN(a, c, b);");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,8 +122,8 @@ public class RedisWithXmlELPollSpringbootTest {
|
||||
public void deleteXMLData() {
|
||||
LiteflowConfig liteflowConfig = LiteflowConfigGetter.get();
|
||||
RedisParserVO redisParserVO = JsonUtil.parseObject(liteflowConfig.getRuleSourceExtData(), RedisParserVO.class);
|
||||
jedis.hdel(redisParserVO.getChainKey(), "chain1");
|
||||
jedis.hdel(redisParserVO.getChainKey(), "chain2");
|
||||
jedis.hdel(redisParserVO.getChainKey(), "chain11");
|
||||
jedis.hdel(redisParserVO.getChainKey(), "chain22");
|
||||
}
|
||||
|
||||
|
||||
@@ -108,7 +133,8 @@ public class RedisWithXmlELPollSpringbootTest {
|
||||
public void addXMLData() {
|
||||
LiteflowConfig liteflowConfig = LiteflowConfigGetter.get();
|
||||
RedisParserVO redisParserVO = JsonUtil.parseObject(liteflowConfig.getRuleSourceExtData(), RedisParserVO.class);
|
||||
jedis.hset(redisParserVO.getChainKey(), "chain4", "THEN(b, c);");
|
||||
jedis.hset(redisParserVO.getChainKey(), "chain33", "THEN(a, b, c, s11, s22);");
|
||||
jedis.hset(redisParserVO.getChainKey(), "chain44", "THEN(b, c);");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,6 +143,43 @@ public class RedisWithXmlELPollSpringbootTest {
|
||||
public void changeScriptData() {
|
||||
LiteflowConfig liteflowConfig = LiteflowConfigGetter.get();
|
||||
RedisParserVO redisParserVO = JsonUtil.parseObject(liteflowConfig.getRuleSourceExtData(), RedisParserVO.class);
|
||||
jedis.hset(redisParserVO.getScriptKey(), "s1:script:脚本s1:groovy", "defaultContext.setData(\"test1\",\"hello s1 version2\");");
|
||||
jedis.hset(redisParserVO.getScriptKey(), "s11:script:脚本s11:groovy", "defaultContext.setData(\"test11\",\"hello s11 version2\");");
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增和删除redisson中的chain
|
||||
*/
|
||||
public void addAndDeleteScriptData() {
|
||||
LiteflowConfig liteflowConfig = LiteflowConfigGetter.get();
|
||||
RedisParserVO redisParserVO = JsonUtil.parseObject(liteflowConfig.getRuleSourceExtData(), RedisParserVO.class);
|
||||
jedis.hdel(redisParserVO.getScriptKey(), "s33:script:脚本s33");
|
||||
jedis.hset(redisParserVO.getScriptKey(),"s55:script:脚本s55:groovy", "defaultContext.setData(\"test55\",\"hello s5\");");
|
||||
}
|
||||
|
||||
/* //为便于测试的redis内规则数据数据清空
|
||||
@Test
|
||||
public void testCleanData() {
|
||||
Set<String> scriptKey = jedis.hkeys("pollScriptKey");
|
||||
Set<String> chainKey = jedis.hkeys("pollChainKey");
|
||||
for (String key : scriptKey) {
|
||||
jedis.hdel("pollScriptKey", key);
|
||||
}
|
||||
for (String key : chainKey) {
|
||||
jedis.hdel("pollChainKey", key);
|
||||
}
|
||||
jedis.hkeys("pollChainKey").forEach(System.out::println);
|
||||
System.out.println(" ");
|
||||
jedis.hkeys("pollScriptKey").forEach(System.out::println);
|
||||
System.out.println("数据清空完成");
|
||||
}*/
|
||||
|
||||
@AfterAll
|
||||
public static void cleanScanCache() {
|
||||
ComponentScanner.cleanCache();
|
||||
FlowBus.cleanCache();
|
||||
ExecutorHelper.loadInstance().clearExecutorServiceMap();
|
||||
SpiFactoryCleaner.clean();
|
||||
LiteflowConfigGetter.clean();
|
||||
FlowInitHook.cleanHook();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
package com.yomahub.liteflow.test.redis;
|
||||
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.core.FlowInitHook;
|
||||
import com.yomahub.liteflow.flow.FlowBus;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.parser.redis.vo.RedisParserVO;
|
||||
import com.yomahub.liteflow.property.LiteflowConfig;
|
||||
import com.yomahub.liteflow.property.LiteflowConfigGetter;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import com.yomahub.liteflow.spi.holder.SpiFactoryCleaner;
|
||||
import com.yomahub.liteflow.spring.ComponentScanner;
|
||||
import com.yomahub.liteflow.thread.ExecutorHelper;
|
||||
import com.yomahub.liteflow.util.JsonUtil;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -98,6 +104,8 @@ public class RedisWithXmlELSubscribeSpringbootTest {
|
||||
Thread.sleep(50);
|
||||
context = flowExecutor.execute2Resp("chain3", "arg").getFirstContextBean();
|
||||
Assertions.assertEquals("hello s1 version2", context.getData("test1"));
|
||||
context = flowExecutor.execute2Resp("chain2", "arg").getFirstContextBean();
|
||||
Assertions.assertEquals("hello s3 version2", context.getData("test2"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -139,6 +147,7 @@ public class RedisWithXmlELSubscribeSpringbootTest {
|
||||
RedisParserVO redisParserVO = JsonUtil.parseObject(liteflowConfig.getRuleSourceExtData(), RedisParserVO.class);
|
||||
RMapCache<String, String> scriptKey = redissonClient.getMapCache(redisParserVO.getScriptKey());
|
||||
scriptKey.put("s1:script:脚本s1:groovy", "defaultContext.setData(\"test1\",\"hello s1 version2\");");
|
||||
scriptKey.put("s3:script:脚本s3", "defaultContext.setData(\"test2\",\"hello s3 version2\");");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,8 +157,36 @@ public class RedisWithXmlELSubscribeSpringbootTest {
|
||||
LiteflowConfig liteflowConfig = LiteflowConfigGetter.get();
|
||||
RedisParserVO redisParserVO = JsonUtil.parseObject(liteflowConfig.getRuleSourceExtData(), RedisParserVO.class);
|
||||
RMapCache<String, String> scriptKey = redissonClient.getMapCache(redisParserVO.getScriptKey());
|
||||
scriptKey.remove("s4:script:脚本s4");
|
||||
scriptKey.remove("s5:script:脚本s5:groovy");
|
||||
scriptKey.remove("s3:script:脚本s3");
|
||||
scriptKey.put("s5:script:脚本s5:groovy", "defaultContext.setData(\"test1\",\"hello s5\");");
|
||||
}
|
||||
|
||||
/* //为便于测试的redis内规则数据数据清空
|
||||
@Test
|
||||
public void testCleanData(){
|
||||
LiteflowConfig liteflowConfig = LiteflowConfigGetter.get();
|
||||
RedisParserVO redisParserVO = JsonUtil.parseObject(liteflowConfig.getRuleSourceExtData(), RedisParserVO.class);
|
||||
RMapCache<String, String> scriptKey = redissonClient.getMapCache(redisParserVO.getScriptKey());
|
||||
RMapCache<String, String> chainKey = redissonClient.getMapCache(redisParserVO.getChainKey());
|
||||
for (String key : chainKey.keySet()) {
|
||||
chainKey.remove(key);
|
||||
}
|
||||
for (String key : scriptKey.keySet()) {
|
||||
scriptKey.remove(key);
|
||||
}
|
||||
chainKey.keySet().forEach(System.out::println);
|
||||
System.out.println("");
|
||||
scriptKey.keySet().forEach(System.out::println);
|
||||
System.out.println("数据清空完成");
|
||||
}*/
|
||||
|
||||
@AfterAll
|
||||
public static void cleanScanCache() {
|
||||
ComponentScanner.cleanCache();
|
||||
FlowBus.cleanCache();
|
||||
ExecutorHelper.loadInstance().clearExecutorServiceMap();
|
||||
SpiFactoryCleaner.clean();
|
||||
LiteflowConfigGetter.clean();
|
||||
FlowInitHook.cleanHook();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user