增加非springboot的测试用例

This commit is contained in:
bryan.zhang 2020-03-25 18:44:30 +08:00
parent f391a5cd50
commit 98cca28182
31 changed files with 150 additions and 389 deletions

View File

@ -28,22 +28,27 @@
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId> <artifactId>spring-beans</artifactId>
<optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId> <artifactId>spring-context</artifactId>
<optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId> <artifactId>spring-aop</artifactId>
<optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId> <artifactId>spring-expression</artifactId>
<optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId> <artifactId>spring-test</artifactId>
<optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>

View File

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>liteflow</artifactId>
<groupId>com.thebeastshop</groupId>
<version>2.2.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>liteflow-test-spring</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.thebeastshop</groupId>
<artifactId>liteflow-core</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,22 @@
package com.thebeastshop.flowtest;
import com.thebeastshop.liteflow.core.FlowExecutor;
import com.thebeastshop.liteflow.entity.data.Slot;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Runner {
private static final Logger log = LoggerFactory.getLogger(Runner.class);
private static ClassPathXmlApplicationContext context;
public static void main(String[] args) throws Throwable {
context = new ClassPathXmlApplicationContext(new String[]{"/applicationContext.xml"});
context.start();
log.info("启动成功");
FlowExecutor flowExecutor = context.getBean(FlowExecutor.class);
Slot slot = flowExecutor.execute("chain3", "it's a request");
System.out.println(slot);
}
}

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<context:component-scan base-package="com.thebeastshop.flowtest.components" />
<bean class="com.thebeastshop.liteflow.spring.ComponentScaner" depends-on="flowExecutor"/>
<bean id="flowExecutor" class="com.thebeastshop.liteflow.core.FlowExecutor">
<property name="rulePath">
<list>
<value>config/flow.xml</value>
</list>
</property>
</bean>
</beans>

View File

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2010-2011 The myBatis Team
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<configuration debug="false">
<!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径-->
<property name="APP_NAME" value="test"/>
<property name="LOG_HOME" value="./logs" />
<!-- 控制台输出 -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<!--格式化输出:%d表示日期%thread表示线程名%-5level级别从左显示5个字符宽度%msg日志消息%n是换行符-->
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
</encoder>
</appender>
<!-- 按照每天生成日志文件 -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${LOG_HOME}/${APP_NAME}.log</File>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!--日志文件输出的文件名-->
<FileNamePattern>${LOG_HOME}/${APP_NAME}.log.%d{yyyy-MM-dd}.%i.log</FileNamePattern>
<!--日志文件保留天数-->
<MaxHistory>30</MaxHistory>
<!--日志文件大小-->
<maxFileSize>1000MB</maxFileSize>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<!--格式化输出:%d表示日期%thread表示线程名%-5level级别从左显示5个字符宽度%msg日志消息%n是换行符-->
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
</encoder>
</appender>
<!-- 日志输出级别 -->
<root level="INFO">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</root>
</configuration>

View File

@ -1,62 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.thebeastshop</groupId>
<artifactId>liteflow-test</artifactId>
<version>1.0.0</version>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.thebeastshop</groupId>
<artifactId>liteflow-spring-boot-starter</artifactId>
<version>2.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,16 +0,0 @@
package com.thebeastshop.flowtest;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class FlowtestApplication {
public static void main(String[] args) {
try{
SpringApplication.run(FlowtestApplication.class, args);
}catch (Throwable t){
t.printStackTrace();
}
}
}

View File

@ -1,21 +0,0 @@
package com.thebeastshop.flowtest;
import com.thebeastshop.liteflow.core.FlowExecutor;
import com.thebeastshop.liteflow.entity.data.Slot;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@Component
public class TestFlow implements CommandLineRunner {
@Resource
private FlowExecutor flowExecutor;
@Override
public void run(String... args) throws Exception {
Slot slot = flowExecutor.execute("chain1", "it's a request");
System.out.println(slot);
}
}

