Pre Merge pull request !361 from DaleLee/fix/issue-IJM5SE-startUpPhase

This commit is contained in:
DaleLee 2026-08-07 07:16:02 +00:00 committed by Gitee
commit f8ad3535de
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
6 changed files with 83 additions and 0 deletions

View File

@ -152,6 +152,7 @@ public class FlowExecutor {
else {
// ruleSource为空而且没有spi形式的扩展那么说明真的没有ruleSource
// 这种情况有可能是基于代码动态构建的
startUpPhase.compareAndSet(true, false);
return;
}
}

View File

@ -24,6 +24,13 @@ public class BuilderTest extends BaseTest {
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
// 验证ruleSource为空时代码动态构建链后startUpPhase正确为false确保脚本热更新可用
@Test
public void testStartUpPhaseWhenRuleSourceEmpty() {
Assertions.assertFalse(flowExecutor.getStartUpPhase().get(),
"当ruleSource为空时startUpPhase应在init完成后为false");
}
// 基于普通组件的builder模式测试
@Test
public void testBuilder() throws Exception {

View File

@ -0,0 +1,60 @@
package com.yomahub.liteflow.test.script.javaxpro.builder;
import com.yomahub.liteflow.builder.LiteFlowNodeBuilder;
import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.enums.ScriptTypeEnum;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.slot.DefaultContext;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import javax.annotation.Resource;
@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = ScriptJavaxProBuilderELTest.class)
@EnableAutoConfiguration
@TestPropertySource(value = "classpath:/builder/application.properties")
public class ScriptJavaxProBuilderELTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
// 验证ruleSource为空时代码动态构建的脚本节点可被正确编译并执行
@Test
public void testScriptCompiledWhenRuleSourceEmpty() {
String script = "import com.yomahub.liteflow.core.NodeComponent;\n"
+ "import com.yomahub.liteflow.slot.DefaultContext;\n"
+ "public class Demo extends NodeComponent {\n"
+ " public void process() {\n"
+ " DefaultContext ctx = this.getFirstContextBean();\n"
+ " ctx.setData(\"scriptExecuted\", true);\n"
+ " }\n"
+ "}";
LiteFlowNodeBuilder.createScriptNode()
.setId("s")
.setName("脚本S")
.setScript(script)
.setLanguage(ScriptTypeEnum.JAVA.getDisplayName())
.build();
LiteFlowChainELBuilder.createChain()
.setChainId("testScriptChain")
.setEL("THEN(s)")
.build();
LiteflowResponse response = flowExecutor.execute2Resp("testScriptChain", null, DefaultContext.class);
Assertions.assertTrue(response.isSuccess(),
"链应执行成功");
DefaultContext ctx = response.getFirstContextBean();
Assertions.assertEquals(true, ctx.getData("scriptExecuted"),
"脚本应被正确编译并执行");
}
}

View File

@ -33,6 +33,13 @@ public class BuilderELSpringbootTest1 extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
// 验证ruleSource为空时代码动态构建链后startUpPhase正确为false
@Test
public void testStartUpPhaseWhenRuleSourceEmpty() {
Assertions.assertFalse(flowExecutor.getStartUpPhase().get(),
"当ruleSource为空时startUpPhase应在init完成后为false");
}
// 基于普通组件的builder模式测试
@Test
public void testBuilder() throws Exception {

View File

@ -31,6 +31,13 @@ public class BuilderELSpringTest1 extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
// 验证ruleSource为空时代码动态构建链后startUpPhase正确为false
@Test
public void testStartUpPhaseWhenRuleSourceEmpty() {
Assertions.assertFalse(flowExecutor.getStartUpPhase().get(),
"当ruleSource为空时startUpPhase应在init完成后为false");
}
// 基于普通组件的builder模式测试
@Test
public void testBuilder() throws Exception {