feature #I9PVQ7 决策路由中增加namespace,可以执行指定命名空间的决策路由
This commit is contained in:
parent
ff88db092a
commit
3e3ab505d9
|
@ -0,0 +1,56 @@
|
||||||
|
package com.yomahub.liteflow.test.sqlroute;
|
||||||
|
|
||||||
|
import com.yomahub.liteflow.core.FlowExecutor;
|
||||||
|
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||||
|
import com.yomahub.liteflow.parser.sql.exception.ELSQLException;
|
||||||
|
import com.yomahub.liteflow.parser.sql.vo.SQLParserVO;
|
||||||
|
import com.yomahub.liteflow.property.LiteflowConfig;
|
||||||
|
import com.yomahub.liteflow.property.LiteflowConfigGetter;
|
||||||
|
import com.yomahub.liteflow.slot.DefaultContext;
|
||||||
|
import com.yomahub.liteflow.test.BaseTest;
|
||||||
|
import com.yomahub.liteflow.util.JsonUtil;
|
||||||
|
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.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.test.context.TestPropertySource;
|
||||||
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author tangkc
|
||||||
|
* @since 2.9.0
|
||||||
|
*/
|
||||||
|
@ExtendWith(SpringExtension.class)
|
||||||
|
@TestPropertySource(value = "classpath:/application-route.properties")
|
||||||
|
@SpringBootTest(classes = SQLRouteSpringbootTest.class)
|
||||||
|
@EnableAutoConfiguration
|
||||||
|
@ComponentScan({ "com.yomahub.liteflow.test.sqlroute.cmp" })
|
||||||
|
public class SQLRouteSpringbootTest extends BaseTest {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private FlowExecutor flowExecutor;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRoute1() {
|
||||||
|
List<LiteflowResponse> responseList = flowExecutor.executeRouteChain("ns", 15, DefaultContext.class);
|
||||||
|
LiteflowResponse response1 = responseList.stream().filter(liteflowResponse -> liteflowResponse.getChainId().equals("r_chain1")).findFirst().orElse(null);
|
||||||
|
Assertions.assertTrue(response1.isSuccess());
|
||||||
|
Assertions.assertEquals("a==>b==>c", response1.getExecuteStepStr());
|
||||||
|
LiteflowResponse response2 = responseList.stream().filter(liteflowResponse -> liteflowResponse.getChainId().equals("r_chain2")).findFirst().orElse(null);
|
||||||
|
Assertions.assertTrue(response2.isSuccess());
|
||||||
|
Assertions.assertEquals("c==>b==>a", response2.getExecuteStepStr());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
/**
|
||||||
|
* <p>Title: liteflow</p>
|
||||||
|
* <p>Description: 轻量级的组件式流程框架</p>
|
||||||
|
* @author Bryan.Zhang
|
||||||
|
* @email weenyc31@163.com
|
||||||
|
* @Date 2020/4/1
|
||||||
|
*/
|
||||||
|
package com.yomahub.liteflow.test.sqlroute.cmp;
|
||||||
|
|
||||||
|
import com.yomahub.liteflow.core.NodeComponent;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component("a")
|
||||||
|
public class ACmp extends NodeComponent {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void process() {
|
||||||
|
System.out.println("ACmp executed!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
/**
|
||||||
|
* <p>Title: liteflow</p>
|
||||||
|
* <p>Description: 轻量级的组件式流程框架</p>
|
||||||
|
* @author Bryan.Zhang
|
||||||
|
* @email weenyc31@163.com
|
||||||
|
* @Date 2020/4/1
|
||||||
|
*/
|
||||||
|
package com.yomahub.liteflow.test.sqlroute.cmp;
|
||||||
|
|
||||||
|
import com.yomahub.liteflow.core.NodeComponent;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component("b")
|
||||||
|
public class BCmp extends NodeComponent {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void process() {
|
||||||
|
System.out.println("BCmp executed!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
/**
|
||||||
|
* <p>Title: liteflow</p>
|
||||||
|
* <p>Description: 轻量级的组件式流程框架</p>
|
||||||
|
* @author Bryan.Zhang
|
||||||
|
* @email weenyc31@163.com
|
||||||
|
* @Date 2020/4/1
|
||||||
|
*/
|
||||||
|
package com.yomahub.liteflow.test.sqlroute.cmp;
|
||||||
|
|
||||||
|
import com.yomahub.liteflow.core.NodeComponent;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component("c")
|
||||||
|
public class CCmp extends NodeComponent {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void process() {
|
||||||
|
System.out.println("CCmp executed!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.yomahub.liteflow.test.sqlroute.cmp;
|
||||||
|
|
||||||
|
import com.yomahub.liteflow.annotation.LiteflowComponent;
|
||||||
|
import com.yomahub.liteflow.core.NodeBooleanComponent;
|
||||||
|
|
||||||
|
@LiteflowComponent("r1")
|
||||||
|
public class R1 extends NodeBooleanComponent {
|
||||||
|
@Override
|
||||||
|
public boolean processBoolean() throws Exception {
|
||||||
|
int testInt = this.getRequestData();
|
||||||
|
return testInt >= 10 && testInt <= 20;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.yomahub.liteflow.test.sqlroute.cmp;
|
||||||
|
|
||||||
|
import com.yomahub.liteflow.annotation.LiteflowComponent;
|
||||||
|
import com.yomahub.liteflow.core.NodeBooleanComponent;
|
||||||
|
|
||||||
|
@LiteflowComponent("r2")
|
||||||
|
public class R2 extends NodeBooleanComponent {
|
||||||
|
@Override
|
||||||
|
public boolean processBoolean() throws Exception {
|
||||||
|
int testInt = this.getRequestData();
|
||||||
|
return testInt > 100;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
liteflow.rule-source-ext-data={\
|
||||||
|
"url":"jdbc:h2:mem:test_db;MODE=MySQL",\
|
||||||
|
"driverClassName":"org.h2.Driver",\
|
||||||
|
"username":"root",\
|
||||||
|
"password":"123456",\
|
||||||
|
"applicationName":"demo",\
|
||||||
|
"chainTableName":"EL_TABLE",\
|
||||||
|
"chainApplicationNameField":"application_name",\
|
||||||
|
"chainNameField":"chain_name",\
|
||||||
|
"elDataField":"EL_DATA",\
|
||||||
|
"routeField":"route",\
|
||||||
|
"namespaceField":"namespace",\
|
||||||
|
"scriptTableName":"script_node_table",\
|
||||||
|
"scriptApplicationNameField":"application_name",\
|
||||||
|
"scriptIdField":"script_node_id",\
|
||||||
|
"scriptNameField":"script_node_name",\
|
||||||
|
"scriptDataField":"script_node_data",\
|
||||||
|
"scriptLanguageField":"script_language",\
|
||||||
|
"scriptTypeField":"script_node_type"\
|
||||||
|
}
|
||||||
|
|
||||||
|
spring.datasource.driver-class-name=org.h2.Driver
|
||||||
|
spring.datasource.url=jdbc:h2:mem:test_db;MODE=MySQL
|
||||||
|
spring.datasource.username=root
|
||||||
|
spring.datasource.password=123456
|
||||||
|
spring.datasource.schema=classpath:/sql/schema.sql
|
||||||
|
spring.datasource.data=classpath:/sql/data.sql
|
||||||
|
spring.datasource.platform=h2
|
|
@ -5,6 +5,8 @@ INSERT INTO EL_TABLE (APPLICATION_NAME,CHAIN_NAME,EL_DATA) values ('demo','chain
|
||||||
INSERT INTO EL_TABLE (APPLICATION_NAME,CHAIN_NAME,EL_DATA) values ('demo','chain3','IF(x0, THEN(a, b));');
|
INSERT INTO EL_TABLE (APPLICATION_NAME,CHAIN_NAME,EL_DATA) values ('demo','chain3','IF(x0, THEN(a, b));');
|
||||||
INSERT INTO EL_TABLE (APPLICATION_NAME,CHAIN_NAME,EL_DATA) values ('demo','<chain3>','IF(x0, THEN(a, b));');
|
INSERT INTO EL_TABLE (APPLICATION_NAME,CHAIN_NAME,EL_DATA) values ('demo','<chain3>','IF(x0, THEN(a, b));');
|
||||||
INSERT INTO EL_TABLE (APPLICATION_NAME,CHAIN_NAME,EL_DATA) values ('demo','chain4','IF(x2, IF(x0, THEN(a, b)));');
|
INSERT INTO EL_TABLE (APPLICATION_NAME,CHAIN_NAME,EL_DATA) values ('demo','chain4','IF(x2, IF(x0, THEN(a, b)));');
|
||||||
|
INSERT INTO EL_TABLE (APPLICATION_NAME,CHAIN_NAME,EL_DATA,ROUTE,NAMESPACE) values ('demo','r_chain1','THEN(a,b,c);','r1','ns');
|
||||||
|
INSERT INTO EL_TABLE (APPLICATION_NAME,CHAIN_NAME,EL_DATA,ROUTE,NAMESPACE) values ('demo','r_chain2','THEN(c,b,a);','OR(r1,r2)','ns');
|
||||||
|
|
||||||
DELETE FROM SCRIPT_NODE_TABLE;
|
DELETE FROM SCRIPT_NODE_TABLE;
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,8 @@ create table IF NOT EXISTS `EL_TABLE`
|
||||||
`application_name` varchar(32) NOT NULL,
|
`application_name` varchar(32) NOT NULL,
|
||||||
`chain_name` varchar(32) NOT NULL,
|
`chain_name` varchar(32) NOT NULL,
|
||||||
`el_data` varchar(1024) NOT NULL,
|
`el_data` varchar(1024) NOT NULL,
|
||||||
|
`route` varchar(1024),
|
||||||
|
`namespace` varchar(32),
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue