private OperationStatus waitForAsyncQuery(OperationHandle opHandle,
      OperationState expectedState, long maxLongPollingTimeout) throws HiveSQLException {
    long testIterationTimeout = System.currentTimeMillis() + 100000;
    long longPollingStart;
    long longPollingEnd;
    long longPollingTimeDelta;
    OperationStatus opStatus = null;
    OperationState state = null;
    int count = 0;
    long start = System.currentTimeMillis();
    while (true) {
      // Break if iteration times out
      if (System.currentTimeMillis() > testIterationTimeout) {
        System.out.println("Polling timed out");
        break;
      }
      longPollingStart = System.currentTimeMillis();
      System.out.println("Long polling starts at: " + longPollingStart);
      opStatus = client.getOperationStatus(opHandle, false);
      state = opStatus.getState();
      longPollingEnd = System.currentTimeMillis();
      System.out.println("Long polling ends at: " + longPollingEnd);

      System.out.println("Polling: " + opHandle + " count=" + (++count)
          + " state=" + state);

      if (state == OperationState.CANCELED ||
          state == OperationState.CLOSED ||
          state == OperationState.FINISHED ||
          state == OperationState.ERROR) {
        break;
      } else {
        // Verify that getOperationStatus returned only after the long polling timeout
        longPollingTimeDelta = longPollingEnd - longPollingStart;
        // Calculate the expected timeout based on the elapsed time between waiting start time and polling start time
        long elapsed = longPollingStart - start;
        long expectedTimeout = Math.min(maxLongPollingTimeout, (elapsed / TimeUnit.SECONDS.toMillis(10) + 1) * 500);
        // Scale down by a factor of 0.9 to account for approximate values
        assertTrue(longPollingTimeDelta - 0.9*expectedTimeout > 0);
      }
    }
    assertEquals(expectedState, client.getOperationStatus(opHandle, false).getState());
    client.closeOperation(opHandle);
    return opStatus;
  }
Sets up a test specific table with the given column definitions and config
@param tableName
@param columnDefinitions
@param confOverlay
@throws Exception
service/src/test/org/apache/hive/service/cli/CLIServiceTest.java