use of com.netflix.client.ClientException in project ribbon by Netflix.
the class RetryTest method testRetriesOnPostWithConnectException.
@Test
public void testRetriesOnPostWithConnectException() throws Exception {
URI localUrl = new URI("/status?code=503");
lb.setServersList(Lists.newArrayList(localServer));
HttpRequest request = HttpRequest.newBuilder().uri(localUrl).verb(Verb.POST).setRetriable(true).build();
try {
HttpResponse response = client.executeWithLoadBalancer(request, DefaultClientConfigImpl.getEmptyConfig().set(CommonClientConfigKey.MaxAutoRetriesNextServer, 2));
fail("Exception expected");
} catch (ClientException e) {
// NOPMD
}
ServerStats stats = lb.getLoadBalancerStats().getSingleServerStat(localServer);
assertEquals(3, stats.getSuccessiveConnectionFailureCount());
}
use of com.netflix.client.ClientException in project ribbon by Netflix.
the class RetryTest method testThrottled.
@Test
public void testThrottled() throws Exception {
URI localUrl = new URI("/status?code=503");
HttpRequest request = HttpRequest.newBuilder().uri(localUrl).build();
try {
client.executeWithLoadBalancer(request, DefaultClientConfigImpl.getEmptyConfig().set(CommonClientConfigKey.MaxAutoRetriesNextServer, 0));
fail("Exception expected");
} catch (ClientException e) {
assertNotNull(e);
}
assertEquals(1, lb.getLoadBalancerStats().getSingleServerStat(localServer).getSuccessiveConnectionFailureCount());
}
use of com.netflix.client.ClientException in project ribbon by Netflix.
the class RetryTest method testSuccessfulRetries.
@Test
public void testSuccessfulRetries() throws Exception {
lb.setServersList(Lists.newArrayList(new Server("localhost:12987"), new Server("localhost:12987"), localServer));
URI localUrl = new URI("/ok");
HttpRequest request = HttpRequest.newBuilder().uri(localUrl).queryParams("name", "ribbon").build();
try {
HttpResponse response = client.executeWithLoadBalancer(request, DefaultClientConfigImpl.getEmptyConfig().set(CommonClientConfigKey.MaxAutoRetriesNextServer, 2));
assertEquals(200, response.getStatus());
} catch (ClientException e) {
fail("Unexpected exception");
}
ServerStats stats = lb.getLoadBalancerStats().getSingleServerStat(new Server("localhost:12987"));
assertEquals(1, stats.getSuccessiveConnectionFailureCount());
}
use of com.netflix.client.ClientException in project ribbon by Netflix.
the class RetryTest method testThrottledWithRetrySameServer.
@Test
public void testThrottledWithRetrySameServer() throws Exception {
URI localUrl = new URI("/status?code=503");
HttpRequest request = HttpRequest.newBuilder().uri(localUrl).build();
try {
client.executeWithLoadBalancer(request, DefaultClientConfigImpl.getEmptyConfig().set(CommonClientConfigKey.MaxAutoRetries, 1).set(CommonClientConfigKey.MaxAutoRetriesNextServer, 0));
fail("Exception expected");
} catch (ClientException e) {
// NOPMD
}
assertEquals(2, lb.getLoadBalancerStats().getSingleServerStat(localServer).getSuccessiveConnectionFailureCount());
}
use of com.netflix.client.ClientException in project ribbon by Netflix.
the class RetryTest method testThrottledWithRetryNextServer.
@Test
public void testThrottledWithRetryNextServer() throws Exception {
int connectionCount = connectionPoolManager.getConnectionsInPool();
URI localUrl = new URI("/status?code=503");
HttpRequest request = HttpRequest.newBuilder().uri(localUrl).build();
try {
client.executeWithLoadBalancer(request, DefaultClientConfigImpl.getEmptyConfig().set(CommonClientConfigKey.MaxAutoRetriesNextServer, 2));
fail("Exception expected");
} catch (ClientException e) {
// NOPMD
}
assertEquals(3, lb.getLoadBalancerStats().getSingleServerStat(localServer).getSuccessiveConnectionFailureCount());
System.out.println("Initial connections count " + connectionCount);
System.out.println("Final connections count " + connectionPoolManager.getConnectionsInPool());
// should be no connection leak
assertTrue(connectionPoolManager.getConnectionsInPool() <= connectionCount + 1);
}
Aggregations