修正单元测试

This commit is contained in:
dq-open-cloud 2022-01-24 10:23:38 +08:00
parent 87cae4a23e
commit b2ef9d6040
4 changed files with 22 additions and 44 deletions

View File

@ -8,36 +8,25 @@
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;
@Component("a")
@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<>());
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();
for (int i = 0; i < 100; i++) {
this.sendPrivateDeliveryData("b",i+1);
}
}
}

View File

@ -1,42 +1,28 @@
/**
* <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;
@Component("b")
@LiteflowComponent("b")
public class BCmp extends NodeComponent {
@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);
System.out.println("BCmp executed!");
Integer value = this.getPrivateDeliveryData();
Set<Integer> testSet = this.getSlot().getData("testSet");
testSet.add(value);
}
}

View File

@ -2,10 +2,17 @@
<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>

View File

@ -1,12 +1,8 @@
package com.yomahub.liteflow.test.customWhenThreadPool;
import com.yomahub.liteflow.builder.LiteFlowChainBuilder;
import com.yomahub.liteflow.builder.LiteFlowConditionBuilder;
import com.yomahub.liteflow.builder.LiteFlowNodeBuilder;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.enums.NodeTypeEnum;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.Assert;
import org.junit.Test;