/** * Retry Condition c until it returns true or timeout. See {@link Condition} * for isTrue semantics. */ public RetryLoop(Condition c, int timeoutSeconds, int intervalBetweenTriesMsec) { timeout = System.currentTimeMillis() + timeoutSeconds * 1000L; while (System.currentTimeMillis() < timeout) { try { if (c.isTrue()) { return; } } catch (AssertionError ae) { // Retry JUnit tests failing in the condition as well reportException(ae); } catch (Exception e) { reportException(e); } try { Thread.sleep(intervalBetweenTriesMsec); } catch (InterruptedException ignore) { } } onTimeout(); fail("RetryLoop failed, condition is false after " + timeoutSeconds + " seconds: " + c.getDescription()); }