8000 修复bug: NodeSelectorSlot只会记录初次调用记录 by lookingatstarts · Pull Request #3498 · alibaba/Sentinel · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

修复bug: NodeSelectorSlot只会记录初次调用记录 #3498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: 1.8
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,11 @@ public void entry(Context context, ResourceWrapper resourceWrapper, Object obj,
cacheMap.putAll(map);
cacheMap.put(context.getName(), node);
map = cacheMap;
// Build invocation tree
((DefaultNode) context.getLastNode()).addChild(node);
}

}
}

// Build invocation tree
((DefaultNode) context.getLastNode()).addChild(node);
context.setCurNode(node);
fireEntry(context, resourceWrapper, node, count, prioritized, args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@
import com.alibaba.csp.sentinel.context.ContextTestUtil;
import com.alibaba.csp.sentinel.context.ContextUtil;
import com.alibaba.csp.sentinel.context.NullContext;
import com.alibaba.csp.sentinel.node.DefaultNode;
import com.alibaba.csp.sentinel.node.Node;
import com.alibaba.csp.sentinel.slotchain.StringResourceWrapper;

import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand All @@ -20,6 +29,51 @@
*/
public class CtEntryTest {

@Test
public void testInvoiceTree(){
try{
ContextUtil.enter("invoice-tree");
DefaultNode entranceNode =(DefaultNode) Constants.ROOT.getChildList().stream()
.filter(e -> ((DefaultNode) e).getId().getName().equals("invoice-tree"))
.findFirst().get();
Entry a = SphU.entry("A");
Entry b = SphU.entry("B");
Entry c = SphU.entry("C");
c.exit();
b.exit();
a.exit();
// A -> B -> C
List<Node> childList = new ArrayList<>(entranceNode.getChildList());
assertEquals(1, childList.size());
DefaultNode nodeA = (DefaultNode) childList.get(0);
assertEquals("A", nodeA.getId().getName());
DefaultNode nodeB = (DefaultNode) new ArrayList<>(nodeA.getChildList()).get(0);
assertEquals("B", nodeB.getId().getName());
DefaultNode nodeC = (DefaultNode) new ArrayList<>(nodeB.getChildList()).get(0);
assertEquals("C", nodeC.getId().getName());
// A -> D
a = SphU.entry("A");
Entry d = SphU.entry("D");
d.exit();
a.exit();
childList = new ArrayList<>(entranceNode.getChildList());
assertEquals(1, childList.size());
nodeA = (DefaultNode) childList.get(0);
Map<String, DefaultNode> nodeAChildMap = nodeA.getChildList()
.stream().map(node -> (DefaultNode) node)
.collect(Collectors.toMap(node -> node.getId().getName(), node -> node));
assertNotNull(nodeAChildMap.get("B"));
assertNotNull(nodeAChildMap.get("D"));

}catch (BlockException ignore){

}finally {
ContextUtil.exit();
}

}


@Test
public void testExitNotMatchCurEntry() {
String contextName = "context-rpc";
Expand Down
0