コード例 #1
0
 private void assertQueryStatus(URI location, QueryState expectedQueryState) {
   URI statusUri = uriBuilderFrom(location).build();
   JsonResponse<QueryInfo> response =
       client.execute(
           prepareGet().setUri(statusUri).build(),
           createFullJsonResponseHandler(jsonCodec(QueryInfo.class)));
   if (expectedQueryState == QueryState.FINISHED
       && response.getStatusCode() == HttpStatus.GONE.code()) {
     // when query finishes the server may delete it
     return;
   }
   QueryInfo queryInfo = response.getValue();
   assertEquals(queryInfo.getState(), expectedQueryState);
 }
コード例 #2
0
 @Override
 public void onSuccess(JsonResponse<T> response) {
   try {
     if (response.getStatusCode() == HttpStatus.OK.code() && response.hasValue()) {
       callback.success(response.getValue());
     } else if (response.getStatusCode() == HttpStatus.SERVICE_UNAVAILABLE.code()) {
       callback.failed(new ServiceUnavailableException(uri));
     } else {
       // Something is broken in the server or the client, so fail the task immediately (includes
       // 500 errors)
       Exception cause = response.getException();
       if (cause == null) {
         if (response.getStatusCode() == HttpStatus.OK.code()) {
           cause =
               new PrestoException(
                   REMOTE_TASK_ERROR, format("Expected response from %s is empty", uri));
         } else {
           cause =
               new PrestoException(
                   REMOTE_TASK_ERROR,
                   format(
                       "Expected response code from %s to be %s, but was %s: %s%n%s",
                       uri,
                       HttpStatus.OK.code(),
                       response.getStatusCode(),
                       response.getStatusMessage(),
                       response.getResponseBody()));
         }
       }
       callback.fatal(cause);
     }
   } catch (Throwable t) {
     // this should never happen
     callback.fatal(t);
   }
 }