feature #IAY66T 修改配置项名称

This commit is contained in:
DaleLee
2025-07-26 23:25:09 +08:00
parent f062ada31b
commit 7714ddf37e
38 changed files with 166 additions and 153 deletions

View File

@@ -23,7 +23,7 @@ import com.yomahub.liteflow.exception.*;
import com.yomahub.liteflow.flow.FlowBus;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.lifecycle.PostProcessChainExecuteLifeCycle;
import com.yomahub.liteflow.lifecycle.impl.RuleCacheLifeCycle;
import com.yomahub.liteflow.lifecycle.impl.ChainCacheLifeCycle;
import com.yomahub.liteflow.flow.element.Chain;
import com.yomahub.liteflow.flow.element.Node;
import com.yomahub.liteflow.flow.element.Rollbackable;
@@ -106,9 +106,9 @@ public class FlowExecutor {
}
// 规则缓存
if (isStart && liteflowConfig.getRuleCacheEnabled()) {
if (isStart && liteflowConfig.getChainCacheEnabled()) {
// 放到解析节点后,是因为要根据节点数量判断缓存大小设置是否合理
initRuleCache();
initChainCache();
}
String ruleSource = liteflowConfig.getRuleSource();
@@ -239,8 +239,8 @@ public class FlowExecutor {
}
// 初始化或reload时评估规则缓存容量大小
if (liteflowConfig.getRuleCacheEnabled()) {
evaluateRuleCacheCapacity();
if (liteflowConfig.getChainCacheEnabled()) {
evaluateChainCacheCapacity();
}
}
@@ -678,40 +678,42 @@ public class FlowExecutor {
return resultSlotList;
}
private void initRuleCache() {
private void initChainCache() {
// 启动chain缓存必须使用 PARSE_ONE_ON_FIRST_EXEC 模式
if (!ParseModeEnum.PARSE_ONE_ON_FIRST_EXEC.equals(liteflowConfig.getParseMode())) {
LOG.warn("The parse mode is not PARSE_ONE_ON_FIRST_EXE, so the chain cache cannot be enabled.");
return;
}
// 容量不能小于等于0
Integer capacity = liteflowConfig.getRuleCacheCapacity();
Integer capacity = liteflowConfig.getChainCacheCapacity();
if (ObjectUtil.isNull(capacity) || capacity <= 0) {
throw new ConfigErrorException("The rule cache capacity must be greater than 0");
throw new ConfigErrorException("The chain cache capacity must be greater than 0");
}
// 添加规则缓存生命周期
List<PostProcessChainExecuteLifeCycle> lifeCycleList = LifeCycleHolder.getPostProcessChainExecuteLifeCycleList();
boolean exist = lifeCycleList.stream()
.anyMatch(lifeCycle -> lifeCycle instanceof RuleCacheLifeCycle);
.anyMatch(lifeCycle -> lifeCycle instanceof ChainCacheLifeCycle);
if (!exist) {
boolean success = RuleCacheLifeCycle.initIfAbsent(capacity);
boolean success = ChainCacheLifeCycle.initIfAbsent(capacity);
if (!success) {
throw new FlowExecutorNotInitException("Initialization of RuleCacheLifeCycle failed");
throw new FlowExecutorNotInitException("Initialization of ChainCacheLifeCycle failed");
}
LifeCycleHolder.addLifeCycle(RuleCacheLifeCycle.getLifeCycle());
}
// 执行时才解析chain
if (!ParseModeEnum.PARSE_ONE_ON_FIRST_EXEC.equals(liteflowConfig.getParseMode())) {
liteflowConfig.setParseMode(ParseModeEnum.PARSE_ONE_ON_FIRST_EXEC);
LOG.warn("The rule cache is enabled, so the parse mode is forcibly set to PARSE_ONE_ON_FIRST_EXE.");
LifeCycleHolder.addLifeCycle(ChainCacheLifeCycle.getLifeCycle());
}
}
// 评估规则缓存容量
private void evaluateRuleCacheCapacity() {
Integer capacity = liteflowConfig.getRuleCacheCapacity();
private void evaluateChainCacheCapacity() {
if (!ParseModeEnum.PARSE_ONE_ON_FIRST_EXEC.equals(liteflowConfig.getParseMode())) {
return;
}
Integer capacity = liteflowConfig.getChainCacheCapacity();
// 容量不足chain总数的30%给予警告
int chainNum = FlowBus.getChainMap().size();
double threshold = chainNum * 0.3;
if (capacity < threshold) {
LOG.warn("The rule cache capacity {} is too small, the current total number of chains is {}, "
LOG.warn("The chain cache capacity {} is too small, the current total number of chains is {}, "
+"it is recommended to be greater than 30% of the number of chains", capacity, chainNum);
}
}

View File

@@ -17,11 +17,11 @@ import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.List;
/**
* Chain 缓存处理
* Chain 缓存生命周期
* @author DaleLee
* @since 2.13.3
*/
public class RuleCacheLifeCycle implements PostProcessChainExecuteLifeCycle {
public class ChainCacheLifeCycle implements PostProcessChainExecuteLifeCycle {
/**
* 缓存
*/
@@ -30,9 +30,9 @@ public class RuleCacheLifeCycle implements PostProcessChainExecuteLifeCycle {
/**
* 实例
*/
private static RuleCacheLifeCycle INSTANCE;
private static ChainCacheLifeCycle INSTANCE;
private RuleCacheLifeCycle(int capacity) {
private ChainCacheLifeCycle(int capacity) {
this.cache = Caffeine.newBuilder()
.maximumSize(capacity)
.evictionListener(new ChainRemovalListener())
@@ -149,7 +149,7 @@ public class RuleCacheLifeCycle implements PostProcessChainExecuteLifeCycle {
*/
public synchronized static boolean initIfAbsent(int capacity) {
if (ObjectUtil.isNull(INSTANCE)) {
INSTANCE = new RuleCacheLifeCycle(capacity);
INSTANCE = new ChainCacheLifeCycle(capacity);
return true;
}
return false;
@@ -159,7 +159,7 @@ public class RuleCacheLifeCycle implements PostProcessChainExecuteLifeCycle {
* 获取生命周期实例
* @return lifeCycle
*/
public static RuleCacheLifeCycle getLifeCycle() {
public static ChainCacheLifeCycle getLifeCycle() {
return INSTANCE;
}
}

View File

@@ -116,11 +116,11 @@ public class LiteflowConfig {
// instance id 生成器
private String instanceIdGeneratorClass;
// 是否启用规则缓存
private Boolean ruleCacheEnabled;
// 是否启用chain缓存
private Boolean chainCacheEnabled;
// 规则缓存容量
private Integer ruleCacheCapacity;
// chain缓存容量
private Integer chainCacheCapacity;
public Boolean getEnableMonitorFile() {
return enableMonitorFile;
@@ -502,22 +502,25 @@ public class LiteflowConfig {
this.instanceIdGeneratorClass = instanceIdGeneratorClass;
}
public Boolean getRuleCacheEnabled() {
if (ObjectUtil.isNull(ruleCacheEnabled)) {
public Boolean getChainCacheEnabled() {
if (ObjectUtil.isNull(chainCacheEnabled)) {
return Boolean.FALSE;
}
return ruleCacheEnabled;
return chainCacheEnabled;
}
public void setRuleCacheEnabled(Boolean ruleCacheEnabled) {
this.ruleCacheEnabled = ruleCacheEnabled;
public void setChainCacheEnabled(Boolean chainCacheEnabled) {
this.chainCacheEnabled = chainCacheEnabled;
}
public Integer getRuleCacheCapacity() {
return ruleCacheCapacity;
public Integer getChainCacheCapacity() {
if (ObjectUtil.isNull(chainCacheCapacity)) {
return 10000;
}
return chainCacheCapacity;
}
public void setRuleCacheCapacity(Integer ruleCacheCapacity) {
this.ruleCacheCapacity = ruleCacheCapacity;
public void setChainCacheCapacity(Integer chainCacheCapacity) {
this.chainCacheCapacity = chainCacheCapacity;
}
}

View File

@@ -51,8 +51,8 @@ public class LiteflowAutoConfiguration {
liteflowConfig.setGlobalThreadPoolQueueSize(property.getGlobalThreadPoolQueueSize());
liteflowConfig.setWhenThreadPoolIsolate(property.getWhenThreadPoolIsolate());
liteflowConfig.setEnableNodeInstanceId(property.isEnableNodeInstanceId());
liteflowConfig.setRuleCacheEnabled(property.getRuleCache().isEnabled());
liteflowConfig.setRuleCacheCapacity(property.getRuleCache().getCapacity());
liteflowConfig.setChainCacheEnabled(property.getChainCache().isEnabled());
liteflowConfig.setChainCacheCapacity(property.getChainCache().getCapacity());
return liteflowConfig;
}

View File

@@ -102,9 +102,9 @@ public class LiteflowProperty {
private boolean enableNodeInstanceId;
// 规则缓存配置
private RuleCacheProperty ruleCache;
private ChainCacheProperty chainCache;
public static class RuleCacheProperty {
public static class ChainCacheProperty {
// 是否启用规则缓存
private Boolean enabled;
@@ -369,11 +369,11 @@ public class LiteflowProperty {
this.enableNodeInstanceId = enableNodeInstanceId;
}
public RuleCacheProperty getRuleCache() {
return ruleCache;
public ChainCacheProperty getChainCache() {
return chainCache;
}
public void setRuleCache(RuleCacheProperty ruleCache) {
this.ruleCache = ruleCache;
public void setChainCache(ChainCacheProperty chainCache) {
this.chainCache = chainCache;
}
}

View File

@@ -19,4 +19,5 @@ liteflow.global-thread-pool-size=16
liteflow.global-thread-pool-queue-size=512
liteflow.global-thread-pool-executor-class=com.yomahub.liteflow.thread.LiteFlowDefaultGlobalExecutorBuilder
liteflow.enable-node-instance-id=false
liteflow.rule-cache.enabled=false
liteflow.chain-cache.enabled=false
liteflow.chain-cache.capacity=10000

View File

@@ -102,13 +102,13 @@ public class LiteflowProperty {
// 规则缓存配置
@NestedConfigurationProperty
private RuleCacheProperty ruleCache;
private ChainCacheProperty chainCache;
public static class RuleCacheProperty {
public static class ChainCacheProperty {
// 是否启用规则缓存
private Boolean enabled;
// 规则缓存容量
// chain缓存容量
private Integer capacity;
public Boolean isEnabled() {
@@ -360,11 +360,11 @@ public class LiteflowProperty {
this.enableNodeInstanceId = enableNodeInstanceId;
}
public RuleCacheProperty getRuleCache() {
return ruleCache;
public ChainCacheProperty getChainCache() {
return chainCache;
}
public void setRuleCache(RuleCacheProperty ruleCache) {
this.ruleCache = ruleCache;
public void setChainCache(ChainCacheProperty chainCache) {
this.chainCache = chainCache;
}
}

View File

@@ -53,8 +53,8 @@ public class LiteflowPropertyAutoConfiguration {
liteflowConfig.setGlobalThreadPoolQueueSize(property.getGlobalThreadPoolQueueSize());
liteflowConfig.setGlobalThreadPoolSize(property.getGlobalThreadPoolSize());
liteflowConfig.setEnableNodeInstanceId(property.isEnableNodeInstanceId());
liteflowConfig.setRuleCacheEnabled(property.getRuleCache().isEnabled());
liteflowConfig.setRuleCacheCapacity(property.getRuleCache().getCapacity());
liteflowConfig.setChainCacheEnabled(property.getChainCache().isEnabled());
liteflowConfig.setChainCacheCapacity(property.getChainCache().getCapacity());
return liteflowConfig;
}

View File

@@ -24,5 +24,7 @@ liteflow.global-thread-pool-size=64
liteflow.global-thread-pool-queue-size=512
liteflow.global-thread-pool-executor-class=com.yomahub.liteflow.thread.LiteFlowDefaultGlobalExecutorBuilder
liteflow.enable-node-instance-id=false
liteflow.rule-cache.enabled=false
liteflow.chain-cache.enabled=false
liteflow.chain-cache.capacity=10000

View File

@@ -1,16 +1,17 @@
package com.yomahub.liteflow.test.ruleCache;
package com.yomahub.liteflow.test.chainCache;
import cn.hutool.core.collection.CollUtil;
import com.github.benmanes.caffeine.cache.Cache;
import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.enums.ParseModeEnum;
import com.yomahub.liteflow.exception.ChainNotFoundException;
import com.yomahub.liteflow.flow.FlowBus;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.flow.element.Chain;
import com.yomahub.liteflow.flow.element.Condition;
import com.yomahub.liteflow.lifecycle.impl.RuleCacheLifeCycle;
import com.yomahub.liteflow.lifecycle.impl.ChainCacheLifeCycle;
import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.test.BaseTest;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -27,19 +28,20 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
/**
* 非Spring环境下的规则缓存测试
* 非Spring环境下的chain缓存测试
* @author DaleLee
*/
public class RuleCacheTest extends BaseTest {
public class ChainCacheTest extends BaseTest {
private static FlowExecutor flowExecutor;
@BeforeAll
public static void init() {
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("ruleCache/flow.el.xml");
config.setRuleCacheEnabled(true);
config.setRuleCacheCapacity(5);
config.setRuleSource("chainCache/flow.el.xml");
config.setChainCacheEnabled(true);
config.setChainCacheCapacity(5);
config.setParseMode(ParseModeEnum.PARSE_ONE_ON_FIRST_EXEC);
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
@@ -47,14 +49,14 @@ public class RuleCacheTest extends BaseTest {
public void reload() {
flowExecutor.reloadRule();
// 清空缓存
Cache<String, RuleCacheLifeCycle.ChainState> cache = getCache();
Cache<String, ChainCacheLifeCycle.ChainState> cache = getCache();
cache.invalidateAll();
cache.cleanUp();
}
// 测试chain被淘汰
@Test
public void testRuleCache1() {
public void testChainCache1() {
// 加满缓存
loadCache();
// 缓存快照
@@ -72,7 +74,7 @@ public class RuleCacheTest extends BaseTest {
// 测试缓存数量上限串行
@Test
public void testRuleCache2() {
public void testChainCache2() {
// 确保至少执行过5个不同的chain
loadCache();
// 随机执行chain
@@ -100,7 +102,7 @@ public class RuleCacheTest extends BaseTest {
// 测试缓存数量上限并行
@Test
public void testRuleCache3() {
public void testChainCache3() {
loadCache();
Random random = new Random();
List<Future<LiteflowResponse>> futureList = CollUtil.newArrayList();
@@ -137,7 +139,7 @@ public class RuleCacheTest extends BaseTest {
// 测试开启规则缓存后进入缓存的chain可以正常被更新
@Test
public void testRuleCache4() {
public void testChainCache4() {
loadCache();
// 缓存快照
HashSet<@NonNull String> strings = CollUtil.newHashSet(getCache().asMap().keySet());
@@ -163,7 +165,7 @@ public class RuleCacheTest extends BaseTest {
// 测试开启规则缓存后进入缓存的chain被移除后无法执行
@Test
public void testRuleCache5() {
public void testChainCache5() {
loadCache();
// 缓存快照
HashSet<@NonNull String> strings = CollUtil.newHashSet(getCache().asMap().keySet());
@@ -184,7 +186,7 @@ public class RuleCacheTest extends BaseTest {
// 测试并发下正在执行的chain的condition被清理但仍能执行
@Test
public void testRuleCache6() throws InterruptedException {
public void testChainCache6() throws InterruptedException {
// 模拟清空编译好的chain
Thread thread = new Thread(()-> {
Chain chain1 = FlowBus.getChain("chain1");
@@ -218,14 +220,14 @@ public class RuleCacheTest extends BaseTest {
Assertions.assertNull(chain.getConditionList());
}
public Cache<String, RuleCacheLifeCycle.ChainState> getCache() {
return RuleCacheLifeCycle.getLifeCycle().getCache();
public Cache<String, ChainCacheLifeCycle.ChainState> getCache() {
return ChainCacheLifeCycle.getLifeCycle().getCache();
}
// 获得淘汰的chain传入淘汰前的chain集合
// 确保只有一个被淘汰时使用
String getEvictedChain(Set<String> set) {
Cache<String, RuleCacheLifeCycle.ChainState> cache = getCache();
Cache<String, ChainCacheLifeCycle.ChainState> cache = getCache();
cache.cleanUp();
Set<@NonNull String> strings = cache.asMap().keySet();
set.removeAll(strings);

View File

@@ -5,7 +5,7 @@
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.ruleCache.cmp;
package com.yomahub.liteflow.test.chainCache.cmp;
import com.yomahub.liteflow.core.NodeComponent;

View File

@@ -5,7 +5,7 @@
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.ruleCache.cmp;
package com.yomahub.liteflow.test.chainCache.cmp;
import com.yomahub.liteflow.core.NodeComponent;

View File

@@ -5,7 +5,7 @@
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.ruleCache.cmp;
package com.yomahub.liteflow.test.chainCache.cmp;
import com.yomahub.liteflow.core.NodeComponent;

View File

@@ -1,4 +1,4 @@
package com.yomahub.liteflow.test.ruleCache.cmp;
package com.yomahub.liteflow.test.chainCache.cmp;
import com.yomahub.liteflow.core.NodeBooleanComponent;

View File

@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<nodes>
<node id="a" class="com.yomahub.liteflow.test.ruleCache.cmp.ACmp"/>
<node id="b" class="com.yomahub.liteflow.test.ruleCache.cmp.BCmp"/>
<node id="c" class="com.yomahub.liteflow.test.ruleCache.cmp.CCmp"/>
<node id="x" class="com.yomahub.liteflow.test.ruleCache.cmp.XCmp"/>
<node id="a" class="com.yomahub.liteflow.test.chainCache.cmp.ACmp"/>
<node id="b" class="com.yomahub.liteflow.test.chainCache.cmp.BCmp"/>
<node id="c" class="com.yomahub.liteflow.test.chainCache.cmp.CCmp"/>
<node id="x" class="com.yomahub.liteflow.test.chainCache.cmp.XCmp"/>
</nodes>
<chain name="chain1">

View File

@@ -1,4 +1,4 @@
package com.yomahub.liteflow.test.ruleCache;
package com.yomahub.liteflow.test.chainCache;
import cn.hutool.core.collection.CollUtil;
import com.github.benmanes.caffeine.cache.Cache;
@@ -9,7 +9,7 @@ import com.yomahub.liteflow.flow.FlowBus;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.flow.element.Chain;
import com.yomahub.liteflow.flow.element.Condition;
import com.yomahub.liteflow.lifecycle.impl.RuleCacheLifeCycle;
import com.yomahub.liteflow.lifecycle.impl.ChainCacheLifeCycle;
import com.yomahub.liteflow.test.BaseTest;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.junit.jupiter.api.Assertions;
@@ -27,12 +27,12 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
/**
* Solon环境下规则缓存测试
* Solon环境下chain缓存测试
* @author DaleLee
*/
@SolonTest
@Import(profiles="classpath:/ruleCache/application.properties")
public class RuleCacheSolonTest extends BaseTest {
@Import(profiles="classpath:/chainCache/application.properties")
public class ChainCacheSolonTest extends BaseTest {
@Inject
private FlowExecutor flowExecutor;
@@ -41,14 +41,14 @@ public class RuleCacheSolonTest extends BaseTest {
public void reload() {
flowExecutor.reloadRule();
// 清空缓存
Cache<String, RuleCacheLifeCycle.ChainState> cache = getCache();
Cache<String, ChainCacheLifeCycle.ChainState> cache = getCache();
cache.invalidateAll();
cache.cleanUp();
}
// 测试chain被淘汰
@Test
public void testRuleCache1() {
public void testChainCache1() {
// 加满缓存
loadCache();
// 缓存快照
@@ -66,7 +66,7 @@ public class RuleCacheSolonTest extends BaseTest {
// 测试缓存数量上限串行
@Test
public void testRuleCache2() {
public void testChainCache2() {
// 确保至少执行过5个不同的chain
loadCache();
// 随机执行chain
@@ -94,7 +94,7 @@ public class RuleCacheSolonTest extends BaseTest {
// 测试缓存数量上限并行
@Test
public void testRuleCache3() {
public void testChainCache3() {
loadCache();
Random random = new Random();
List<Future<LiteflowResponse>> futureList = CollUtil.newArrayList();
@@ -131,7 +131,7 @@ public class RuleCacheSolonTest extends BaseTest {
// 测试开启规则缓存后进入缓存的chain可以正常被更新
@Test
public void testRuleCache4() {
public void testChainCache4() {
loadCache();
// 缓存快照
HashSet<@NonNull String> strings = CollUtil.newHashSet(getCache().asMap().keySet());
@@ -157,7 +157,7 @@ public class RuleCacheSolonTest extends BaseTest {
// 测试开启规则缓存后进入缓存的chain被移除后无法执行
@Test
public void testRuleCache5() {
public void testChainCache5() {
loadCache();
// 缓存快照
HashSet<@NonNull String> strings = CollUtil.newHashSet(getCache().asMap().keySet());
@@ -178,7 +178,7 @@ public class RuleCacheSolonTest extends BaseTest {
// 测试并发下正在执行的chain的condition被清理但仍能执行
@Test
public void testRuleCache6() throws InterruptedException {
public void testChainCache6() throws InterruptedException {
// 模拟清空编译好的chain
Thread thread = new Thread(()-> {
Chain chain1 = FlowBus.getChain("chain1");
@@ -212,14 +212,14 @@ public class RuleCacheSolonTest extends BaseTest {
Assertions.assertNull(chain.getConditionList());
}
public Cache<String, RuleCacheLifeCycle.ChainState> getCache() {
return RuleCacheLifeCycle.getLifeCycle().getCache();
public Cache<String, ChainCacheLifeCycle.ChainState> getCache() {
return ChainCacheLifeCycle.getLifeCycle().getCache();
}
// 获得淘汰的chain传入淘汰前的chain集合
// 确保只有一个被淘汰时使用
String getEvictedChain(Set<String> set) {
Cache<String, RuleCacheLifeCycle.ChainState> cache = getCache();
Cache<String, ChainCacheLifeCycle.ChainState> cache = getCache();
cache.cleanUp();
Set<@NonNull String> strings = cache.asMap().keySet();
set.removeAll(strings);

View File

@@ -5,7 +5,7 @@
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.ruleCache.cmp;
package com.yomahub.liteflow.test.chainCache.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import org.noear.solon.annotation.Component;

View File

@@ -5,7 +5,7 @@
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.ruleCache.cmp;
package com.yomahub.liteflow.test.chainCache.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import org.noear.solon.annotation.Component;

View File

@@ -5,7 +5,7 @@
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.ruleCache.cmp;
package com.yomahub.liteflow.test.chainCache.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import org.noear.solon.annotation.Component;

View File

@@ -1,4 +1,4 @@
package com.yomahub.liteflow.test.ruleCache.cmp;
package com.yomahub.liteflow.test.chainCache.cmp;
import com.yomahub.liteflow.core.NodeBooleanComponent;
import org.noear.solon.annotation.Component;

View File

@@ -0,0 +1,4 @@
liteflow.rule-source=chainCache/flow.el.xml
liteflow.chain-cache.enabled=true
liteflow.chain-cache.capacity=5
liteflow.parse-mode=PARSE_ONE_ON_FIRST_EXEC

View File

@@ -1,3 +0,0 @@
liteflow.rule-source=ruleCache/flow.el.xml
liteflow.rule-cache.enabled=true
liteflow.rule-cache.capacity=5

View File

@@ -1,4 +1,4 @@
package com.yomahub.liteflow.test.ruleCache;
package com.yomahub.liteflow.test.chainCache;
import cn.hutool.core.collection.CollUtil;
import com.github.benmanes.caffeine.cache.Cache;
@@ -9,7 +9,7 @@ import com.yomahub.liteflow.flow.FlowBus;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.flow.element.Chain;
import com.yomahub.liteflow.flow.element.Condition;
import com.yomahub.liteflow.lifecycle.impl.RuleCacheLifeCycle;
import com.yomahub.liteflow.lifecycle.impl.ChainCacheLifeCycle;
import com.yomahub.liteflow.test.BaseTest;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.junit.jupiter.api.Assertions;
@@ -29,14 +29,14 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
/**
* Springboot环境下规则缓存测试
* Springboot环境下chain缓存测试
* @author DaleLee
*/
@TestPropertySource(value = "classpath:/ruleCache/application.properties")
@SpringBootTest(classes = RuleCacheSpringbootTest.class)
@TestPropertySource(value = "classpath:/chainCache/application.properties")
@SpringBootTest(classes = ChainCacheSpringbootTest.class)
@EnableAutoConfiguration
@ComponentScan({ "com.yomahub.liteflow.test.ruleCache.cmp" })
public class RuleCacheSpringbootTest extends BaseTest {
@ComponentScan({"com.yomahub.liteflow.test.chainCache.cmp"})
public class ChainCacheSpringbootTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
@@ -44,14 +44,14 @@ public class RuleCacheSpringbootTest extends BaseTest {
public void reload() {
flowExecutor.reloadRule();
// 清空缓存
Cache<String, RuleCacheLifeCycle.ChainState> cache = getCache();
Cache<String, ChainCacheLifeCycle.ChainState> cache = getCache();
cache.invalidateAll();
cache.cleanUp();
}
// 测试chain被淘汰
@Test
public void testRuleCache1() {
public void testChainCache1() {
// 加满缓存
loadCache();
// 缓存快照
@@ -69,7 +69,7 @@ public class RuleCacheSpringbootTest extends BaseTest {
// 测试缓存数量上限串行
@Test
public void testRuleCache2() {
public void testChainCache2() {
// 确保至少执行过5个不同的chain
loadCache();
// 随机执行chain
@@ -97,7 +97,7 @@ public class RuleCacheSpringbootTest extends BaseTest {
// 测试缓存数量上限并行
@Test
public void testRuleCache3() {
public void testChainCache3() {
loadCache();
Random random = new Random();
List<Future<LiteflowResponse>> futureList = CollUtil.newArrayList();
@@ -134,7 +134,7 @@ public class RuleCacheSpringbootTest extends BaseTest {
// 测试开启规则缓存后进入缓存的chain可以正常被更新
@Test
public void testRuleCache4() {
public void testChainCache4() {
loadCache();
// 缓存快照
HashSet<@NonNull String> strings = CollUtil.newHashSet(getCache().asMap().keySet());
@@ -160,7 +160,7 @@ public class RuleCacheSpringbootTest extends BaseTest {
// 测试开启规则缓存后进入缓存的chain被移除后无法执行
@Test
public void testRuleCache5() {
public void testChainCache5() {
loadCache();
// 缓存快照
HashSet<@NonNull String> strings = CollUtil.newHashSet(getCache().asMap().keySet());
@@ -181,7 +181,7 @@ public class RuleCacheSpringbootTest extends BaseTest {
// 测试并发下正在执行的chain的condition被清理但仍能执行
@Test
public void testRuleCache6() throws InterruptedException {
public void testChainCache6() throws InterruptedException {
// 模拟清空编译好的chain
Thread thread = new Thread(()-> {
Chain chain1 = FlowBus.getChain("chain1");
@@ -215,14 +215,14 @@ public class RuleCacheSpringbootTest extends BaseTest {
Assertions.assertNull(chain.getConditionList());
}
public Cache<String, RuleCacheLifeCycle.ChainState> getCache() {
return RuleCacheLifeCycle.getLifeCycle().getCache();
public Cache<String, ChainCacheLifeCycle.ChainState> getCache() {
return ChainCacheLifeCycle.getLifeCycle().getCache();
}
// 获得淘汰的chain传入淘汰前的chain集合
// 确保只有一个被淘汰时使用
String getEvictedChain(Set<String> set) {
Cache<String, RuleCacheLifeCycle.ChainState> cache = getCache();
Cache<String, ChainCacheLifeCycle.ChainState> cache = getCache();
cache.cleanUp();
Set<@NonNull String> strings = cache.asMap().keySet();
set.removeAll(strings);

View File

@@ -5,7 +5,7 @@
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.ruleCache.cmp;
package com.yomahub.liteflow.test.chainCache.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.ruleCache.cmp;
package com.yomahub.liteflow.test.chainCache.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.ruleCache.cmp;
package com.yomahub.liteflow.test.chainCache.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;

View File

@@ -1,4 +1,4 @@
package com.yomahub.liteflow.test.ruleCache.cmp;
package com.yomahub.liteflow.test.chainCache.cmp;
import com.yomahub.liteflow.core.NodeBooleanComponent;
import org.springframework.stereotype.Component;

View File

@@ -0,0 +1,4 @@
liteflow.rule-source=chainCache/flow.el.xml
liteflow.chain-cache.enabled=true
liteflow.chain-cache.capacity=5
liteflow.parse-mode=PARSE_ONE_ON_FIRST_EXEC

View File

@@ -1,3 +0,0 @@
liteflow.rule-source=ruleCache/flow.el.xml
liteflow.rule-cache.enabled=true
liteflow.rule-cache.capacity=5

View File

@@ -1,4 +1,4 @@
package com.yomahub.liteflow.test.ruleCache;
package com.yomahub.liteflow.test.chainCache;
import cn.hutool.core.collection.CollUtil;
import com.github.benmanes.caffeine.cache.Cache;
@@ -9,7 +9,7 @@ import com.yomahub.liteflow.flow.FlowBus;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.flow.element.Chain;
import com.yomahub.liteflow.flow.element.Condition;
import com.yomahub.liteflow.lifecycle.impl.RuleCacheLifeCycle;
import com.yomahub.liteflow.lifecycle.impl.ChainCacheLifeCycle;
import com.yomahub.liteflow.test.BaseTest;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.junit.jupiter.api.Assertions;
@@ -28,12 +28,12 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
/**
* Spring环境下规则缓存测试
* Spring环境下chain缓存测试
* @author DaleLee
*/
@ExtendWith(SpringExtension.class)
@ContextConfiguration("classpath:/ruleCache/application.xml")
public class RuleCacheSpringTest extends BaseTest {
@ContextConfiguration("classpath:/chainCache/application.xml")
public class ChainCacheSpringTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
@@ -41,14 +41,14 @@ public class RuleCacheSpringTest extends BaseTest {
public void reload() {
flowExecutor.reloadRule();
// 清空缓存
Cache<String, RuleCacheLifeCycle.ChainState> cache = getCache();
Cache<String, ChainCacheLifeCycle.ChainState> cache = getCache();
cache.invalidateAll();
cache.cleanUp();
}
// 测试chain被淘汰
@Test
public void testRuleCache1() {
public void testChainCache1() {
// 加满缓存
loadCache();
// 缓存快照
@@ -66,7 +66,7 @@ public class RuleCacheSpringTest extends BaseTest {
// 测试缓存数量上限串行
@Test
public void testRuleCache2() {
public void testChainCache2() {
// 确保至少执行过5个不同的chain
loadCache();
// 随机执行chain
@@ -94,7 +94,7 @@ public class RuleCacheSpringTest extends BaseTest {
// 测试缓存数量上限并行
@Test
public void testRuleCache3() {
public void testChainCache3() {
loadCache();
Random random = new Random();
List<Future<LiteflowResponse>> futureList = CollUtil.newArrayList();
@@ -131,7 +131,7 @@ public class RuleCacheSpringTest extends BaseTest {
// 测试开启规则缓存后进入缓存的chain可以正常被更新
@Test
public void testRuleCache4() {
public void testChainCache4() {
loadCache();
// 缓存快照
HashSet<@NonNull String> strings = CollUtil.newHashSet(getCache().asMap().keySet());
@@ -157,7 +157,7 @@ public class RuleCacheSpringTest extends BaseTest {
// 测试开启规则缓存后进入缓存的chain被移除后无法执行
@Test
public void testRuleCache5() {
public void testChainCache5() {
loadCache();
// 缓存快照
HashSet<@NonNull String> strings = CollUtil.newHashSet(getCache().asMap().keySet());
@@ -178,7 +178,7 @@ public class RuleCacheSpringTest extends BaseTest {
// 测试并发下正在执行的chain的condition被清理但仍能执行
@Test
public void testRuleCache6() throws InterruptedException {
public void testChainCache6() throws InterruptedException {
// 模拟清空编译好的chain
Thread thread = new Thread(()-> {
Chain chain1 = FlowBus.getChain("chain1");
@@ -212,14 +212,14 @@ public class RuleCacheSpringTest extends BaseTest {
Assertions.assertNull(chain.getConditionList());
}
public Cache<String, RuleCacheLifeCycle.ChainState> getCache() {
return RuleCacheLifeCycle.getLifeCycle().getCache();
public Cache<String, ChainCacheLifeCycle.ChainState> getCache() {
return ChainCacheLifeCycle.getLifeCycle().getCache();
}
// 获得淘汰的chain传入淘汰前的chain集合
// 确保只有一个被淘汰时使用
String getEvictedChain(Set<String> set) {
Cache<String, RuleCacheLifeCycle.ChainState> cache = getCache();
Cache<String, ChainCacheLifeCycle.ChainState> cache = getCache();
cache.cleanUp();
Set<@NonNull String> strings = cache.asMap().keySet();
set.removeAll(strings);

View File

@@ -5,7 +5,7 @@
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.ruleCache.cmp;
package com.yomahub.liteflow.test.chainCache.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.ruleCache.cmp;
package com.yomahub.liteflow.test.chainCache.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.ruleCache.cmp;
package com.yomahub.liteflow.test.chainCache.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;

View File

@@ -1,4 +1,4 @@
package com.yomahub.liteflow.test.ruleCache.cmp;
package com.yomahub.liteflow.test.chainCache.cmp;
import com.yomahub.liteflow.core.NodeBooleanComponent;
import org.springframework.stereotype.Component;

View File

@@ -7,16 +7,17 @@
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.ruleCache.cmp" />
<context:component-scan base-package="com.yomahub.liteflow.test.chainCache.cmp" />
<bean id="springAware" class="com.yomahub.liteflow.spi.spring.SpringAware"/>
<bean class="com.yomahub.liteflow.spring.ComponentScanner"/>
<bean id="liteflowConfig" class="com.yomahub.liteflow.property.LiteflowConfig">
<property name="ruleSource" value="ruleCache/flow.el.xml"/>
<property name="ruleCacheEnabled" value="true"/>
<property name="ruleCacheCapacity" value="5"/>
<property name="ruleSource" value="chainCache/flow.el.xml"/>
<property name="chainCacheEnabled" value="true"/>
<property name="chainCacheCapacity" value="5"/>
<property name="parseMode" value="PARSE_ONE_ON_FIRST_EXEC"/>
</bean>
<bean id="flowExecutor" class="com.yomahub.liteflow.core.FlowExecutor">