diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/monitor/MonitorFile.java b/liteflow-core/src/main/java/com/yomahub/liteflow/monitor/MonitorFile.java index 756d54273..fb3226b77 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/monitor/MonitorFile.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/monitor/MonitorFile.java @@ -63,13 +63,21 @@ public class MonitorFile { @Override public void onFileChange(File file) { LOG.info("file modify,filePath={}", file.getAbsolutePath()); - FlowExecutorHolder.loadInstance().reloadRule(); + this.reloadRule(); } @Override public void onFileDelete(File file) { LOG.info("file delete,filePath={}", file.getAbsolutePath()); - FlowExecutorHolder.loadInstance().reloadRule(); + this.reloadRule(); + } + + private void reloadRule() { + try { + FlowExecutorHolder.loadInstance().reloadRule(); + } catch (Exception e) { + LOG.error("reload rule error", e); + } } }); // 创建文件变化监听器 diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELSpringbootTest.java index 2ffdd06e2..32c895be8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELSpringbootTest.java @@ -7,8 +7,10 @@ import com.yomahub.liteflow.core.FlowExecutor; import com.yomahub.liteflow.flow.LiteflowResponse; import com.yomahub.liteflow.test.BaseTest; import org.junit.Assert; +import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.ComponentScan; @@ -23,6 +25,7 @@ import java.io.File; @SpringBootTest(classes = MonitorFileELSpringbootTest.class) @EnableAutoConfiguration @ComponentScan({ "com.yomahub.liteflow.test.monitorFile.cmp" }) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) public class MonitorFileELSpringbootTest extends BaseTest { @Resource @@ -39,4 +42,28 @@ public class MonitorFileELSpringbootTest extends BaseTest { Assert.assertEquals("a==>c==>b", response.getExecuteStepStr()); } + /** + * 测试文件变更,但是 EL 规则错误情况 + * 输出 ERROR 日志异常信息,但是不会停止监听线程,当下一次变更正确后替换为新规则 + */ + @Test + public void testMonitorError() throws Exception { + String absolutePath = new ClassPathResource("classpath:/monitorFile/flow.el.xml").getAbsolutePath(); + String content = FileUtil.readUtf8String(absolutePath); + + // 错误规则配置 + String newContent = content.replace("THEN(a, c, b);", "THEN(c, b, ;"); + FileUtil.writeString(newContent, new File(absolutePath), CharsetUtil.CHARSET_UTF_8); + Thread.sleep(3000); + LiteflowResponse reloadFailedResponse = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertEquals("a==>c==>b", reloadFailedResponse.getExecuteStepStr()); + + // 再次变更正确 + newContent = content.replace("THEN(a, c, b);", "THEN(c, b, a);"); + FileUtil.writeString(newContent, new File(absolutePath), CharsetUtil.CHARSET_UTF_8); + Thread.sleep(3000); + LiteflowResponse reloadSuccessResponse = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertEquals("c==>b==>a", reloadSuccessResponse.getExecuteStepStr()); + } + }