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