View File

@ -1,131 +0,0 @@
package com.thebeastshop.flowtest.curator;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.recipes.cache.*;
import org.apache.curator.retry.RetryNTimes;
public class CuratorTest {
/** Zookeeper info */
private static final String ZK_ADDRESS = "123.206.92.144:2181,123.206.92.144:2182,123.206.92.144:2183";
private static final String ZK_PATH = "/zktest/a1/aa1";
public static void main(String[] args) throws Exception {
// 1.Connect to zk
CuratorFramework client = CuratorFrameworkFactory.newClient(
ZK_ADDRESS,
new RetryNTimes(10, 5000)
);
client.start();
checkNode(client);
// childNodeListen(client);
// removeNodeData(client);
// createNode(client);
// nodeListen(client);
//
// modifyNodeData(client);
System.in.read();
// getNodeData(client);
//
//
}
private static void checkNode(CuratorFramework client) throws Exception {
System.out.println(client.checkExists().forPath("/test"));
}
private static void createNode(CuratorFramework client) throws Exception {
String data1 = "nice to meet you";
print("create", ZK_PATH, data1);
client.create().
creatingParentsIfNeeded().
forPath(ZK_PATH, data1.getBytes());
}
private static void getNodeData(CuratorFramework client) throws Exception {
print("ls", "/");
print(client.getChildren().forPath("/"));
print("get", ZK_PATH);
print(client.getData().forPath(ZK_PATH));
}
private static void modifyNodeData(CuratorFramework client) throws Exception {
String data2 = "world for u";
print("set", ZK_PATH, data2);
client.setData().forPath(ZK_PATH, data2.getBytes());
print("get", ZK_PATH);
print(client.getData().forPath(ZK_PATH));
}
private static void removeNodeData(CuratorFramework client) throws Exception {
print("delete", "/zktest/dddd");
client.delete().forPath("/zktest/dddd");
print("ls", "/");
print(client.getChildren().forPath("/"));
}
private static void nodeListen(CuratorFramework client) throws Exception {
final NodeCache cache = new NodeCache(client,ZK_PATH);
cache.start();
cache.getListenable().addListener(new NodeCacheListener() {
@Override
public void nodeChanged() throws Exception {
byte[] res = cache.getCurrentData().getData();
System.out.println("data: " + new String(res));
}
});
}
private static void childNodeListen(CuratorFramework client) throws Exception {
final PathChildrenCache cache = new PathChildrenCache(client,"/zktest",true);
cache.start();
cache.getListenable().addListener(new PathChildrenCacheListener() {
@Override
public void childEvent(CuratorFramework curator, PathChildrenCacheEvent event) throws Exception {
switch (event.getType()) {
case CHILD_ADDED:
System.out.println("add:" + event.getData().getPath() + ":" + new String(event.getData().getData()));
break;
case CHILD_UPDATED:
System.out.println("update:" + event.getData().getPath() + ":" + new String(event.getData().getData()));
break;
case CHILD_REMOVED:
System.out.println("remove:" + event.getData().getPath() + ":" + new String(event.getData().getData()));
break;
default:
break;
}
}
});
}
private static void print(String... cmds) {
StringBuilder text = new StringBuilder("$ ");
for (String cmd : cmds) {
text.append(cmd).append(" ");
}
System.out.println(text.toString());
}
private static void print(Object result) {
System.out.println(
result instanceof byte[]
? new String((byte[]) result)
: result);
}
}

View File

