Search in sources :

Example 6 with DiscoveryTreeNode

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());
}
Also used : DiscoveryContext(org.apache.servicecomb.registry.discovery.DiscoveryContext) DiscoveryTreeNode(org.apache.servicecomb.registry.discovery.DiscoveryTreeNode) Test(org.junit.Test)

Example 7 with DiscoveryTreeNode

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));
}
Also used : DiscoveryTreeNode(org.apache.servicecomb.registry.discovery.DiscoveryTreeNode) Test(org.junit.Test)

Example 8 with DiscoveryTreeNode

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);
}
Also used : DiscoveryTreeNode(org.apache.servicecomb.registry.discovery.DiscoveryTreeNode) Test(org.junit.Test)

Example 9 with DiscoveryTreeNode

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);
}
Also used : VersionedCache(org.apache.servicecomb.foundation.common.cache.VersionedCache) DiscoveryTreeNode(org.apache.servicecomb.registry.discovery.DiscoveryTreeNode) Test(org.junit.Test)

Example 10 with DiscoveryTreeNode

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);
}
Also used : Expectations(mockit.Expectations) DiscoveryContext(org.apache.servicecomb.registry.discovery.DiscoveryContext) DiscoveryTreeNode(org.apache.servicecomb.registry.discovery.DiscoveryTreeNode) DiscoveryFilter(org.apache.servicecomb.registry.discovery.DiscoveryFilter) Test(org.junit.Test)

Aggregations

DiscoveryTreeNode (org.apache.servicecomb.registry.discovery.DiscoveryTreeNode)33 Test (org.junit.Test)25 MicroserviceInstance (org.apache.servicecomb.registry.api.registry.MicroserviceInstance)20 HashMap (java.util.HashMap)11 Invocation (org.apache.servicecomb.core.Invocation)11 ArrayList (java.util.ArrayList)6 NonSwaggerInvocation (org.apache.servicecomb.core.NonSwaggerInvocation)6 Transport (org.apache.servicecomb.core.Transport)6 TransportManager (org.apache.servicecomb.core.transport.TransportManager)6 ServiceCombServer (org.apache.servicecomb.loadbalance.ServiceCombServer)6 InstanceCacheManager (org.apache.servicecomb.registry.cache.InstanceCacheManager)6 MicroserviceMeta (org.apache.servicecomb.core.definition.MicroserviceMeta)5 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)5 DataCenterInfo (org.apache.servicecomb.registry.api.registry.DataCenterInfo)5 DiscoveryContext (org.apache.servicecomb.registry.discovery.DiscoveryContext)5 InvocationRuntimeType (org.apache.servicecomb.core.definition.InvocationRuntimeType)4 SchemaMeta (org.apache.servicecomb.core.definition.SchemaMeta)4 ReferenceConfig (org.apache.servicecomb.core.provider.consumer.ReferenceConfig)4 ServiceCombServerStats (org.apache.servicecomb.loadbalance.ServiceCombServerStats)4 TestServiceCombServerStats (org.apache.servicecomb.loadbalance.TestServiceCombServerStats)4