mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 04:02:09 +08:00
增加benchmark的工程测试
This commit is contained in:
@@ -12,4 +12,13 @@
|
||||
|
||||
<artifactId>liteflow-benchmark-common</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>liteflow-script-javax</artifactId>
|
||||
<version>${revision}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.yomahub.liteflow.benchmark;
|
||||
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
||||
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 org.openjdk.jmh.annotations.*;
|
||||
import org.openjdk.jmh.runner.Runner;
|
||||
import org.openjdk.jmh.runner.RunnerException;
|
||||
import org.openjdk.jmh.runner.options.Options;
|
||||
import org.openjdk.jmh.runner.options.OptionsBuilder;
|
||||
import org.openjdk.jmh.runner.options.TimeValue;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@State(Scope.Benchmark)
|
||||
@EnableAutoConfiguration
|
||||
@PropertySource(value = "classpath:application.properties")
|
||||
@ComponentScan("com.yomahub.liteflow.benchmark.cmp")
|
||||
public class CommonBenchmark {
|
||||
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
|
||||
private FlowExecutor flowExecutor;
|
||||
|
||||
@Setup
|
||||
public void setup() {
|
||||
applicationContext = SpringApplication.run(CommonBenchmark.class);
|
||||
flowExecutor = applicationContext.getBean(FlowExecutor.class);
|
||||
}
|
||||
|
||||
@TearDown
|
||||
public void tearDown() {
|
||||
applicationContext.close();
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void test1(){
|
||||
flowExecutor.execute2Resp("chain1");
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void test2(){
|
||||
flowExecutor.execute2Resp("chain2");
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) throws RunnerException {
|
||||
Options opt = new OptionsBuilder()
|
||||
.include(CommonBenchmark.class.getSimpleName())
|
||||
.mode(Mode.Throughput)
|
||||
.warmupIterations(1)//预热次数
|
||||
.measurementIterations(3)//执行次数
|
||||
.measurementTime(new TimeValue(10, TimeUnit.SECONDS))//每次执行多少时间
|
||||
.threads(100)//多少个线程
|
||||
.forks(1)//多少个进程
|
||||
.timeUnit(TimeUnit.SECONDS)
|
||||
.build();
|
||||
new Runner(opt).run();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
*/
|
||||
package com.yomahub.liteflow.benchmark.cmp;
|
||||
|
||||
import com.yomahub.liteflow.annotation.LiteflowComponent;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
|
||||
@LiteflowComponent("a")
|
||||
public class ACmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
*/
|
||||
package com.yomahub.liteflow.benchmark.cmp;
|
||||
|
||||
import com.yomahub.liteflow.annotation.LiteflowComponent;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
|
||||
@LiteflowComponent("b")
|
||||
public class BCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
*/
|
||||
package com.yomahub.liteflow.benchmark.cmp;
|
||||
|
||||
import com.yomahub.liteflow.annotation.LiteflowComponent;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
|
||||
@LiteflowComponent("c")
|
||||
public class CCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.yomahub.liteflow.benchmark.cmp;
|
||||
|
||||
public class Person {
|
||||
private String name;
|
||||
|
||||
private Integer salary;
|
||||
|
||||
public Person(String name, Integer salary) {
|
||||
this.name = name;
|
||||
this.salary = salary;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Integer getSalary() {
|
||||
return salary;
|
||||
}
|
||||
|
||||
public void setSalary(Integer salary) {
|
||||
this.salary = salary;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.yomahub.liteflow.benchmark.test;
|
||||
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
||||
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.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;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
@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() {
|
||||
flowExecutor.execute2Resp("chain1");
|
||||
}
|
||||
}
|
||||
@@ -2,54 +2,32 @@
|
||||
<!DOCTYPE flow PUBLIC "liteflow" "liteflow.dtd">
|
||||
<flow>
|
||||
<nodes>
|
||||
<node id="s1" name="普通脚本1" type="script" language="groovy">
|
||||
<node id="s1" name="普通脚本1" type="script" language="java">
|
||||
<![CDATA[
|
||||
import cn.hutool.core.collection.ListUtil
|
||||
import cn.hutool.core.date.DateUtil
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import com.yomahub.liteflow.benchmark.cmp.Person;
|
||||
import com.yomahub.liteflow.script.body.CommonScriptBody;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import com.yomahub.liteflow.spi.holder.ContextAwareHolder;
|
||||
import com.yomahub.liteflow.script.ScriptExecuteWrap;
|
||||
|
||||
import java.util.function.Consumer
|
||||
import java.util.function.Function
|
||||
import java.util.stream.Collectors
|
||||
import java.util.List;
|
||||
import java.util.function.ToIntFunction;
|
||||
|
||||
def date = DateUtil.parse("2022-10-17 13:31:43")
|
||||
defaultContext.setData("demoDate", date)
|
||||
|
||||
List<String> list = ListUtil.toList("a", "b", "c")
|
||||
|
||||
List<String> resultList = list.stream().map(s -> "hello," + s).collect(Collectors.toList())
|
||||
|
||||
defaultContext.setData("resultList", resultList)
|
||||
|
||||
class Student {
|
||||
int studentID
|
||||
String studentName
|
||||
public class Demo implements CommonScriptBody {
|
||||
public Void body(ScriptExecuteWrap wrap) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Student student = new Student()
|
||||
student.studentID = 100301
|
||||
student.studentName = "张三"
|
||||
defaultContext.setData("student", student)
|
||||
|
||||
def a = 3
|
||||
def b = 2
|
||||
defaultContext.setData("s1", a * b)
|
||||
]]>
|
||||
</node>
|
||||
|
||||
<node id="s2" name="循环脚本1" type="for_script" language="groovy">
|
||||
<![CDATA[
|
||||
return 2
|
||||
]]>
|
||||
</node>
|
||||
|
||||
<node id="s3" name="选择脚本" type="switch_script" language="groovy">
|
||||
<![CDATA[
|
||||
return "b"
|
||||
]]>
|
||||
</node>
|
||||
</nodes>
|
||||
|
||||
<chain name="chain1">
|
||||
THEN(FOR(s2).DO(THEN(a, b, c, s1)), SWITCH(s3).TO(a,b));
|
||||
THEN(a,b,c);
|
||||
</chain>
|
||||
|
||||
<chain name="chain2">
|
||||
THEN(a,b,s1);
|
||||
</chain>
|
||||
</flow>
|
||||
Reference in New Issue
Block a user