Search in sources :

Example 21 with ClientException

use of com.netflix.client.ClientException in project ribbon by Netflix.

the class NettyClientTest method testLoadBalancerThrottle.

@Test
public void testLoadBalancerThrottle() throws Exception {
    HttpClientRequest<ByteBuf> request = HttpClientRequest.createGet("/testAsync/throttle");
    IClientConfig config = DefaultClientConfigImpl.getClientConfigWithDefaultValues().set(IClientConfigKey.Keys.MaxAutoRetriesNextServer, 1).set(IClientConfigKey.Keys.OkToRetryOnAllOperations, true);
    BaseLoadBalancer lb = new BaseLoadBalancer(new DummyPing(), new AvailabilityFilteringRule());
    LoadBalancingHttpClient<ByteBuf, ByteBuf> lbObservables = RibbonTransport.newHttpClient(lb, config);
    Server server = new Server(host, port);
    lb.setServersList(Lists.newArrayList(server, server, server));
    Observable<HttpClientResponse<ByteBuf>> response = lbObservables.submit(request);
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicReference<Throwable> error = new AtomicReference<Throwable>();
    response.subscribe(new Action1<HttpClientResponse<ByteBuf>>() {

        @Override
        public void call(HttpClientResponse<ByteBuf> t1) {
            System.err.println("Get response: " + t1.getStatus().code());
            latch.countDown();
        }
    }, new Action1<Throwable>() {

        @Override
        public void call(Throwable t1) {
            error.set(t1);
            latch.countDown();
        }
    }, new Action0() {

        @Override
        public void call() {
            Thread.dumpStack();
            latch.countDown();
        }
    });
    latch.await();
    assertTrue(error.get() instanceof ClientException);
    ClientException ce = (ClientException) error.get();
    assertTrue(ce.toString(), ce.getErrorType() == ClientException.ErrorType.NUMBEROF_RETRIES_NEXTSERVER_EXCEEDED);
    assertEquals(2, lbObservables.getServerStats(server).getSuccessiveConnectionFailureCount());
}
Also used : Action0(rx.functions.Action0) HttpServer(com.sun.net.httpserver.HttpServer) Server(com.netflix.loadbalancer.Server) MockWebServer(com.google.mockwebserver.MockWebServer) BaseLoadBalancer(com.netflix.loadbalancer.BaseLoadBalancer) AtomicReference(java.util.concurrent.atomic.AtomicReference) ByteBuf(io.netty.buffer.ByteBuf) CountDownLatch(java.util.concurrent.CountDownLatch) DummyPing(com.netflix.loadbalancer.DummyPing) HttpClientResponse(io.reactivex.netty.protocol.http.client.HttpClientResponse) IClientConfig(com.netflix.client.config.IClientConfig) ClientException(com.netflix.client.ClientException) AvailabilityFilteringRule(com.netflix.loadbalancer.AvailabilityFilteringRule) Test(org.junit.Test)

Example 22 with ClientException

use of com.netflix.client.ClientException in project feign by OpenFeign.

the class RibbonClient method execute.

@Override
public Response execute(Request request, Request.Options options) throws IOException {
    try {
        URI asUri = URI.create(request.url());
        String clientName = asUri.getHost();
        URI uriWithoutHost = cleanUrl(request.url(), clientName);
        LBClient.RibbonRequest ribbonRequest = new LBClient.RibbonRequest(delegate, request, uriWithoutHost);
        return lbClient(clientName).executeWithLoadBalancer(ribbonRequest, new FeignOptionsClientConfig(options)).toResponse();
    } catch (ClientException e) {
        propagateFirstIOException(e);
        throw new RuntimeException(e);
    }
}
Also used : ClientException(com.netflix.client.ClientException) URI(java.net.URI)

Example 23 with ClientException

use of com.netflix.client.ClientException in project feign by OpenFeign.

the class PropagateFirstIOExceptionTest method propagatesDoubleNestedIOE.

/**
   * Happened in practice; a blocking observable wrapped the connect exception in a runtime
   * exception
   */
@Test
public void propagatesDoubleNestedIOE() throws IOException {
    thrown.expect(ConnectException.class);
    RibbonClient.propagateFirstIOException(new ClientException(new RuntimeException(new ConnectException())));
}
Also used : ClientException(com.netflix.client.ClientException) ConnectException(java.net.ConnectException) Test(org.junit.Test)

Example 24 with ClientException

use of com.netflix.client.ClientException in project feign by OpenFeign.

the class PropagateFirstIOExceptionTest method propagatesNestedIOE.

@Test
public void propagatesNestedIOE() throws IOException {
    thrown.expect(IOException.class);
    RibbonClient.propagateFirstIOException(new ClientException(new IOException()));
}
Also used : ClientException(com.netflix.client.ClientException) IOException(java.io.IOException) 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