Search in sources :

Example 16 with Server

use of com.netflix.loadbalancer.Server in project incubator-servicecomb-java-chassis by apache.

the class TestLoadbalanceHandler method testSetIsolationFilter.

@Test
public void testSetIsolationFilter() {
    Invocation invocation = Mockito.mock(Invocation.class);
    Mockito.when(invocation.getMicroserviceName()).thenReturn("test");
    LoadbalanceHandler lbHandler = new LoadbalanceHandler();
    LoadBalancer myLB = new LoadBalancer("loadBalancerName", rule, "test");
    lbHandler.setIsolationFilter(myLB, "abc");
    Assert.assertEquals(1, myLB.getFilterSize());
    Mockito.when(invocation.getMicroserviceName()).thenReturn("abc");
    myLB = new LoadBalancer("loadBalancerName", rule, "test");
    lbHandler.setIsolationFilter(myLB, "abc");
    myLB.setInvocation(invocation);
    Assert.assertEquals(1, myLB.getFilterSize());
    Map<String, ServerListFilterExt> filters = Deencapsulation.getField(myLB, "filters");
    List<Server> servers = new ArrayList<>();
    servers.add(new Server(null));
    Assert.assertEquals(servers.size(), filters.get("org.apache.servicecomb.loadbalance.filter.IsolationServerListFilter").getFilteredListOfServers(servers).size());
}
Also used : Invocation(org.apache.servicecomb.core.Invocation) Server(com.netflix.loadbalancer.Server) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 17 with Server

use of com.netflix.loadbalancer.Server in project incubator-servicecomb-java-chassis by apache.

the class TestLoadbalanceHandler method send_failed.

@Test
public void send_failed() {
    CacheEndpoint cacheEndpoint = new CacheEndpoint("rest://localhost:8080", null);
    CseServer server = new CseServer(restTransport, cacheEndpoint);
    new MockUp<System>() {

        @Mock
        long currentTimeMillis() {
            return 123;
        }
    };
    new Expectations(loadBalancer) {

        {
            loadBalancer.chooseServer(invocation);
            result = server;
        }
    };
    int continuousFailureCount = server.getCountinuousFailureCount();
    sendResponse = Response.create(Status.BAD_REQUEST, "send failed");
    Holder<Throwable> result = new Holder<>();
    Deencapsulation.invoke(handler, "send", invocation, (AsyncResponse) resp -> {
        result.value = (Throwable) resp.getResult();
    }, loadBalancer);
    Assert.assertEquals(123, server.getLastVisitTime());
    Assert.assertEquals(1, loadBalancer.getLoadBalancerStats().getSingleServerStat(server).getSuccessiveConnectionFailureCount());
    Assert.assertEquals("InvocationException: code=400;msg=send failed", result.value.getMessage());
    Assert.assertEquals(continuousFailureCount + 1, server.getCountinuousFailureCount());
}
Also used : Expectations(mockit.Expectations) BeforeClass(org.junit.BeforeClass) Transport(org.apache.servicecomb.core.Transport) RegistryUtils(org.apache.servicecomb.serviceregistry.RegistryUtils) Expectations(mockit.Expectations) ArchaiusUtils(org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils) HashMap(java.util.HashMap) AsyncResponse(org.apache.servicecomb.swagger.invocation.AsyncResponse) SimpleTransactionControlFilter(org.apache.servicecomb.loadbalance.filter.SimpleTransactionControlFilter) ArrayList(java.util.ArrayList) AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) Map(java.util.Map) After(org.junit.After) Mock(mockit.Mock) Status(javax.ws.rs.core.Response.Status) InstanceCacheManager(org.apache.servicecomb.serviceregistry.cache.InstanceCacheManager) Response(org.apache.servicecomb.swagger.invocation.Response) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before) AfterClass(org.junit.AfterClass) MockUp(mockit.MockUp) Server(com.netflix.loadbalancer.Server) VersionedCache(org.apache.servicecomb.foundation.common.cache.VersionedCache) ConfigUtil(org.apache.servicecomb.config.ConfigUtil) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) Deencapsulation(mockit.Deencapsulation) DynamicPropertyFactory(com.netflix.config.DynamicPropertyFactory) Invocation(org.apache.servicecomb.core.Invocation) CacheEndpoint(org.apache.servicecomb.serviceregistry.cache.CacheEndpoint) Mockito(org.mockito.Mockito) List(java.util.List) MicroserviceInstance(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance) Rule(org.junit.Rule) ServiceRegistry(org.apache.servicecomb.serviceregistry.ServiceRegistry) IRule(com.netflix.loadbalancer.IRule) Holder(javax.xml.ws.Holder) TransportManager(org.apache.servicecomb.core.transport.TransportManager) Injectable(mockit.Injectable) CseContext(org.apache.servicecomb.core.CseContext) Assert(org.junit.Assert) Mocked(mockit.Mocked) CacheEndpoint(org.apache.servicecomb.serviceregistry.cache.CacheEndpoint) Holder(javax.xml.ws.Holder) MockUp(mockit.MockUp) CacheEndpoint(org.apache.servicecomb.serviceregistry.cache.CacheEndpoint) Test(org.junit.Test)

