Search in sources :

Example 1 with ClientException

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());
}
Also used : HttpRequest(com.netflix.client.http.HttpRequest) ServerStats(com.netflix.loadbalancer.ServerStats) HttpResponse(com.netflix.client.http.HttpResponse) ClientException(com.netflix.client.ClientException) URI(java.net.URI) Test(org.junit.Test)

Example 2 with ClientException

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());
}
Also used : HttpRequest(com.netflix.client.http.HttpRequest) ClientException(com.netflix.client.ClientException) URI(java.net.URI) Test(org.junit.Test)

Example 3 with ClientException

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());
}
Also used : HttpRequest(com.netflix.client.http.HttpRequest) MockHttpServer(com.netflix.client.testutil.MockHttpServer) Server(com.netflix.loadbalancer.Server) ServerStats(com.netflix.loadbalancer.ServerStats) HttpResponse(com.netflix.client.http.HttpResponse) ClientException(com.netflix.client.ClientException) URI(java.net.URI) Test(org.junit.Test)

Example 4 with ClientException

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());
}
Also used : HttpRequest(com.netflix.client.http.HttpRequest) ClientException(com.netflix.client.ClientException) URI(java.net.URI) Test(org.junit.Test)

Example 5 with ClientException

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);
}
Also used : HttpRequest(com.netflix.client.http.HttpRequest) ClientException(com.netflix.client.ClientException) URI(java.net.URI) Test(org.junit.Test)

Aggregations

ClientException (com.netflix.client.ClientException)24 Test (org.junit.Test)18 URI (java.net.URI)11 HttpRequest (com.netflix.client.http.HttpRequest)9 Server (com.netflix.loadbalancer.Server)8 ServerStats (com.netflix.loadbalancer.ServerStats)7 MockWebServer (com.google.mockwebserver.MockWebServer)6 ByteBuf (io.netty.buffer.ByteBuf)6 IClientConfig (com.netflix.client.config.IClientConfig)5 AvailabilityFilteringRule (com.netflix.loadbalancer.AvailabilityFilteringRule)5 BaseLoadBalancer (com.netflix.loadbalancer.BaseLoadBalancer)5 DummyPing (com.netflix.loadbalancer.DummyPing)5 HttpServer (com.sun.net.httpserver.HttpServer)4 IOException (java.io.IOException)4 AbortExecutionException (com.netflix.loadbalancer.reactive.ExecutionListener.AbortExecutionException)3 HttpResponse (com.netflix.client.http.HttpResponse)2 ExecutionListener (com.netflix.loadbalancer.reactive.ExecutionListener)2 Person (com.netflix.ribbon.test.resources.EmbeddedResources.Person)2 Pair (com.netflix.util.Pair)2 HttpClientResponse (io.reactivex.netty.protocol.http.client.HttpClientResponse)2