Search in sources :

Example 11 with ServiceCombServer

use of org.apache.servicecomb.loadbalance.ServiceCombServer in project incubator-servicecomb-java-chassis by apache.

the class IsolationDiscoveryFilterTest method discovery_isolate_error_instance.

@Test
public void discovery_isolate_error_instance() {
    ServiceCombServer server0 = ServiceCombLoadBalancerStats.INSTANCE.getServiceCombServer(data.get("i0"));
    for (int i = 0; i < 4; ++i) {
        ServiceCombLoadBalancerStats.INSTANCE.markFailure(server0);
    }
    DiscoveryTreeNode childNode = filter.discovery(discoveryContext, discoveryTreeNode);
    Map<String, MicroserviceInstance> childNodeData = childNode.data();
    Assert.assertThat(childNodeData.keySet(), Matchers.containsInAnyOrder("i0", "i1", "i2"));
    Assert.assertEquals(data.get("i0"), childNodeData.get("i0"));
    Assert.assertEquals(data.get("i1"), childNodeData.get("i1"));
    Assert.assertEquals(data.get("i2"), childNodeData.get("i2"));
    // by default 5 times continuous failure will cause isolation
    ServiceCombLoadBalancerStats.INSTANCE.markFailure(server0);
    Assert.assertFalse(ServiceCombLoadBalancerStats.INSTANCE.getServiceCombServerStats(server0).isIsolated());
    childNode = filter.discovery(discoveryContext, discoveryTreeNode);
    childNodeData = childNode.data();
    Assert.assertThat(childNodeData.keySet(), Matchers.containsInAnyOrder("i1", "i2"));
    Assert.assertEquals(data.get("i1"), childNodeData.get("i1"));
    Assert.assertEquals(data.get("i2"), childNodeData.get("i2"));
    Assert.assertTrue(ServiceCombLoadBalancerStats.INSTANCE.getServiceCombServerStats(server0).isIsolated());
}
Also used : ServiceCombServer(org.apache.servicecomb.loadbalance.ServiceCombServer) DiscoveryTreeNode(org.apache.servicecomb.registry.discovery.DiscoveryTreeNode) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) CacheEndpoint(org.apache.servicecomb.registry.cache.CacheEndpoint) Test(org.junit.Test)

Example 12 with ServiceCombServer

use of org.apache.servicecomb.loadbalance.ServiceCombServer in project incubator-servicecomb-java-chassis by apache.

the class IsolationDiscoveryFilterTest method discovery_keep_minIsolationTime.

@Test
public void discovery_keep_minIsolationTime() {
    ServiceCombServer server0 = ServiceCombLoadBalancerStats.INSTANCE.getServiceCombServer(data.get("i0"));
    ServiceCombLoadBalancerStats.INSTANCE.markIsolated(server0, true);
    ServiceCombLoadBalancerStats.INSTANCE.markSuccess(server0);
    DiscoveryTreeNode childNode = filter.discovery(discoveryContext, discoveryTreeNode);
    Map<String, MicroserviceInstance> childNodeData = childNode.data();
    Assert.assertThat(childNodeData.keySet(), Matchers.containsInAnyOrder("i1", "i2"));
    Assert.assertEquals(data.get("i1"), childNodeData.get("i1"));
    Assert.assertEquals(data.get("i2"), childNodeData.get("i2"));
    ServiceCombServerStats serviceCombServerStats = ServiceCombLoadBalancerStats.INSTANCE.getServiceCombServerStats(server0);
    Deencapsulation.setField(serviceCombServerStats, "isolatedTime", System.currentTimeMillis() - Configuration.INSTANCE.getMinIsolationTime(invocation.getMicroserviceName()) - 1);
    childNode = filter.discovery(discoveryContext, discoveryTreeNode);
    childNodeData = childNode.data();
    Assert.assertThat(childNodeData.keySet(), Matchers.containsInAnyOrder("i0", "i1", "i2"));
    Assert.assertEquals(data.get("i0"), childNodeData.get("i0"));
    Assert.assertEquals(data.get("i1"), childNodeData.get("i1"));
    Assert.assertEquals(data.get("i2"), childNodeData.get("i2"));
}
Also used : ServiceCombServer(org.apache.servicecomb.loadbalance.ServiceCombServer) DiscoveryTreeNode(org.apache.servicecomb.registry.discovery.DiscoveryTreeNode) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) ServiceCombServerStats(org.apache.servicecomb.loadbalance.ServiceCombServerStats) TestServiceCombServerStats(org.apache.servicecomb.loadbalance.TestServiceCombServerStats) Test(org.junit.Test)

Example 13 with ServiceCombServer

use of org.apache.servicecomb.loadbalance.ServiceCombServer in project incubator-servicecomb-java-chassis by apache.

the class IsolationDiscoveryFilterTest method discovery_not_try_isolated_instance_concurrently.

