bug #I4HZYN 使用When操作同一个Node时,会造成Tag标签的线程不安全

This commit is contained in:
bryan31
2021-12-09 13:37:05 +08:00
parent 106d59c65d
commit 21458d6c47
4 changed files with 45 additions and 4 deletions

View File

@@ -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;
@@ -15,6 +16,7 @@ import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import java.util.Set;
import java.util.function.Function;
/**
* springboot环境下隐私投递的测试
@@ -45,9 +47,15 @@ public class NodeTagSpringbootTest extends BaseTest {
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());
}
}
}

View File

@@ -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>());
}
}

View File

@@ -7,9 +7,12 @@
*/
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")
@@ -17,6 +20,8 @@ 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());
}
}

View File

@@ -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>