mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 20:22:07 +08:00
fix test
This commit is contained in:
@@ -102,7 +102,7 @@ public class RedisParserPollingMode implements RedisParserHelper {
|
||||
}
|
||||
//创建定时任务线程池
|
||||
if (ObjectUtil.isNull(pollExecutor)) {
|
||||
ThreadFactory namedThreadFactory = new NamedThreadFactory("RedisParser-Polling-Thread-", false);
|
||||
ThreadFactory namedThreadFactory = new NamedThreadFactory("Redis-Polling-", false);
|
||||
pollExecutor = new ScheduledThreadPoolExecutor(
|
||||
CORE_POOL_SIZE,
|
||||
namedThreadFactory,
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.yomahub.liteflow.test.redis;
|
||||
|
||||
import org.redisson.Redisson;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.redisson.api.redisnode.RedisNodes;
|
||||
import org.redisson.api.redisnode.RedisSingle;
|
||||
import org.redisson.config.Config;
|
||||
|
||||
/**
|
||||
* 判断本地是否启动Redis
|
||||
*
|
||||
* @author hxinyu
|
||||
* @since 2.11.0
|
||||
*/
|
||||
public class RedisSubscribeTestCondition {
|
||||
|
||||
/* 若6379端口未启动Redis则返回true */
|
||||
public static boolean notStartRedis() {
|
||||
try{
|
||||
Config config = new Config();
|
||||
config.useSingleServer().setAddress("redis://127.0.0.1:6379");
|
||||
RedissonClient redissonClient = Redisson.create(config);
|
||||
RedisSingle redisNode = redissonClient.getRedisNodes(RedisNodes.SINGLE);
|
||||
return !redisNode.pingAll();
|
||||
} catch (Exception e) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,16 @@ package com.yomahub.liteflow.test.redis;
|
||||
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
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.mode.RClient;
|
||||
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.test.BaseTest;
|
||||
import com.yomahub.liteflow.thread.ExecutorHelper;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
@@ -58,9 +63,13 @@ public class RedisWithXmlELPollSpringbootTest extends BaseTest {
|
||||
"local sha1 = redis.sha1hex(value);\n" +
|
||||
"return sha1;";
|
||||
|
||||
|
||||
@AfterEach
|
||||
public void after() {
|
||||
FlowBus.cleanCache();
|
||||
FlowInitHook.cleanHook();
|
||||
ExecutorHelper.loadInstance().clearExecutorServiceMap();
|
||||
SpiFactoryCleaner.clean();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,7 +103,7 @@ public class RedisWithXmlELPollSpringbootTest extends BaseTest {
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("a==>b==>c", response.getExecuteStepStr());
|
||||
|
||||
Thread.sleep(2000);
|
||||
Thread.sleep(4000);
|
||||
|
||||
//测试修改后的chain
|
||||
response = flowExecutor.execute2Resp("chain11", "arg");
|
||||
@@ -106,10 +115,10 @@ public class RedisWithXmlELPollSpringbootTest extends BaseTest {
|
||||
* 测试script
|
||||
*/
|
||||
@Test
|
||||
public void testPollWithScriptXml() throws InterruptedException {
|
||||
public void testPollWithScript() throws InterruptedException {
|
||||
Set<String> chainNameSet = new HashSet<>();
|
||||
chainNameSet.add("chain22");
|
||||
String chainValue = "THEN(a, b, c, s11, s22, s33);";
|
||||
String chainValue = "THEN(s11, s22, s33, a, b);";
|
||||
when(chainClient.hkeys("pollChainKey")).thenReturn(chainNameSet);
|
||||
when(chainClient.hget("pollChainKey", "chain22")).thenReturn(chainValue);
|
||||
when(chainClient.scriptLoad(luaOfKey)).thenReturn("keysha");
|
||||
@@ -150,9 +159,9 @@ public class RedisWithXmlELPollSpringbootTest extends BaseTest {
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("hello s11", context.getData("test11"));
|
||||
Assertions.assertEquals("hello s22", context.getData("test22"));
|
||||
Assertions.assertEquals("a==>b==>c==>s11[脚本s11]==>s22[脚本s22]==>s33[脚本s33]", response.getExecuteStepStrWithoutTime());
|
||||
Assertions.assertEquals("s11[脚本s11]==>s22[脚本s22]==>s33[脚本s33]==>a==>b", response.getExecuteStepStrWithoutTime());
|
||||
|
||||
Thread.sleep(2000);
|
||||
Thread.sleep(4000);
|
||||
|
||||
//测试修改后的script
|
||||
response = flowExecutor.execute2Resp("chain22", "arg");
|
||||
|
||||
@@ -31,9 +31,12 @@ import javax.annotation.Resource;
|
||||
/**
|
||||
* springboot环境下的redis配置源订阅模式功能测试
|
||||
*
|
||||
* 由于redisson中RMapCache监听器功能无法mock测试
|
||||
* 由于Redisson中RMapCache的监听器功能无法mock测试
|
||||
* 故Sub模式测试用例需本地启动Redis服务 连接地址: 127.0.0.1:6379
|
||||
* 若本地该端口号未启动Redis服务 则自动忽略本类中测试用例
|
||||
* 若本地该端口号未启动Redis 则自动忽略本类中测试用例
|
||||
*
|
||||
* 测试用例会在1号database中添加测试数据 chainKey:testChainKey; scriptKey:testScriptKey
|
||||
* 测试完成后清除测试数据
|
||||
*
|
||||
* @author hxinyu
|
||||
* @since 2.11.0
|
||||
@@ -56,8 +59,8 @@ public class RedisWithXmlELSubscribeSpringbootTest extends BaseTest {
|
||||
Config config = new Config();
|
||||
config.useSingleServer().setAddress("redis://127.0.0.1:6379").setDatabase(1);
|
||||
redissonClient = Redisson.create(config);
|
||||
RMapCache<String, String> chainKey = redissonClient.getMapCache("chainKey");
|
||||
RMapCache<String, String> scriptKey = redissonClient.getMapCache("scriptKey");
|
||||
RMapCache<String, String> chainKey = redissonClient.getMapCache("testChainKey");
|
||||
RMapCache<String, String> scriptKey = redissonClient.getMapCache("testScriptKey");
|
||||
scriptKey.put("s1:script:脚本s1:groovy", "defaultContext.setData(\"test1\",\"hello s1\");");
|
||||
scriptKey.put("s2:script:脚本s2:js", "defaultContext.setData(\"test2\",\"hello s2\");");
|
||||
scriptKey.put("s3:script:脚本s3", "defaultContext.setData(\"test3\",\"hello s3\");");
|
||||
@@ -68,7 +71,6 @@ public class RedisWithXmlELSubscribeSpringbootTest extends BaseTest {
|
||||
|
||||
@AfterAll
|
||||
public static void after(){
|
||||
System.out.println("after");
|
||||
testCleanData();
|
||||
}
|
||||
|
||||
@@ -179,17 +181,16 @@ public class RedisWithXmlELSubscribeSpringbootTest extends BaseTest {
|
||||
//redis内规则数据数据清空
|
||||
public static void testCleanData(){
|
||||
if(ObjectUtil.isNotNull(redissonClient)){
|
||||
RMapCache<String, String> scriptKey = redissonClient.getMapCache("chainKey");
|
||||
RMapCache<String, String> chainKey = redissonClient.getMapCache("scriptKey");
|
||||
RMapCache<String, String> chainKey = redissonClient.getMapCache("testChainKey");
|
||||
RMapCache<String, String> scriptKey = redissonClient.getMapCache("testScriptKey");
|
||||
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);
|
||||
chainKey.delete();
|
||||
scriptKey.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
liteflow.rule-source-ext-data={\
|
||||
"host":"localhost",\
|
||||
"port":6379,\
|
||||
"pollingInterval":1,\
|
||||
"pollingStartTime":1,\
|
||||
"pollingInterval":2,\
|
||||
"pollingStartTime":2,\
|
||||
"chainDataBase":1,\
|
||||
"chainKey":"pollChainKey",\
|
||||
"scriptDataBase":1,\
|
||||
|
||||
@@ -3,8 +3,8 @@ liteflow.rule-source-ext-data={\
|
||||
"port":6379,\
|
||||
"mode":"sub",\
|
||||
"chainDataBase":1,\
|
||||
"chainKey":"chainKey",\
|
||||
"chainKey":"testChainKey",\
|
||||
"scriptDataBase":1,\
|
||||
"scriptKey":"scriptKey"\
|
||||
"scriptKey":"testScriptKey"\
|
||||
}
|
||||
liteflow.parse-on-start=false
|
||||
Reference in New Issue
Block a user