use of com.alibaba.csp.sentinel.node.EntranceNode in project Sentinel by alibaba.
the class NodeSelectorTest method testMultipleEntrance.
@Test
public void testMultipleEntrance() throws Exception {
final String firstEntry = "entry_multiple_one";
final String anotherEntry = "entry_multiple_another";
final String resName = "nodeA";
Node firstNode, anotherNode;
ContextUtil.enter(firstEntry);
Entry nodeA = SphU.entry(resName);
firstNode = ContextUtil.getContext().getCurNode();
if (nodeA != null) {
nodeA.exit();
}
ContextUtil.exit();
ContextUtil.enter(anotherEntry);
nodeA = SphU.entry(resName);
anotherNode = ContextUtil.getContext().getCurNode();
if (nodeA != null) {
nodeA.exit();
}
assertNotSame(firstNode, anotherNode);
for (Node node : Constants.ROOT.getChildList()) {
EntranceNode firstEntrance = (EntranceNode) node;
if (firstEntrance.getId().getName().equals(firstEntry)) {
assertEquals(1, firstEntrance.getChildList().size());
for (Node child : firstEntrance.getChildList()) {
assertEquals(resName, ((DefaultNode) child).getId().getName());
}
} else if (firstEntrance.getId().getName().equals(anotherEntry)) {
assertEquals(1, firstEntrance.getChildList().size());
for (Node child : firstEntrance.getChildList()) {
assertEquals(resName, ((DefaultNode) child).getId().getName());
}
} else {
System.out.println("Multiple entries: " + firstEntrance.getId().getName());
}
}
ContextUtil.exit();
}
use of com.alibaba.csp.sentinel.node.EntranceNode in project Sentinel by alibaba.
the class NodeSelectorTest method testSingleEntrance.
@Test
public void testSingleEntrance() throws Exception {
final String contextName = "entry_SingleEntrance";
ContextUtil.enter(contextName);
EntranceNode entranceNode = null;
for (Node node : Constants.ROOT.getChildList()) {
entranceNode = (EntranceNode) node;
if (entranceNode.getId().getName().equals(contextName)) {
break;
} else {
System.out.println("Single entry: " + entranceNode.getId().getName());
}
}
assertNotNull(entranceNode);
assertTrue(entranceNode.getId().getName().equalsIgnoreCase(contextName));
final String resName = "nodeA";
Entry nodeA = SphU.entry(resName);
assertNotNull(ContextUtil.getContext().getCurNode());
assertEquals(resName, ((DefaultNode) ContextUtil.getContext().getCurNode()).getId().getName());
boolean hasNode = false;
for (Node node : entranceNode.getChildList()) {
if (((DefaultNode) node).getId().getName().equals(resName)) {
hasNode = true;
}
}
assertTrue(hasNode);
if (nodeA != null) {
nodeA.exit();
}
ContextUtil.exit();
}
use of com.alibaba.csp.sentinel.node.EntranceNode in project Sentinel by alibaba.
the class SentinelJaxRsQuarkusAdapterTest method testAsyncGetHello.
@Test
public void testAsyncGetHello() {
String url = "/test/async-hello";
String resourceName = "GET:" + url;
Response response = given().get(url);
response.then().statusCode(200).body(equalTo(HELLO_STR));
ClusterNode cn = ClusterBuilderSlot.getClusterNode(resourceName);
assertNotNull(cn);
assertEquals(1, cn.passQps(), 0.01);
String context = "";
for (Node n : Constants.ROOT.getChildList()) {
if (n instanceof EntranceNode) {
String id = ((EntranceNode) n).getId().getName();
if (url.equals(id)) {
context = ((EntranceNode) n).getId().getName();
}
}
}
assertEquals("", context);
}
Aggregations