use of org.apache.servicecomb.core.Invocation in project incubator-servicecomb-java-chassis by apache.
the class TestLoadbalanceHandler method send_success.
@Test
public void send_success() {
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;
}
};
server.incrementContinuousFailureCount();
sendResponse = Response.ok("success");
Holder<String> result = new Holder<>();
Deencapsulation.invoke(handler, "send", invocation, (AsyncResponse) resp -> {
result.value = resp.getResult();
}, loadBalancer);
Assert.assertEquals(123, server.getLastVisitTime());
Assert.assertEquals(1, loadBalancer.getLoadBalancerStats().getSingleServerStat(server).getActiveRequestsCount());
Assert.assertEquals("success", result.value);
Assert.assertEquals(0, server.getCountinuousFailureCount());
}
use of org.apache.servicecomb.core.Invocation 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());
}
use of org.apache.servicecomb.core.Invocation 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());
}
use of org.apache.servicecomb.core.Invocation in project incubator-servicecomb-java-chassis by apache.
the class TestIsolationServerListFilter method testGetFilteredListOfServers.
@Test
public void testGetFilteredListOfServers() {
Invocation invocation = Mockito.mock(Invocation.class);
CseServer testServer = Mockito.mock(CseServer.class);
Mockito.when(invocation.getMicroserviceName()).thenReturn("microserviceName");
Mockito.when(testServer.getLastVisitTime()).thenReturn(System.currentTimeMillis());
List<Server> serverList = new ArrayList<>();
serverList.add(testServer);
IsolationServerListFilter.setLoadBalancerStats(loadBalancerStats);
IsolationServerListFilter.setInvocation(invocation);
List<Server> returnedServerList = IsolationServerListFilter.getFilteredListOfServers(serverList);
Assert.assertEquals(returnedServerList.size(), 1);
loadBalancerStats.incrementNumRequests(testServer);
loadBalancerStats.incrementNumRequests(testServer);
loadBalancerStats.incrementNumRequests(testServer);
loadBalancerStats.incrementSuccessiveConnectionFailureCount(testServer);
returnedServerList = IsolationServerListFilter.getFilteredListOfServers(serverList);
Assert.assertEquals(returnedServerList.size(), 0);
}
use of org.apache.servicecomb.core.Invocation in project incubator-servicecomb-java-chassis by apache.
the class TestIsolationServerListFilter method testGetFilteredListOfServersOnContinuousFailureIsBelowThreshold.
@Test
public void testGetFilteredListOfServersOnContinuousFailureIsBelowThreshold() {
((AbstractConfiguration) DynamicPropertyFactory.getBackingConfigurationSource()).addProperty("cse.loadbalance.isolation.continuousFailureThreshold", "3");
Invocation invocation = Mockito.mock(Invocation.class);
CseServer testServer = Mockito.mock(CseServer.class);
Mockito.when(invocation.getMicroserviceName()).thenReturn("microserviceName");
Mockito.when(testServer.getCountinuousFailureCount()).thenReturn(2);
Mockito.when(testServer.getLastVisitTime()).thenReturn(System.currentTimeMillis());
for (int i = 0; i < 3; ++i) {
loadBalancerStats.incrementNumRequests(testServer);
}
List<Server> serverList = new ArrayList<>();
serverList.add(testServer);
IsolationServerListFilter.setLoadBalancerStats(loadBalancerStats);
IsolationServerListFilter.setInvocation(invocation);
List<Server> returnedServerList = IsolationServerListFilter.getFilteredListOfServers(serverList);
Assert.assertEquals(1, returnedServerList.size());
}
Aggregations