@Before public void setup() throws InterruptedException, ExecutionException, TimeoutException { when(loadBalancer.getHealthyInstance()).thenReturn(createServiceEndpoint()); when(loadBalancer.getHealthyInstanceExclude(anyListOf(ServiceEndpoint.class))) .thenReturn(createServiceEndpoint()); when(rpcClient.getRetries()).thenReturn(NUMBER_OF_RETRIES); when(rpcClient.getTimeout()).thenReturn(0); httpClientWrapper.setLoadBalancer(loadBalancer); when(rpcClientMetrics.getMethodTimer(any(), any())).thenReturn(new GoTimer("timer")); when(tracer.buildSpan(any())).thenReturn(spanBuilder); when(spanBuilder.start()).thenReturn(span); when(httpClient.newRequest(any(URI.class))).thenReturn(request); when(httpClient.newRequest(any(String.class))).thenReturn(request); when(request.content(any(ContentProvider.class))).thenReturn(request); when(request.method(anyString())).thenReturn(request); when(request.timeout(anyLong(), any(TimeUnit.class))).thenReturn(request); when(request.send()).thenReturn(httpContentResponse); when(httpContentResponse.getStatus()).thenReturn(100); dependencyHealthCheck = mock(ServiceDependencyHealthCheck.class); }
private HttpRequestWrapper createHttpPost(HttpRequestWrapper previous, List<ServiceEndpoint> triedEndpoints) throws RpcCallException { ServiceEndpoint instance = loadBalancer.getHealthyInstanceExclude(triedEndpoints); if (instance == null) { throw new RpcCallException(RpcCallException.Category.InternalServerError, "RpcCallException calling " + loadBalancer.getServiceName() + ", no available instance"). withSource(serviceProps.getServiceName()); } //TODO: There may still be a problem where retries are setting chunked encoding // or the content-length gets munged HttpRequestWrapper retval = new HttpRequestWrapper("POST", instance); retval.setHeaders(previous.getHeaders()); retval.setContentProvider(previous.getContentProvider()); return retval; }