Object executeTraceFeignClient(Object bean, ProceedingJoinPoint pjp) throws IOException { Object[] args = pjp.getArgs(); Request request = (Request) args[0]; Request.Options options = (Request.Options) args[1]; return ((Client) bean).execute(request, options); }
@Override public Response execute(Request request, Request.Options options) throws IOException { Request modifiedRequest = getModifyRequest(request); try { return this.delegate.execute(modifiedRequest, options); } finally { } }
@Override public Response execute(Request request, Request.Options options) throws IOException { if (log.isDebugEnabled()) { log.debug( "Sending a request via tracing feign client [" + tracingFeignClient() + "] " + "and the delegate [" + this.delegate + "]"); } return tracingFeignClient().execute(request, options); }
@Override public Response execute(Request request, Request.Options options) throws IOException { return ((Client) wrapper().wrap(this.delegate)).execute(request, options); }
@Override public Response execute(Request request, Request.Options options) throws IOException { Map<String, Collection<String>> headers = new HashMap<>(request.headers()); Span span = handleSend(headers, request, null); if (log.isDebugEnabled()) { log.debug("Handled send of " + span); } Response response = null; Throwable error = null; try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span)) { return response = this.delegate.execute(modifiedRequest(request, headers), options); } catch (IOException | RuntimeException | Error e) { error = e; throw e; } finally { handleReceive(span, response, error); if (log.isDebugEnabled()) { log.debug("Handled receive of " + span); } } }
private void callExecute(Client refreshingClient, int numberOfExecutions) throws IOException { for (int i = 0; i < numberOfExecutions; i++) { try { refreshingClient.execute(request, options); } catch (RuntimeException e) { // ignored - TODO(gsheasby): Should check exception content } } } }
@Test public void createsClientOnlyOnceIfMakingMultipleRequests() throws IOException { when(clientSupplier.get()).thenReturn(client); when(client.execute(request, options)).thenReturn( Response.create(204, "no content", ImmutableMap.of(), new byte[0])); Client refreshingClient = CounterBackedRefreshingClient.createRefreshingClient(clientSupplier); refreshingClient.execute(request, options); refreshingClient.execute(request, options); refreshingClient.execute(request, options); verify(clientSupplier).get(); verify(client, times(3)).execute(request, options); verifyNoMoreInteractions(clientSupplier, client); }
@Test public void reinvokesSupplierAfterTheSpecifiedNumberOfRequestsHaveBeenMade() throws IOException { when(clientSupplier.get()).thenReturn(client); when(client.execute(request, options)).thenReturn( Response.create(204, "no content", ImmutableMap.of(), new byte[0])); Client refreshingClient = new CounterBackedRefreshingClient(clientSupplier, 2); refreshingClient.execute(request, options); refreshingClient.execute(request, options); refreshingClient.execute(request, options); verify(clientSupplier, times(2)).get(); verify(client, times(3)).execute(request, options); verifyNoMoreInteractions(clientSupplier, client); }
@Test public void reinvokesSupplierAfterTheSpecifiedNumberOfExceptionsThrown() throws IOException { when(clientSupplier.get()).thenReturn(client); when(client.execute(request, options)).thenThrow(CLIENT_EXCEPTION); Client refreshingClient = new ExceptionCountingRefreshingClient(clientSupplier, EXCEPTION_COUNT_BEFORE_REFRESH); int numberOfExecutions = EXCEPTION_COUNT_BEFORE_REFRESH + 1; callExecute(refreshingClient, numberOfExecutions); verify(clientSupplier, times(numberOfExecutions / EXCEPTION_COUNT_BEFORE_REFRESH + 1)).get(); verify(client, times(numberOfExecutions)).execute(request, options); verifyNoMoreInteractions(clientSupplier, client); }
@Test public void passesRequestsThroughToTheDelegate() throws IOException { when(clientSupplier.get()).thenReturn(client); when(client.execute(request, options)).thenReturn( Response.create(204, "no content", ImmutableMap.of(), new byte[0])); Client refreshingClient = CounterBackedRefreshingClient.createRefreshingClient(clientSupplier); refreshingClient.execute(request, options); verify(client, times(1)).execute(request, options); verifyNoMoreInteractions(client); }
@Test public void requestsContinueWithOldClientIfDelegateSupplierThrows() throws IOException { when(clientSupplier.get()).thenReturn(client); when(client.execute(request, options)).thenReturn( Response.create(204, "no content", ImmutableMap.of(), new byte[0])); Client refreshingClient = new CounterBackedRefreshingClient(clientSupplier, 2); refreshingClient.execute(request, options); when(clientSupplier.get()).thenThrow(new IllegalStateException("bad")); refreshingClient.execute(request, options); refreshingClient.execute(request, options); // Creation failed, so we delegate to the old client still. verify(clientSupplier, times(2)).get(); verify(client, times(3)).execute(request, options); verifyNoMoreInteractions(clientSupplier, client); } }
@Test public void passesRequestsThroughToTheDelegate() throws IOException { when(clientSupplier.get()).thenReturn(client); when(client.execute(request, options)).thenReturn(response); Client refreshingClient = ExceptionCountingRefreshingClient.createRefreshingClient(clientSupplier); callExecute(refreshingClient, 1); verify(client, times(1)).execute(request, options); verifyNoMoreInteractions(client); }
@Test public void requestsContinueWithOldClientIfDelegateSupplierThrows() throws IOException { when(clientSupplier.get()).thenReturn(client).thenThrow(new IllegalStateException("bad")); when(client.execute(request, options)).thenThrow(CLIENT_EXCEPTION); Client refreshingClient = new ExceptionCountingRefreshingClient(clientSupplier, EXCEPTION_COUNT_BEFORE_REFRESH); int numberOfExecutions = EXCEPTION_COUNT_BEFORE_REFRESH + 1; callExecute(refreshingClient, numberOfExecutions); verify(clientSupplier, times(numberOfExecutions / EXCEPTION_COUNT_BEFORE_REFRESH + 1)).get(); verify(client, times(numberOfExecutions)).execute(request, options); verifyNoMoreInteractions(clientSupplier, client); }
@Test public void createsClientOnlyOnceIfMakingMultipleRequests() throws IOException { when(clientSupplier.get()).thenReturn(client); when(client.execute(request, options)).thenReturn(response); Client refreshingClient = ExceptionCountingRefreshingClient.createRefreshingClient(clientSupplier); callExecute(refreshingClient, 3); verify(clientSupplier, times(1)).get(); verify(client, times(3)).execute(request, options); verifyNoMoreInteractions(clientSupplier, client); }
@Test public void doesRefreshClientIfExceptionsAreThrownInARow() throws IOException { when(clientSupplier.get()).thenReturn(client); when(client.execute(request, options)) .thenReturn(response) .thenThrow(CLIENT_EXCEPTION) .thenThrow(CLIENT_EXCEPTION) .thenReturn(response); Client refreshingClient = new ExceptionCountingRefreshingClient(clientSupplier, EXCEPTION_COUNT_BEFORE_REFRESH); int numberOfExecutions = 4; callExecute(refreshingClient, numberOfExecutions); verify(clientSupplier, times(2)).get(); verify(client, times(numberOfExecutions)).execute(request, options); }
@Test public void doesNotRefreshClientIfExceptionsAreNotThrownInARow() throws IOException { when(clientSupplier.get()).thenReturn(client); when(client.execute(request, options)) .thenThrow(CLIENT_EXCEPTION) .thenReturn(response) .thenThrow(CLIENT_EXCEPTION) .thenReturn(response); Client refreshingClient = new ExceptionCountingRefreshingClient(clientSupplier, EXCEPTION_COUNT_BEFORE_REFRESH); int numberOfExecutions = 4; callExecute(refreshingClient, numberOfExecutions); verify(clientSupplier, times(1)).get(); verify(client, times(numberOfExecutions)).execute(request, options); }
@Override public Response execute(Request request, Request.Options options) throws IOException { return clientDelegate.execute(request, options); } }
@Override public Response execute(Request request, Request.Options options) throws IOException { if (log.isDebugEnabled()) { log.debug( "Sending a request via tracing feign client [" + tracingFeignClient() + "] " + "and the delegate [" + this.delegate + "]"); } return tracingFeignClient().execute(request, options); }
@Override public Response execute(Request request, Request.Options options) throws IOException { TraceEvent clientStartTraceEvent = generateClientStartTraceEvent(request); Request traceableRequest = tracePreRequest(request, clientStartTraceEvent); Response response = clientDelegate.execute(traceableRequest, options); tracePostRequest(response, clientStartTraceEvent); return response; }
@Override public Response execute(Request request, Options options) throws IOException { Response response = client.execute(request, options); if (response.status() >= 200 && response.status() < 300) { // Call successful: set our attempts back to 0. failedServers.set(0); failedAttemptsForCurrentServer.set(0); } return response; } };