use of org.apache.servicecomb.registry.discovery.DiscoveryContext 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.DiscoveryContext 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);
}
use of org.apache.servicecomb.registry.discovery.DiscoveryContext in project java-chassis by ServiceComb.
the class LoadbalanceHandler method getOrCreateLoadBalancer.
protected LoadBalancer getOrCreateLoadBalancer(Invocation invocation) {
DiscoveryContext context = new DiscoveryContext();
context.setInputParameters(invocation);
VersionedCache serversVersionedCache = discoveryTree.discovery(context, invocation.getAppId(), invocation.getMicroserviceName(), invocation.getMicroserviceVersionRule());
invocation.addLocalContext(CONTEXT_KEY_SERVER_LIST, serversVersionedCache.data());
return loadBalancerMap.computeIfAbsent(serversVersionedCache.name(), name -> createLoadBalancer(invocation.getMicroserviceName()));
}
use of org.apache.servicecomb.registry.discovery.DiscoveryContext in project java-chassis by ServiceComb.
the class CommonHttpEdgeDispatcher method getOrCreateLoadBalancer.
protected LoadBalancer getOrCreateLoadBalancer(Invocation invocation, String microserviceName, String versionRule) {
DiscoveryContext context = new DiscoveryContext();
context.setInputParameters(invocation);
VersionedCache serversVersionedCache = discoveryTree.discovery(context, RegistrationManager.INSTANCE.getMicroservice().getAppId(), microserviceName, versionRule);
invocation.addLocalContext(LoadbalanceHandler.CONTEXT_KEY_SERVER_LIST, serversVersionedCache.data());
return loadBalancerMap.computeIfAbsent(microserviceName, name -> createLoadBalancer(microserviceName));
}
use of org.apache.servicecomb.registry.discovery.DiscoveryContext in project java-chassis by ServiceComb.
the class PriorityInstancePropertyDiscoveryFilterTest method executeTest.
private void executeTest(String selfProperty, Set<String> expectedMatchedKeys) {
Invocation invocation = new Invocation();
DiscoveryContext discoveryContext = new DiscoveryContext();
discoveryContext.setInputParameters(invocation);
self.getProperties().put(PROPERTY_KEY, selfProperty);
DiscoveryTreeNode parent = new DiscoveryTreeNode();
parent.name("parent");
parent.data(instances);
DiscoveryTreeNode node = filter.discovery(discoveryContext, parent);
Map<String, MicroserviceInstance> filterInstance = node.data();
assertThat(filterInstance.keySet()).containsAnyElementsOf(expectedMatchedKeys);
}
Aggregations