JsonElement element = object.get(SOURCE); if (element != null && !(element instanceof JsonNull)) { retval.withSource(element.getAsString());
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); }
@Test public void testJsonEncodingDecoding() throws Exception { RpcCallException exception = new RpcCallException(RpcCallException.Category.BadRequest, "You fool!").withData("my data").withErrorCode("SERVICE_PROTOBUF_ENUM"). withRetriable(true).withSource("com.sixt.service.foobar"); String json = exception.toString(); assertThat(json).isEqualTo("{\"category\":400,\"message\":\"You fool!\"," + "\"source\":\"com.sixt.service.foobar\",\"code\":\"SERVICE_PROTOBUF_ENUM\"," + "\"data\":\"my data\",\"retriable\":true}"); RpcCallException.fromJson(json); }
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; }
@Test public void retriableError() { //Create 2 servers and have both throw an exception that is retriable. //The exception should be thrown locally loadBalancer.addServiceEndpoint(new ServiceEndpoint(executor, "localhost:20001", "dc1", dependencyHealthCheck)); loadBalancer.addServiceEndpoint(new ServiceEndpoint(executor, "localhost:20002", "dc1", dependencyHealthCheck)); rpcClient = clientFactory.newClient(serviceName, "testing", FrameworkTest.Foobar.class). withRetries(1).build(); httpClient.setResponseException(new RpcCallException(RpcCallException.Category. InternalServerError, "test1234").withSource("testing567")); int failureCount = 0; try { rpcClient.callSynchronous(FrameworkTest.Foobar.newBuilder().build(), new OrangeContext()); } catch (RpcCallException ex) { failureCount++; assertThat(ex.getCategory()).isEqualTo(RpcCallException.Category.InternalServerError); assertThat(ex.getMessage()).isEqualTo("test1234"); assertThat(ex.getSource()).isEqualTo("testing567"); } assertThat(failureCount).isEqualTo(1); assertThat(httpClient.verifyRequestsProcessed(2)).isTrue(); }
@Test public void nonRetriableError() { //Create 2 servers and have the first throw an exception that is not retriable. //The exception should be thrown and not retried with the other node loadBalancer.addServiceEndpoint(new ServiceEndpoint(executor, "localhost:20001", "dc1", dependencyHealthCheck)); loadBalancer.addServiceEndpoint(new ServiceEndpoint(executor, "localhost:20002", "dc1", dependencyHealthCheck)); rpcClient = clientFactory.newClient(serviceName, "testing", FrameworkTest.Foobar.class). withRetries(1).build(); httpClient.setResponseException(new RpcCallException(RpcCallException.Category. InsufficientPermissions, "test").withSource("testing")); int failureCount = 0; try { rpcClient.callSynchronous(FrameworkTest.Foobar.newBuilder().build(), new OrangeContext()); } catch (RpcCallException ex) { failureCount++; assertThat(ex.getCategory()).isEqualTo(RpcCallException.Category.InsufficientPermissions); assertThat(ex.getMessage()).isEqualTo("test"); } assertThat(failureCount).isEqualTo(1); assertThat(httpClient.verifyRequestsProcessed(1)).isTrue(); }
"Null response in execute").withSource(serviceProps.getServiceName()); } else { throw lastException;