/** Creates a new instance with the given status code. */ public static HttpJsonStatusCode of(int httpStatus, String errorMessage) { return new HttpJsonStatusCode(httpStatus, httpStatusToStatusCode(httpStatus, errorMessage)); }
@Test public void retryNoRecover() { thrown.expect(ApiException.class); thrown.expectMessage("foobar"); ImmutableSet<StatusCode.Code> retryable = ImmutableSet.of(Code.UNAVAILABLE); HttpResponseException httpResponseException = new HttpResponseException.Builder(STATUS_FAILED_PRECONDITION, "foobar", new HttpHeaders()) .build(); ApiException apiException = ApiExceptionFactory.createException( "foobar", httpResponseException, HttpJsonStatusCode.of(Code.FAILED_PRECONDITION), false); Mockito.when(callInt.futureCall((Integer) Mockito.any(), (ApiCallContext) Mockito.any())) .thenReturn(RetryingTest.<Integer>immediateFailedFuture(apiException)) .thenReturn(ApiFutures.<Integer>immediateFuture(2)); UnaryCallSettings<Integer, Integer> callSettings = createSettings(retryable, FAST_RETRY_SETTINGS); UnaryCallable<Integer, Integer> callable = HttpJsonCallableFactory.createUnaryCallable(callInt, callSettings, clientContext); callable.call(1); }
public static HttpJsonStatusCode of(StatusCode.Code statusCode) { return new HttpJsonStatusCode(statusCode.getHttpStatusCode(), statusCode); }
callable.call(1); } catch (FailedPreconditionException exception) { Truth.assertThat(((HttpJsonStatusCode) exception.getStatusCode()).getTransportCode()) .isEqualTo(STATUS_FAILED_PRECONDITION); Truth.assertThat(exception.getMessage()).contains(HttpJsonStatusCode.FAILED_PRECONDITION);
@Test(expected = ApiException.class) public void retryTotalTimeoutExceeded() { ImmutableSet<StatusCode.Code> retryable = ImmutableSet.of(Code.UNAVAILABLE); HttpResponseException httpResponseException = new HttpResponseException.Builder( HttpStatusCodes.STATUS_CODE_SERVICE_UNAVAILABLE, "server unavailable", new HttpHeaders()) .build(); ApiException apiException = ApiExceptionFactory.createException( "foobar", httpResponseException, HttpJsonStatusCode.of(Code.FAILED_PRECONDITION), false); Mockito.when(callInt.futureCall((Integer) Mockito.any(), (ApiCallContext) Mockito.any())) .thenReturn(RetryingTest.<Integer>immediateFailedFuture(apiException)) .thenReturn(ApiFutures.<Integer>immediateFuture(2)); RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() .setInitialRetryDelay(Duration.ofMillis(Integer.MAX_VALUE)) .setMaxRetryDelay(Duration.ofMillis(Integer.MAX_VALUE)) .build(); UnaryCallSettings<Integer, Integer> callSettings = createSettings(retryable, retrySettings); UnaryCallable<Integer, Integer> callable = HttpJsonCallableFactory.createUnaryCallable(callInt, callSettings, clientContext); callable.call(1); }
public static HttpJsonStatusCode of(StatusCode.Code statusCode) { return new HttpJsonStatusCode(statusCode.getHttpStatusCode(), statusCode); }
@Override public void run() { try { HttpRequest httpRequest = createHttpRequest(); HttpResponse httpResponse = httpRequest.execute(); if (!httpResponse.isSuccessStatusCode()) { ApiExceptionFactory.createException( null, HttpJsonStatusCode.of(httpResponse.getStatusCode(), httpResponse.getStatusMessage()), false); } if (getApiMethodDescriptor().getResponseParser() != null) { ResponseT response = getApiMethodDescriptor().getResponseParser().parse(httpResponse.getContent()); getResponseFuture().set(response); } else { getResponseFuture().set(null); } } catch (Exception e) { getResponseFuture().setException(e); } }
/** Creates a new instance with the given status code. */ public static HttpJsonStatusCode of(int httpStatus, String errorMessage) { return new HttpJsonStatusCode(httpStatus, httpStatusToStatusCode(httpStatus, errorMessage)); }
@Override public void run() { try { HttpRequest httpRequest = createHttpRequest(); HttpResponse httpResponse = httpRequest.execute(); if (!httpResponse.isSuccessStatusCode()) { ApiExceptionFactory.createException( null, HttpJsonStatusCode.of(httpResponse.getStatusCode(), httpResponse.getStatusMessage()), false); } if (getApiMethodDescriptor().getResponseParser() != null) { ResponseT response = getApiMethodDescriptor().getResponseParser().parse(httpResponse.getContent()); getResponseFuture().set(response); } else { getResponseFuture().set(null); } } catch (Exception e) { getResponseFuture().setException(e); } }