Search in sources :

Example 1 with ServerStats

use of com.netflix.loadbalancer.ServerStats 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 ServerStats

use of com.netflix.loadbalancer.ServerStats 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 3 with ServerStats

use of com.netflix.loadbalancer.ServerStats in project ribbon by Netflix.

the class RetryTest method testRetriesOnPost.

@Test
public void testRetriesOnPost() throws Exception {
    URI localUrl = new URI("/noresponse");
    HttpRequest request = HttpRequest.newBuilder().uri(localUrl).verb(Verb.POST).setRetriable(true).build();
    try {
        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) ClientException(com.netflix.client.ClientException) URI(java.net.URI) Test(org.junit.Test)

Example 4 with ServerStats

use of com.netflix.loadbalancer.ServerStats in project ribbon by Netflix.

the class NettyClientTest method testObservableWithMultipleServersWithOverrideRxConfig.

@Test
public void testObservableWithMultipleServersWithOverrideRxConfig() throws Exception {
    IClientConfig config = DefaultClientConfigImpl.getClientConfigWithDefaultValues().withProperty(CommonClientConfigKey.ConnectTimeout, "1000");
    HttpClientRequest<ByteBuf> request = HttpClientRequest.createGet("/testAsync/person");
    Server badServer = new Server("localhost:12345");
    Server goodServer = new Server("localhost:" + port);
    List<Server> servers = Lists.newArrayList(badServer, badServer, badServer, goodServer);
    BaseLoadBalancer lb = LoadBalancerBuilder.<Server>newBuilder().withRule(new AvailabilityFilteringRule()).withPing(new DummyPing()).buildFixedServerListLoadBalancer(servers);
    LoadBalancingHttpClient<ByteBuf, ByteBuf> lbObservables = RibbonTransport.newHttpClient(lb, config, new NettyHttpLoadBalancerErrorHandler(1, 3, true));
    HttpClientConfig rxconfig = HttpClientConfig.Builder.newDefaultConfig();
    Person person = getPersonObservable(lbObservables.submit(request, rxconfig)).toBlocking().single();
    assertEquals(EmbeddedResources.defaultPerson, person);
    ServerStats stats = lbObservables.getServerStats(badServer);
    // two requests to bad server because retry same server is set to 1
    assertEquals(4, stats.getTotalRequestsCount());
    assertEquals(0, stats.getActiveRequestsCount());
    assertEquals(4, stats.getSuccessiveConnectionFailureCount());
    stats = lbObservables.getServerStats(goodServer);
    assertEquals(1, stats.getTotalRequestsCount());
    assertEquals(0, stats.getActiveRequestsCount());
    assertEquals(0, stats.getSuccessiveConnectionFailureCount());
    final HttpClientListener listener = lbObservables.getListener();
    assertEquals(1, listener.getConnectionCount());
    waitUntilTrueOrTimeout(1000, new Func0<Boolean>() {

        @Override
        public Boolean call() {
            return listener.getPoolReleases() == 1;
        }
    });
}
Also used : HttpClientConfig(io.reactivex.netty.protocol.http.client.HttpClient.HttpClientConfig) HttpServer(com.sun.net.httpserver.HttpServer) Server(com.netflix.loadbalancer.Server) MockWebServer(com.google.mockwebserver.MockWebServer) BaseLoadBalancer(com.netflix.loadbalancer.BaseLoadBalancer) ByteBuf(io.netty.buffer.ByteBuf) HttpClientListener(io.reactivex.netty.servo.http.HttpClientListener) ServerStats(com.netflix.loadbalancer.ServerStats) DummyPing(com.netflix.loadbalancer.DummyPing) IClientConfig(com.netflix.client.config.IClientConfig) AvailabilityFilteringRule(com.netflix.loadbalancer.AvailabilityFilteringRule) Person(com.netflix.ribbon.test.resources.EmbeddedResources.Person) Test(org.junit.Test)

Example 5 with ServerStats

use of com.netflix.loadbalancer.ServerStats in project ribbon by Netflix.

the class NettyClientTest method testObservableWithRetrySameServer.

@Test
public void testObservableWithRetrySameServer() throws Exception {
    IClientConfig config = DefaultClientConfigImpl.getClientConfigWithDefaultValues().withProperty(CommonClientConfigKey.ConnectTimeout, "1000");
    HttpClientRequest<ByteBuf> request = HttpClientRequest.createGet("/testAsync/person");
    Server badServer = new Server("localhost:12345");
    Server goodServer = new Server("localhost:" + port);
    List<Server> servers = Lists.newArrayList(badServer, badServer, goodServer);
    BaseLoadBalancer lb = LoadBalancerBuilder.<Server>newBuilder().withRule(new AvailabilityFilteringRule()).withPing(new DummyPing()).buildFixedServerListLoadBalancer(servers);
    LoadBalancingHttpClient<ByteBuf, ByteBuf> lbObservables = RibbonTransport.newHttpClient(lb, config, new NettyHttpLoadBalancerErrorHandler(1, 0, true));
    Observable<Person> observableWithRetries = getPersonObservable(lbObservables.submit(request));
    ObserverWithLatch<Person> observer = new ObserverWithLatch<Person>();
    observableWithRetries.subscribe(observer);
    observer.await();
    assertNull(observer.obj);
    assertTrue(observer.error instanceof ClientException);
    ServerStats stats = lbObservables.getServerStats(badServer);
    // two requests to bad server because retry same server is set to 1
    assertEquals(2, stats.getTotalRequestsCount());
    assertEquals(0, stats.getActiveRequestsCount());
    stats = lbObservables.getServerStats(goodServer);
    assertEquals(0, stats.getTotalRequestsCount());
}
Also used : HttpServer(com.sun.net.httpserver.HttpServer) Server(com.netflix.loadbalancer.Server) MockWebServer(com.google.mockwebserver.MockWebServer) BaseLoadBalancer(com.netflix.loadbalancer.BaseLoadBalancer) ByteBuf(io.netty.buffer.ByteBuf) ServerStats(com.netflix.loadbalancer.ServerStats) DummyPing(com.netflix.loadbalancer.DummyPing) IClientConfig(com.netflix.client.config.IClientConfig) ClientException(com.netflix.client.ClientException) AvailabilityFilteringRule(com.netflix.loadbalancer.AvailabilityFilteringRule) Person(com.netflix.ribbon.test.resources.EmbeddedResources.Person) Test(org.junit.Test)

Aggregations

ServerStats (com.netflix.loadbalancer.ServerStats)15 Test (org.junit.Test)12 Server (com.netflix.loadbalancer.Server)10 MockWebServer (com.google.mockwebserver.MockWebServer)8 IClientConfig (com.netflix.client.config.IClientConfig)8 AvailabilityFilteringRule (com.netflix.loadbalancer.AvailabilityFilteringRule)8 BaseLoadBalancer (com.netflix.loadbalancer.BaseLoadBalancer)8 DummyPing (com.netflix.loadbalancer.DummyPing)8 Person (com.netflix.ribbon.test.resources.EmbeddedResources.Person)8 HttpServer (com.sun.net.httpserver.HttpServer)8 ByteBuf (io.netty.buffer.ByteBuf)8 ClientException (com.netflix.client.ClientException)7 MockResponse (com.google.mockwebserver.MockResponse)4 HttpRequest (com.netflix.client.http.HttpRequest)4 HttpClientListener (io.reactivex.netty.servo.http.HttpClientListener)4 URI (java.net.URI)4 RequestSpecificRetryHandler (com.netflix.client.RequestSpecificRetryHandler)3 RetryHandler (com.netflix.client.RetryHandler)3 HttpResponse (com.netflix.client.http.HttpResponse)2 MockHttpServer (com.netflix.client.testutil.MockHttpServer)1