mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 20:22:07 +08:00
对异步线程的测试用例进行了重写
This commit is contained in:
@@ -105,12 +105,13 @@ public class AsyncNodeSpringbootTest extends BaseTest {
|
||||
Assert.assertEquals(TestException.class, response.getCause().getClass());
|
||||
}
|
||||
|
||||
//d g h并行,配置了any=true,其中d耗时3秒,g耗时1秒,其他都不设耗时
|
||||
//d g h并行,配置了any=true,其中d耗时1秒,g耗时0.5秒,其他都不设耗时
|
||||
//最终执行效果应该是h先返回,然后执行abc,最后gd
|
||||
//这里要注意的是,由于step是先加入,所以step的打印顺序并不是这样的。但是实际执行是正确的
|
||||
@Test
|
||||
public void testAsyncFlow8() throws Exception {
|
||||
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain8", "it's a base request");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertTrue(response.getSlot().getData("check").toString().startsWith("habc"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.yomahub.liteflow.test.asyncNode.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.entity.data.Slot;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
@@ -8,6 +9,16 @@ import org.springframework.stereotype.Component;
|
||||
public class ACmp extends NodeComponent {
|
||||
@Override
|
||||
public void process() {
|
||||
Slot slot = this.getSlot();
|
||||
synchronized (NodeComponent.class){
|
||||
if (slot.hasData("check")){
|
||||
String str = slot.getData("check");
|
||||
str += this.getNodeId();
|
||||
slot.setData("check", str);
|
||||
}else{
|
||||
slot.setData("check", this.getNodeId());
|
||||
}
|
||||
}
|
||||
System.out.println("Acomp executed!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.yomahub.liteflow.test.asyncNode.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.entity.data.Slot;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
@@ -8,6 +9,16 @@ import org.springframework.stereotype.Component;
|
||||
public class BCmp extends NodeComponent {
|
||||
@Override
|
||||
public void process() {
|
||||
Slot slot = this.getSlot();
|
||||
synchronized (NodeComponent.class){
|
||||
if (slot.hasData("check")){
|
||||
String str = slot.getData("check");
|
||||
str += this.getNodeId();
|
||||
slot.setData("check", str);
|
||||
}else{
|
||||
slot.setData("check", this.getNodeId());
|
||||
}
|
||||
}
|
||||
System.out.println("Bcomp executed!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.yomahub.liteflow.test.asyncNode.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.entity.data.Slot;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
@@ -8,6 +9,16 @@ import org.springframework.stereotype.Component;
|
||||
public class CCmp extends NodeComponent {
|
||||
@Override
|
||||
public void process() throws Exception {
|
||||
Slot slot = this.getSlot();
|
||||
synchronized (NodeComponent.class){
|
||||
if (slot.hasData("check")){
|
||||
String str = slot.getData("check");
|
||||
str += this.getNodeId();
|
||||
slot.setData("check", str);
|
||||
}else{
|
||||
slot.setData("check", this.getNodeId());
|
||||
}
|
||||
}
|
||||
System.out.println("Ccomp executed!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.yomahub.liteflow.test.asyncNode.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.entity.data.Slot;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
@@ -8,7 +9,17 @@ import org.springframework.stereotype.Component;
|
||||
public class DCmp extends NodeComponent {
|
||||
@Override
|
||||
public void process() throws Exception {
|
||||
Thread.sleep(3000);
|
||||
Thread.sleep(1000);
|
||||
Slot slot = this.getSlot();
|
||||
synchronized (NodeComponent.class){
|
||||
if (slot.hasData("check")){
|
||||
String str = slot.getData("check");
|
||||
str += this.getNodeId();
|
||||
slot.setData("check", str);
|
||||
}else{
|
||||
slot.setData("check", this.getNodeId());
|
||||
}
|
||||
}
|
||||
System.out.println("Dcomp executed!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.yomahub.liteflow.test.asyncNode.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.entity.data.Slot;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
@@ -9,7 +10,17 @@ public class GCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() throws Exception {
|
||||
Thread.sleep(1000);
|
||||
Thread.sleep(500);
|
||||
Slot slot = this.getSlot();
|
||||
synchronized (NodeComponent.class){
|
||||
if (slot.hasData("check")){
|
||||
String str = slot.getData("check");
|
||||
str += this.getNodeId();
|
||||
slot.setData("check", str);
|
||||
}else{
|
||||
slot.setData("check", this.getNodeId());
|
||||
}
|
||||
}
|
||||
System.out.println("Gcomp executed!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,29 @@
|
||||
package com.yomahub.liteflow.test.asyncNode.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.core.NodeCondComponent;
|
||||
import com.yomahub.liteflow.entity.data.Slot;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
|
||||
@Component("h")
|
||||
public class HCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() throws Exception {
|
||||
Slot slot = this.getSlot();
|
||||
synchronized (NodeComponent.class){
|
||||
if (slot.hasData("check")){
|
||||
String str = slot.getData("check");
|
||||
str += this.getNodeId();
|
||||
slot.setData("check", str);
|
||||
}else{
|
||||
slot.setData("check", this.getNodeId());
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Hcomp executed!");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user