Search in sources :

Example 6 with Transport

use of org.apache.servicecomb.core.Transport in project incubator-servicecomb-java-chassis by apache.

the class TestSessionSticknessRule method testRuleFullOperation.

@Test
public void testRuleFullOperation() {
    SessionStickinessRule rule = new SessionStickinessRule();
    LoadBalancer mockedLb = mock(LoadBalancer.class);
    Transport transport = mock(Transport.class);
    CseServer mockedServer = new CseServer(transport, new CacheEndpoint("rest:127.0.0.1:8889", null));
    Object key = Mockito.mock(Object.class);
    LoadBalancerStats stats = mock(LoadBalancerStats.class);
    Mockito.when(mockedLb.getLoadBalancerStats()).thenReturn(stats);
    Deencapsulation.invoke(rule, "chooseServerWhenTimeout", key);
    mockedServer.setAlive(true);
    mockedServer.setReadyToServe(true);
    List<Server> allServers = Arrays.asList(mockedServer);
    when(mockedLb.getReachableServers()).thenReturn(allServers);
    when(mockedLb.getAllServers()).thenReturn(allServers);
    rule.setLoadBalancer(mockedLb);
    Assert.assertEquals(rule.getLoadBalancer(), mockedLb);
    Server s = rule.choose("default");
    Assert.assertEquals(s, mockedServer);
    s = rule.choose("default");
    Assert.assertEquals(s, mockedServer);
}
Also used : Server(com.netflix.loadbalancer.Server) CacheEndpoint(org.apache.servicecomb.serviceregistry.cache.CacheEndpoint) LoadBalancerStats(com.netflix.loadbalancer.LoadBalancerStats) Transport(org.apache.servicecomb.core.Transport) Test(org.junit.Test)

Aggregations

Transport (org.apache.servicecomb.core.Transport)6 ArrayList (java.util.ArrayList)3 List (java.util.List)3 CacheEndpoint (org.apache.servicecomb.serviceregistry.cache.CacheEndpoint)2 LoadBalancerStats (com.netflix.loadbalancer.LoadBalancerStats)1 Server (com.netflix.loadbalancer.Server)1 HashMap (java.util.HashMap)1 Endpoint (org.apache.servicecomb.core.Endpoint)1 Microservice (org.apache.servicecomb.serviceregistry.api.registry.Microservice)1 Test (org.junit.Test)1