diff --git a/liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/CommonBenchmark.java b/liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/CommonBenchmark.java index 275683423..43c9b1d55 100644 --- a/liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/CommonBenchmark.java +++ b/liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/CommonBenchmark.java @@ -1,10 +1,13 @@ package com.yomahub.liteflow.benchmark; import cn.hutool.core.io.resource.ResourceUtil; +import com.yomahub.liteflow.benchmark.cmp.TestContext; import com.yomahub.liteflow.builder.LiteFlowNodeBuilder; import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder; import com.yomahub.liteflow.core.FlowExecutor; import com.yomahub.liteflow.flow.FlowBus; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.slot.DefaultContext; import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; @@ -42,7 +45,12 @@ public class CommonBenchmark { @Benchmark public void test1(){ - flowExecutor.execute2Resp("chain1"); + TestContext context = new TestContext(); + context.setName("tom"); + context.setAge(21); + DefaultContext defaultContext = new DefaultContext(); + + flowExecutor.execute2Resp("chain1", null, context,defaultContext); } public static void main(String[] args) throws RunnerException { diff --git a/liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/CommonTest.java b/liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/CommonTest.java new file mode 100644 index 000000000..f8869ab68 --- /dev/null +++ b/liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/CommonTest.java @@ -0,0 +1,41 @@ +package com.yomahub.liteflow.benchmark; + +import cn.hutool.core.io.resource.ResourceUtil; +import com.yomahub.liteflow.benchmark.cmp.TestContext; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.util.JsonUtil; +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.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import javax.annotation.Resource; + +@ExtendWith(SpringExtension.class) +@TestPropertySource(value = "classpath:application.properties") +@SpringBootTest(classes = CommonTest.class) +@EnableAutoConfiguration +@ComponentScan({ "com.yomahub.liteflow.benchmark.cmp" }) +public class CommonTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void test1() throws Exception { + TestContext context = new TestContext(); + context.setName("tom"); + context.setAge(21); + DefaultContext defaultContext = new DefaultContext(); + + LiteflowResponse response = flowExecutor.execute2Resp("chain1", null, context,defaultContext); + if (!response.isSuccess()){ + throw response.getCause(); + } + } +} diff --git a/liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/cmp/ACmp.java b/liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/cmp/ACmp.java index 4611110de..0ff485aa2 100644 --- a/liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/cmp/ACmp.java +++ b/liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/cmp/ACmp.java @@ -22,7 +22,7 @@ public class ACmp extends NodeComponent { public void process() { int v1 = 2; int v2 = 3; - DefaultContext ctx = this.getFirstContextBean(); + DefaultContext ctx = this.getContextBean(DefaultContext.class); ctx.setData("s1", v1 * v2); TestDomain domain = ContextAwareHolder.loadContextAware().getBean(TestDomain.class); diff --git a/liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/cmp/CmpConfig.java b/liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/cmp/CmpConfig.java new file mode 100644 index 000000000..54dcefdc0 --- /dev/null +++ b/liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/cmp/CmpConfig.java @@ -0,0 +1,21 @@ +package com.yomahub.liteflow.benchmark.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowFact; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent +public class CmpConfig { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") + public void processA(NodeComponent bindCmp, @LiteflowFact("name") String name) { + System.out.println(name); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "c") + public void processB(NodeComponent bindCmp, @LiteflowFact("age") int age) { + System.out.println(age); + } +} diff --git a/liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/cmp/TestContext.java b/liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/cmp/TestContext.java new file mode 100644 index 000000000..df6f9430a --- /dev/null +++ b/liteflow-benchmark/liteflow-benchmark-common/src/test/java/com/yomahub/liteflow/benchmark/cmp/TestContext.java @@ -0,0 +1,24 @@ +package com.yomahub.liteflow.benchmark.cmp; + +public class TestContext { + + private String name; + + private int age; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } +} diff --git a/liteflow-benchmark/liteflow-benchmark-common/src/test/resources/flow.xml b/liteflow-benchmark/liteflow-benchmark-common/src/test/resources/flow.xml index 41259eb42..45589ebd2 100644 --- a/liteflow-benchmark/liteflow-benchmark-common/src/test/resources/flow.xml +++ b/liteflow-benchmark/liteflow-benchmark-common/src/test/resources/flow.xml @@ -2,6 +2,6 @@ - THEN(a); + THEN(a,b,c); \ No newline at end of file