@Override
    public void evaluate() throws Throwable {
      int failedAttempts = 0;
      boolean retry;
      do {
        try {
          wrappedStatement.evaluate();
          retry = false;
        } catch (Throwable throwable) {
          if (retryCount > failedAttempts) {
            failedAttempts++;
            retry = true;
            System.out.println(description + " Caught: " + throwable.getMessage() + ". Retrying test " +
              failedAttempts + "/" + retryCount);
          } else {
            throw throwable;
          }
        }
      } while (retry);
    }
JUnit test rule that reruns test on failure. With Retry test rule only the test method will be retried,
the test class will not be re-initialized.
common/src/test/org/apache/hive/common/util/Retry.java