示例#1
0
 public boolean testTailLog(String testHandle) throws Exception {
   testHandle = Strings.nullToEmpty(testHandle).trim();
   if (testHandle.isEmpty()) {
     throw new IllegalArgumentException("TestHandle is required");
   }
   TestStatusRequest statusRequest = new TestStatusRequest(testHandle);
   TestStatusResponse statusResponse;
   do {
     TimeUnit.SECONDS.sleep(5);
     statusResponse = post(statusRequest, true);
   } while (Status.isPending(statusResponse.getTestStatus().getStatus()));
   long offset = 0;
   do {
     long length = statusResponse.getTestStatus().getLogFileLength();
     if (length > offset) {
       offset = printLogs(testHandle, offset);
     } else {
       TimeUnit.SECONDS.sleep(5);
     }
     statusResponse = post(statusRequest, true);
   } while (Status.isInProgress(statusResponse.getTestStatus().getStatus()));
   while (offset < statusResponse.getTestStatus().getLogFileLength()) {
     offset = printLogs(testHandle, offset);
   }
   Status.assertOKOrFailed(statusResponse.getTestStatus().getStatus());
   return Status.isOK(statusResponse.getTestStatus().getStatus());
 }
示例#2
0
 private <S extends GenericResponse> S post(Object payload, boolean agressiveRetry)
     throws Exception {
   EndPointResponsePair endPointResponse =
       Preconditions.checkNotNull(
           REQUEST_TO_ENDPOINT.get(payload.getClass()), payload.getClass().getName());
   HttpPost request = new HttpPost(mApiEndPoint + endPointResponse.getEndpoint());
   try {
     String payloadString = mMapper.writeValueAsString(payload);
     StringEntity params = new StringEntity(payloadString);
     request.addHeader("content-type", "application/json");
     request.setEntity(params);
     if (agressiveRetry) {
       mHttpClient.setHttpRequestRetryHandler(new PTestHttpRequestRetryHandler());
     }
     HttpResponse httpResponse = mHttpClient.execute(request);
     StatusLine statusLine = httpResponse.getStatusLine();
     if (statusLine.getStatusCode() != 200) {
       throw new IllegalStateException(
           statusLine.getStatusCode() + " " + statusLine.getReasonPhrase());
     }
     String response = EntityUtils.toString(httpResponse.getEntity(), "UTF-8");
     @SuppressWarnings("unchecked")
     S result =
         (S)
             endPointResponse
                 .getResponseClass()
                 .cast(mMapper.readValue(response, endPointResponse.getResponseClass()));
     Status.assertOK(result.getStatus());
     if (System.getProperty("DEBUG_PTEST_CLIENT") != null) {
       System.err.println("payload " + payloadString);
       if (result instanceof TestLogResponse) {
         System.err.println(
             "response "
                 + ((TestLogResponse) result).getOffset()
                 + " "
                 + ((TestLogResponse) result).getStatus());
       } else {
         System.err.println("response " + response);
       }
     }
     Thread.sleep(1000);
     return result;
   } finally {
     request.abort();
   }
 }