use of org.apache.servicecomb.registry.discovery.DiscoveryTreeNode in project java-chassis by ServiceComb.
the class TestDiscoveryTree method filterRerun.
@Test
public void filterRerun() {
parent.name("1.0.0-2.0.0");
discoveryTree.addFilter(new DiscoveryFilterForTest("g1") {
@Override
public DiscoveryTreeNode discovery(DiscoveryContext context, DiscoveryTreeNode parent) {
if (context.getContextParameter("step") == null) {
context.pushRerunFilter();
context.putContextParameter("step", 1);
return new DiscoveryTreeNode().name(groupName).data("first");
}
return new DiscoveryTreeNode().name(groupName).data("second");
}
});
discoveryTree.addFilter(new DiscoveryFilterForTest(null) {
@Override
public DiscoveryTreeNode discovery(DiscoveryContext context, DiscoveryTreeNode parent) {
if ("first".equals(parent.data())) {
return new DiscoveryTreeNode();
}
return new DiscoveryTreeNode().data(parent.data());
}
});
result = discoveryTree.discovery(context, parent);
Assert.assertEquals("second", result.data());
}
use of org.apache.servicecomb.registry.discovery.DiscoveryTreeNode in project java-chassis by ServiceComb.
the class TestDiscoveryTree method isMatch_yes.
@Test
public void isMatch_yes() {
parent.cacheVersion(1);
Assert.assertTrue(discoveryTree.isMatch(new DiscoveryTreeNode().cacheVersion(1), parent));
}
use of org.apache.servicecomb.registry.discovery.DiscoveryTreeNode in project java-chassis by ServiceComb.
the class TestDiscoveryTree method getOrCreateRoot_match.
@Test
public void getOrCreateRoot_match() {
Deencapsulation.setField(discoveryTree, "root", parent);
DiscoveryTreeNode root = discoveryTree.getOrCreateRoot(parent);
Assert.assertSame(parent, root);
}
use of org.apache.servicecomb.registry.discovery.DiscoveryTreeNode in project java-chassis by ServiceComb.
the class TestDiscoveryTree method getOrCreateRoot_expired.
@Test
public void getOrCreateRoot_expired() {
Deencapsulation.setField(discoveryTree, "root", parent);
VersionedCache inputCache = new VersionedCache().cacheVersion(parent.cacheVersion() + 1);
DiscoveryTreeNode root = discoveryTree.getOrCreateRoot(inputCache);
Assert.assertEquals(inputCache.cacheVersion(), root.cacheVersion());
Assert.assertSame(Deencapsulation.getField(discoveryTree, "root"), root);
}
use of org.apache.servicecomb.registry.discovery.DiscoveryTreeNode in project java-chassis by ServiceComb.
the class TestDiscoveryTree method discovery_filterReturnNull.
@Test
public void discovery_filterReturnNull(@Mocked InstanceCacheManager instanceCacheManager) {
new Expectations(DiscoveryManager.class) {
{
DiscoveryManager.INSTANCE.getInstanceCacheManager();
result = instanceCacheManager;
instanceCacheManager.getOrCreateVersionedCache(anyString, anyString, anyString);
result = parent;
}
};
DiscoveryFilter filter = new DiscoveryFilter() {
@Override
public int getOrder() {
return 0;
}
@Override
public DiscoveryTreeNode discovery(DiscoveryContext context, DiscoveryTreeNode parent) {
return null;
}
};
discoveryTree.addFilter(filter);
expectedException.expect(ServiceCombException.class);
expectedException.expectMessage(Matchers.is(filter.getClass().getName() + " discovery return null."));
result = discoveryTree.discovery(context, null, null, null);
}
Aggregations