bug #I4LV63 在2.6.5版本中多线程tag取值中,xml没有问题,而json形式有问题

This commit is contained in:
bryan31
2021-12-09 18:47:29 +08:00
parent 21458d6c47
commit c425997b3c
6 changed files with 89 additions and 6 deletions

View File

@@ -170,7 +170,7 @@ public abstract class JsonFlowParser extends FlowParser {
for (RegexNodeEntity realItem : regexEntity.getRealItemArray()) {
if (FlowBus.containNode(realItem.getId())) {
Node condNode = FlowBus.copyNode(realItem.getId());
node.setTag(realItem.getTag());
condNode.setTag(realItem.getTag());
node.setCondNode(condNode.getId(), condNode);
} else if (hasChain(flowJsonObjectList, realItem.getId())) {
Chain chain = FlowBus.getChain(realItem.getId());

View File

@@ -15,8 +15,6 @@ import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import java.util.Set;
import java.util.function.Function;
/**
* springboot环境下隐私投递的测试
@@ -24,11 +22,11 @@ import java.util.function.Function;
* @since 2.5.0
*/
@RunWith(SpringRunner.class)
@TestPropertySource(value = "classpath:/tag/application.properties")
@SpringBootTest(classes = NodeTagSpringbootTest.class)
@TestPropertySource(value = "classpath:/tag/application-json.properties")
@SpringBootTest(classes = NodeTagSpringbootJsonTest.class)
@EnableAutoConfiguration
@ComponentScan({"com.yomahub.liteflow.test.tag.cmp"})
public class NodeTagSpringbootTest extends BaseTest {
public class NodeTagSpringbootJsonTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;

View File

@@ -0,0 +1,59 @@
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;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
/**
* springboot环境下隐私投递的测试
* @author Bryan.Zhang
* @since 2.5.0
*/
@RunWith(SpringRunner.class)
@TestPropertySource(value = "classpath:/tag/application-xml.properties")
@SpringBootTest(classes = NodeTagSpringbootXmlTest.class)
@EnableAutoConfiguration
@ComponentScan({"com.yomahub.liteflow.test.tag.cmp"})
public class NodeTagSpringbootXmlTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
@Test
public void testTag1() throws Exception{
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("123",response.getSlot().getData("test"));
}
@Test
public void testTag2() throws Exception{
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain2", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("a==>a==>a==>c==>e", response.getSlot().printStep());
}
//测试多线程when情况下的tag取值是否正确
//这里循环多次的原因是因为when多线程有时候因为凑巧可能正确。所以多次情况下在2.6.4版本肯定出错
@Test
public void testTag3() throws Exception{
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 @@
liteflow.rule-source=tag/flow.json

View File

@@ -0,0 +1,25 @@
{
"flow": {
"chain": [
{
"name": "chain1",
"condition": [
{"type": "then", "value": "a[1],a[2],a[3]"}
]
},
{
"name": "chain2",
"condition": [
{"type": "then", "value": "a[1],a[2],a[3],c[2](d[5]|e[6])"}
]
},
{
"name": "chain3",
"condition": [
{"type": "then", "value": "b1"},
{"type": "when", "value": "b[1],b[2],b[3]"}
]
}
]
}
}