mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 12:12:08 +08:00
测试
This commit is contained in:
@@ -13,6 +13,7 @@ import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.ReUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.yomahub.liteflow.entity.flow.Node;
|
||||
import com.yomahub.liteflow.enums.FlowParserTypeEnum;
|
||||
import com.yomahub.liteflow.exception.*;
|
||||
import com.yomahub.liteflow.parser.*;
|
||||
@@ -266,6 +267,11 @@ public class FlowExecutor {
|
||||
this.execute(chainId, param, slotClazz, slotIndex, true);
|
||||
}
|
||||
|
||||
public <T extends Slot> void invoke(String nodeId, Integer slotIndex) throws Exception {
|
||||
Node node = FlowBus.getNode(nodeId);
|
||||
node.execute(slotIndex);
|
||||
}
|
||||
|
||||
public DefaultSlot execute(String chainId) throws Exception {
|
||||
return this.execute(chainId, null, DefaultSlot.class, null, false);
|
||||
}
|
||||
|
||||
@@ -127,6 +127,15 @@ public abstract class AbsSlot implements Slot {
|
||||
}
|
||||
}
|
||||
|
||||
public <T> Queue<T> getPrivateDeliveryQueue(String nodeId){
|
||||
String privateDKey = PRIVATE_DELIVERY_PREFIX + nodeId;
|
||||
if(dataMap.containsKey(privateDKey)){
|
||||
return (Queue<T>) dataMap.get(privateDKey);
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public <T> T getPrivateDeliveryData(String nodeId){
|
||||
String privateDKey = PRIVATE_DELIVERY_PREFIX + nodeId;
|
||||
if(dataMap.containsKey(privateDKey)){
|
||||
|
||||
@@ -8,23 +8,36 @@
|
||||
package com.yomahub.liteflow.test.privateDelivery.cmp;
|
||||
|
||||
import com.yomahub.liteflow.annotation.LiteflowComponent;
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.entity.data.DefaultSlot;
|
||||
import com.yomahub.liteflow.entity.data.Slot;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
@LiteflowComponent("a")
|
||||
public class ACmp extends NodeComponent {
|
||||
|
||||
@Autowired
|
||||
private FlowExecutor flowExecutor;
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("ACmp executed!");
|
||||
Slot slot = getSlot();
|
||||
slot.setData("testSet", new HashSet<>());
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
this.sendPrivateDeliveryData("b",i+1);
|
||||
try {
|
||||
Queue<Integer> queue = new ConcurrentLinkedQueue<>();
|
||||
for (int i = 1; i <= 100; i++) {
|
||||
queue.add(i);
|
||||
}
|
||||
flowExecutor.execute2Resp("chain2", queue);
|
||||
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,42 @@
|
||||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
*
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
*/
|
||||
package com.yomahub.liteflow.test.privateDelivery.cmp;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.yomahub.liteflow.annotation.LiteflowComponent;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
|
||||
@LiteflowComponent("b")
|
||||
public class BCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("BCmp executed!");
|
||||
Integer value = this.getPrivateDeliveryData();
|
||||
Set<Integer> testSet = this.getSlot().getData("testSet");
|
||||
testSet.add(value);
|
||||
}
|
||||
@Override
|
||||
public boolean isAccess() {
|
||||
Queue<Integer> values = this.getSlot().getRequestData();
|
||||
System.out.println("BCmp executed! values.size" + values.size());
|
||||
if (CollUtil.isEmpty(values)) {
|
||||
return false;
|
||||
}
|
||||
Integer value = values.poll();
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
this.sendPrivateDeliveryData(this.getNodeId(), value);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
Integer value = getPrivateDeliveryData();
|
||||
System.out.println("BCmp executed!" + value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.privateDelivery.cmp;
|
||||
|
||||
import com.yomahub.liteflow.annotation.LiteflowComponent;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
|
||||
@LiteflowComponent("d")
|
||||
public class DCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("CCmp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,17 +2,10 @@
|
||||
<flow>
|
||||
<chain name="chain1">
|
||||
<then value="a"/>
|
||||
<!-- 100个b组件并发 -->
|
||||
<when value="b,b,b,b,b,b,b,b,b,b"/>
|
||||
<when value="b,b,b,b,b,b,b,b,b,b"/>
|
||||
<when value="b,b,b,b,b,b,b,b,b,b"/>
|
||||
<when value="b,b,b,b,b,b,b,b,b,b"/>
|
||||
<when value="b,b,b,b,b,b,b,b,b,b"/>
|
||||
<when value="b,b,b,b,b,b,b,b,b,b"/>
|
||||
<when value="b,b,b,b,b,b,b,b,b,b"/>
|
||||
<when value="b,b,b,b,b,b,b,b,b,b"/>
|
||||
<when value="b,b,b,b,b,b,b,b,b,b"/>
|
||||
<when value="b,b,b,b,b,b,b,b,b,b"/>
|
||||
<then value="c"/>
|
||||
</chain>
|
||||
<chain name="chain2">
|
||||
<pre value="d"/>
|
||||
<when value="b,b,b,b,b,b,b,b,b,b"/>
|
||||
</chain>
|
||||
</flow>
|
||||
Reference in New Issue
Block a user