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);
}
Aggregations