@ -1,117 +0,0 @@
package com.thebeastshop.flowtest.curator;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.recipes.cache.*;
import org.apache.curator.retry.RetryNTimes;
public class CuratorTest2 {
/** Zookeeper info */
private static final String ZK_ADDRESS = "114.55.174.189:2181";
private static final String ZK_PATH = "/zktest/ffff";
public static void main(String[] args) throws Exception {
// 1.Connect to zk
CuratorFramework client = CuratorFrameworkFactory.newClient(
ZK_ADDRESS,
new RetryNTimes(10, 5000)
);
client.start();
// removeNodeData(client);
// createNode(client);
// nodeListen(client);
//
modifyNodeData(client);
}
private static void createNode(CuratorFramework client) throws Exception {
String data1 = "hello";
print("create", ZK_PATH, data1);
client.create().
creatingParentsIfNeeded().
forPath(ZK_PATH, data1.getBytes());
}
private static void getNodeData(CuratorFramework client) throws Exception {
print("ls", "/");
print(client.getChildren().forPath("/"));
print("get", ZK_PATH);
print(client.getData().forPath(ZK_PATH));
}
private static void modifyNodeData(CuratorFramework client) throws Exception {
String data2 = "world for u";
print("set", ZK_PATH, data2);
client.setData().forPath(ZK_PATH, data2.getBytes());
print("get", ZK_PATH);
print(client.getData().forPath(ZK_PATH));
}
private static void removeNodeData(CuratorFramework client) throws Exception {
print("delete", "/zktest/dddd");
client.delete().forPath("/zktest/dddd");
print("ls", "/");
print(client.getChildren().forPath("/"));
}
private static void nodeListen(CuratorFramework client) throws Exception {
final NodeCache cache = new NodeCache(client,ZK_PATH);
cache.start();
cache.getListenable().addListener(new NodeCacheListener() {
@Override
public void nodeChanged() throws Exception {
byte[] res = cache.getCurrentData().getData();
System.out.println("data: " + new String(res));
}
});
}
private static void childNodeListen(CuratorFramework client) throws Exception {
final PathChildrenCache cache = new PathChildrenCache(client,"/zktest",true);
cache.start();
cache.getListenable().addListener(new PathChildrenCacheListener() {
@Override
public void childEvent(CuratorFramework curator, PathChildrenCacheEvent event) throws Exception {
switch (event.getType()) {
case CHILD_ADDED:
System.out.println("add:" + event.getData().getPath() + ":" + new String(event.getData().getData()));
break;
case CHILD_UPDATED:
System.out.println("update:" + event.getData().getPath() + ":" + new String(event.getData().getData()));
break;
case CHILD_REMOVED:
System.out.println("remove:" + event.getData().getPath() + ":" + new String(event.getData().getData()));
break;
default:
break;
}
}
});
}
private static void print(String... cmds) {
StringBuilder text = new StringBuilder("$ ");
for (String cmd : cmds) {
text.append(cmd).append(" ");
}
System.out.println(text.toString());
}
private static void print(Object result) {
System.out.println(
result instanceof byte[]
? new String((byte[]) result)
: result);
}
}

View File

@ -1,23 +0,0 @@
package com.thebeastshop.flowtest.regex;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexTest {
public static void main(String[] args) {
String str = "192.168.1.1:2181,192.168.1.2:2182,192.168.1.3:2183";
List<String> list = new ArrayList<String>();
Pattern p = Pattern.compile("[\\w\\d][\\w\\d\\.]+\\:(\\d)+(\\,[\\w\\d][\\w\\d\\.]+\\:(\\d)+)*");
Matcher m = p.matcher(str);
while(m.find()){
list.add(m.group());
}
System.out.println(list.size());
System.out.println(list);
}
}

View File

@ -1 +0,0 @@
liteflow.ruleSource=config/flow.xml

View File

@ -1,16 +0,0 @@
package com.thebeastshop.flowtest;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class FlowtestApplicationTests {
@Test
public void contextLoads() {
}
}

View File

@ -139,8 +139,9 @@
<modules> <modules>
<module>liteflow-core</module> <module>liteflow-core</module>
<module>liteflow-test</module> <module>liteflow-spring-boot-starter</module>
<module>liteflow-spring-boot-starter</module> <module>liteflow-test-springboot</module>
<module>liteflow-test-spring</module>
</modules> </modules>
<!-- <!--