private void retry(final Description description, final EachTestNotifier notifier,
    final Statement statement, final Throwable currentThrowable) {
    Throwable caughtThrowable = currentThrowable;
    while (retryCount > failedAttempts) {
      try {
        System.out.println(description + " Caught: " + (currentThrowable == null ? "exception" :
          currentThrowable.getMessage()) + ". Retrying test " + failedAttempts + "/" + retryCount);
        statement.evaluate();
        return;
      } catch (Throwable t) {
        failedAttempts++;
        caughtThrowable = t;
      }
    }
    notifier.addFailure(caughtThrowable);
  }
JUnit test runner that reruns test on failure.
common/src/test/org/apache/hive/common/util/RetryTestRunner.java