Example 18 with Server

use of com.netflix.loadbalancer.Server in project incubator-servicecomb-java-chassis by apache.

the class TestSessionSticknessRule method testServerWithoutTimeoutAndThreshold.

@Test
public void testServerWithoutTimeoutAndThreshold() {
    boolean status = true;
    SessionStickinessRule ss = new SessionStickinessRule();
    Object key = new Object();
    Server s = new Server("test");
    Deencapsulation.setField(ss, "lastServer", s);
    new MockUp<SessionStickinessRule>() {

        @Mock
        private boolean isTimeOut() {
            return false;
        }
    };
    new MockUp<SessionStickinessRule>() {

        @Mock
        private boolean isErrorThresholdMet() {
            return false;
        }
    };
    try {
        ss.choose(key);
    } catch (Exception e) {
        status = false;
    }
    Assert.assertTrue(status);
}
Also used : Server(com.netflix.loadbalancer.Server) MockUp(mockit.MockUp) Test(org.junit.Test)

Example 19 with Server

use of com.netflix.loadbalancer.Server in project incubator-servicecomb-java-chassis by apache.

the class TestSessionSticknessRule method testServerWithoutTimeoutAndWithThreshold.

@Test
public void testServerWithoutTimeoutAndWithThreshold() {
    boolean status = true;
    SessionStickinessRule ss = new SessionStickinessRule();
    Object key = new Object();
    Server s = new Server("test");
    Deencapsulation.setField(ss, "lastServer", s);
    new MockUp<SessionStickinessRule>() {

        @Mock
        private boolean isTimeOut() {
            return false;
        }
    };
    new MockUp<SessionStickinessRule>() {

        @Mock
        private boolean isErrorThresholdMet() {
            return true;
        }
    };
    try {
        ss.choose(key);
    } catch (Exception e) {
        status = false;
    }
    Assert.assertTrue(status);
}
Also used : Server(com.netflix.loadbalancer.Server) MockUp(mockit.MockUp) Test(org.junit.Test)

Example 20 with Server

use of com.netflix.loadbalancer.Server in project incubator-servicecomb-java-chassis by apache.

the class TestSessionSticknessRule method testServerWithActualServerObj.

@Test
public void testServerWithActualServerObj() {
    boolean status = true;
    SessionStickinessRule ss = new SessionStickinessRule();
    Object key = new Object();
    Server s = new Server("test");
    Deencapsulation.setField(ss, "lastServer", s);
    try {
        ss.choose(key);
    } catch (Exception e) {
        status = false;
    }
    Assert.assertTrue(status);
}
Also used : Server(com.netflix.loadbalancer.Server) Test(org.junit.Test)

Aggregations

Server (com.netflix.loadbalancer.Server)133 Test (org.junit.Test)98 ArrayList (java.util.ArrayList)40 ByteBuf (io.netty.buffer.ByteBuf)26 MockWebServer (com.google.mockwebserver.MockWebServer)25 BaseLoadBalancer (com.netflix.loadbalancer.BaseLoadBalancer)25 IClientConfig (com.netflix.client.config.IClientConfig)23 AvailabilityFilteringRule (com.netflix.loadbalancer.AvailabilityFilteringRule)20 DummyPing (com.netflix.loadbalancer.DummyPing)18 HttpServer (com.sun.net.httpserver.HttpServer)18 URI (java.net.URI)15 Invocation (org.apache.servicecomb.core.Invocation)14 DynamicServerListLoadBalancer (com.netflix.loadbalancer.DynamicServerListLoadBalancer)12 ServerStats (com.netflix.loadbalancer.ServerStats)12 Person (com.netflix.ribbon.test.resources.EmbeddedResources.Person)12 MockUp (mockit.MockUp)12 ClientException (com.netflix.client.ClientException)11 DefaultClientConfigImpl (com.netflix.client.config.DefaultClientConfigImpl)10 ExecutionListener (com.netflix.loadbalancer.reactive.ExecutionListener)9 HttpClientResponse (io.reactivex.netty.protocol.http.client.HttpClientResponse)9