Skip to content

Commit

Permalink
bug #I4HZYN 使用When操作同一个Node时,会造成Tag标签的线程不安全
Browse files Browse the repository at this point in the history
  • Loading branch information
bryan31 committed Dec 9, 2021
1 parent 106d59c commit 21458d6
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.yomahub.liteflow.test.tag;

import cn.hutool.core.collection.ConcurrentHashSet;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
Expand All @@ -15,6 +16,7 @@

import javax.annotation.Resource;
import java.util.Set;
import java.util.function.Function;

/**
* springboot环境下隐私投递的测试
Expand Down Expand Up @@ -45,9 +47,15 @@ public void testTag2() throws Exception{
Assert.assertEquals("a==>a==>a==>c==>e", response.getSlot().printStep());
}

//测试多线程when情况下的tag取值是否正确
//这里循环多次的原因是,因为when多线程,有时候因为凑巧,可能正确。所以多次情况下在2.6.4版本肯定出错
@Test
public void testTag3() throws Exception{
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain3", "arg");
Assert.assertTrue(response.isSuccess());
for (int i = 0; i < 50; i++) {
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain3", "arg");
Assert.assertTrue(response.isSuccess());
ConcurrentHashSet<String> testSet = response.getSlot().getData("test");
Assert.assertEquals(3, testSet.size());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.tag.cmp;

import cn.hutool.core.collection.ConcurrentHashSet;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.entity.data.Slot;

import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

@LiteflowComponent("b1")
public class B1Cmp extends NodeComponent {

@Override
public void process() {
Slot slot = this.getSlot();
slot.setData("test",new ConcurrentHashSet<String>());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@
*/
package com.yomahub.liteflow.test.tag.cmp;

import cn.hutool.core.collection.ConcurrentHashSet;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.entity.data.Slot;

import java.util.HashSet;
import java.util.Set;

@LiteflowComponent("b")
public class BCmp extends NodeComponent {

@Override
public void process() {
System.out.println(this.getTag());
Slot slot = this.getSlot();
ConcurrentHashSet<String> testSet = slot.getData("test");
testSet.add(this.getTag());
}
}
3 changes: 2 additions & 1 deletion liteflow-testcase-springboot/src/test/resources/tag/flow.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
</chain>

<chain name="chain3">
<when value="b[1],b[2],b[3],b"/>
<then value="b1"/>
<when value="b[1],b[2],b[3]"/>
</chain>
</flow>

0 comments on commit 21458d6

Please sign in to comment.