private synchronized String getServiceBaseUrl() { if (serviceBaseUrl == null) { LoadBalancer lb = lbFactory.getLoadBalancer(serviceName); lb.waitForServiceInstance(); com.sixt.service.framework.rpc.ServiceEndpoint endpoint = lb.getHealthyInstance(); serviceBaseUrl = "http://" + endpoint.getHostAndPort(); } return serviceBaseUrl; }
@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); }
public HttpRequestWrapper createHttpPost(RpcClient client) throws RpcCallException { this.client = client; ServiceEndpoint instance = loadBalancer.getHealthyInstance(); if (instance == null) { throw new RpcCallException(RpcCallException.Category.InternalServerError, "No available instance of " + loadBalancer.getServiceName()). withSource(serviceProps.getServiceName()); } return new HttpRequestWrapper("POST", instance); }