--- old/test/testlibrary/com/oracle/java/testlibrary/Utils.java 2014-12-04 21:15:00.768585423 +0300 +++ new/test/testlibrary/com/oracle/java/testlibrary/Utils.java 2014-12-04 21:15:00.444585435 +0300 @@ -37,6 +37,7 @@ import java.util.Collections; import java.util.List; import java.util.Random; +import java.util.function.BooleanSupplier; import java.util.regex.Matcher; import java.util.regex.Pattern; import sun.misc.Unsafe; @@ -88,6 +89,13 @@ TIMEOUT_FACTOR = Double.parseDouble(toFactor); } + /** + * Returns the value of 'test.iterations.count' system property + * converted to {@code int}. + */ + public static final int ITERATIONS_COUNT = + Integer.getInteger("com.oracle.java.testlibrary.iterations", 1); + private Utils() { // Private constructor to prevent class instantiation } @@ -367,4 +375,31 @@ } return RANDOM_GENERATOR; } + + /** + * Wait for condition to be true + * + * @param condition, a condition to wait for, using default sleep time 100 + */ + public static final void waitForCondition(BooleanSupplier condition) { + waitForCondition(condition, 100); + } + + /** + * Wait until timeout for condition to be true + * + * @param condition, a condition to wait for + * @param sleepTime a time to sleep value in milliseconds + */ + public static final void waitForCondition(BooleanSupplier condition, + long sleepTime) { + while (!condition.getAsBoolean()) { + try { + Thread.sleep(sleepTime); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw new Error(e); + } + } + } }