@Test
public void discovery_not_try_isolated_instance_concurrently() {
    ServiceCombServer server0 = ServiceCombLoadBalancerStats.INSTANCE.getServiceCombServer(data.get("i0"));
    ServiceCombServerStats serviceCombServerStats = ServiceCombLoadBalancerStats.INSTANCE.getServiceCombServerStats(server0);
    for (int i = 0; i < 5; ++i) {
        serviceCombServerStats.markFailure();
    }
    ServiceCombLoadBalancerStats.INSTANCE.markIsolated(server0, true);
    letIsolatedInstancePassSingleTestTime(serviceCombServerStats);
    Assert.assertTrue(ServiceCombServerStats.isolatedServerCanTry());
    // The first invocation can occupy the trying chance
    DiscoveryTreeNode childNode = filter.discovery(discoveryContext, discoveryTreeNode);
    Map<String, MicroserviceInstance> childNodeData = childNode.data();
    Assert.assertThat(childNodeData.keySet(), Matchers.containsInAnyOrder("i0", "i1", "i2"));
    Assert.assertEquals(data.get("i0"), childNodeData.get("i0"));
    Assert.assertEquals(data.get("i1"), childNodeData.get("i1"));
    Assert.assertEquals(data.get("i2"), childNodeData.get("i2"));
    Assert.assertFalse(ServiceCombServerStats.isolatedServerCanTry());
    // Other invocation cannot get trying chance concurrently
    childNode = filter.discovery(discoveryContext, discoveryTreeNode);
    childNodeData = childNode.data();
    Assert.assertThat(childNodeData.keySet(), Matchers.containsInAnyOrder("i1", "i2"));
    Assert.assertEquals(data.get("i1"), childNodeData.get("i1"));
    Assert.assertEquals(data.get("i2"), childNodeData.get("i2"));
    ServiceCombServerStats.checkAndReleaseTryingChance(// after the first invocation releases the trying chance
    invocation);
    // Other invocation can get the trying chance
    childNode = filter.discovery(discoveryContext, discoveryTreeNode);
    childNodeData = childNode.data();
    Assert.assertThat(childNodeData.keySet(), Matchers.containsInAnyOrder("i0", "i1", "i2"));
    Assert.assertEquals(data.get("i0"), childNodeData.get("i0"));
    Assert.assertEquals(data.get("i1"), childNodeData.get("i1"));
    Assert.assertEquals(data.get("i2"), childNodeData.get("i2"));
    Assert.assertFalse(ServiceCombServerStats.isolatedServerCanTry());
}
Also used : ServiceCombServer(org.apache.servicecomb.loadbalance.ServiceCombServer) DiscoveryTreeNode(org.apache.servicecomb.registry.discovery.DiscoveryTreeNode) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) ServiceCombServerStats(org.apache.servicecomb.loadbalance.ServiceCombServerStats) TestServiceCombServerStats(org.apache.servicecomb.loadbalance.TestServiceCombServerStats) CacheEndpoint(org.apache.servicecomb.registry.cache.CacheEndpoint) Test(org.junit.Test)

Example 14 with ServiceCombServer

use of org.apache.servicecomb.loadbalance.ServiceCombServer in project incubator-servicecomb-java-chassis by apache.

the class TestServerDiscoveryFilter method createEndpointNormal.

@Test
public void createEndpointNormal(@Injectable DiscoveryContext context, @Injectable Invocation invocation) {
    new Expectations(transportManager) {

        {
            transportManager.findTransport(anyString);
            result = trasport;
            context.getInputParameters();
            result = invocation;
            invocation.getMicroserviceName();
            result = "test";
        }
    };
    MicroserviceInstance instance = new MicroserviceInstance();
    instance.setInstanceId("0000001");
    ServiceCombServer server = (ServiceCombServer) filter.createEndpoint(context, Const.RESTFUL, "rest://localhost:8080", instance);
    Assert.assertSame(instance, server.getInstance());
    Assert.assertSame(trasport, server.getEndpoint().getTransport());
    Assert.assertEquals("rest://localhost:8080", server.getEndpoint().getEndpoint());
}
Also used : Expectations(mockit.Expectations) ServiceCombServer(org.apache.servicecomb.loadbalance.ServiceCombServer) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) Test(org.junit.Test)

Example 15 with ServiceCombServer

use of org.apache.servicecomb.loadbalance.ServiceCombServer in project incubator-servicecomb-java-chassis by apache.

the class TestServerDiscoveryFilter method createEndpoint_TransportNotExist.

@Test
public void createEndpoint_TransportNotExist() {
    new Expectations(transportManager) {

        {
            transportManager.findTransport(anyString);
            result = null;
        }
    };
    ServiceCombServer server = (ServiceCombServer) filter.createEndpoint(null, Const.RESTFUL, null, null);
    Assert.assertNull(server);
}
Also used : Expectations(mockit.Expectations) ServiceCombServer(org.apache.servicecomb.loadbalance.ServiceCombServer) Test(org.junit.Test)

Aggregations

ServiceCombServer (org.apache.servicecomb.loadbalance.ServiceCombServer)28 MicroserviceInstance (org.apache.servicecomb.registry.api.registry.MicroserviceInstance)14 Test (org.junit.Test)14 DiscoveryTreeNode (org.apache.servicecomb.registry.discovery.DiscoveryTreeNode)12 ServiceCombServerStats (org.apache.servicecomb.loadbalance.ServiceCombServerStats)10 CacheEndpoint (org.apache.servicecomb.registry.cache.CacheEndpoint)10 TestServiceCombServerStats (org.apache.servicecomb.loadbalance.TestServiceCombServerStats)8 Expectations (mockit.Expectations)4 Invocation (org.apache.servicecomb.core.Invocation)4 DiscoveryContext (org.apache.servicecomb.registry.discovery.DiscoveryContext)4 ConcurrentCompositeConfiguration (com.netflix.config.ConcurrentCompositeConfiguration)2 DynamicPropertyFactory (com.netflix.config.DynamicPropertyFactory)2 DynamicStringProperty (com.netflix.config.DynamicStringProperty)2 Future (io.vertx.core.Future)2 Handler (io.vertx.core.Handler)2 Buffer (io.vertx.core.buffer.Buffer)2 HttpClient (io.vertx.core.http.HttpClient)2 RequestOptions (io.vertx.core.http.RequestOptions)2 Router (io.vertx.ext.web.Router)2 RoutingContext (io.vertx.ext.web.RoutingContext)2