|
@@ -59,6 +59,7 @@ import org.mockito.invocation.InvocationOnMock;
|
|
|
import org.mockito.stubbing.Answer;
|
|
|
|
|
|
import com.google.common.base.Joiner;
|
|
|
+import com.google.common.base.Preconditions;
|
|
|
import com.google.common.base.Supplier;
|
|
|
import com.google.common.collect.Sets;
|
|
|
|
|
@@ -85,6 +86,14 @@ public abstract class GenericTestUtils {
|
|
|
*/
|
|
|
public static final String DEFAULT_TEST_DATA_PATH = "target/test/data/";
|
|
|
|
|
|
+ /**
|
|
|
+ * Error string used in {@link GenericTestUtils#waitFor(Supplier, int, int)}.
|
|
|
+ */
|
|
|
+ public static final String ERROR_MISSING_ARGUMENT =
|
|
|
+ "Input supplier interface should be initailized";
|
|
|
+ public static final String ERROR_INVALID_ARGUMENT =
|
|
|
+ "Total wait time should be greater than check interval time";
|
|
|
+
|
|
|
@SuppressWarnings("unchecked")
|
|
|
public static void disableLog(Log log) {
|
|
|
// We expect that commons-logging is a wrapper around Log4j.
|
|
@@ -258,10 +267,12 @@ public abstract class GenericTestUtils {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static void waitFor(Supplier<Boolean> check,
|
|
|
- int checkEveryMillis, int waitForMillis)
|
|
|
- throws TimeoutException, InterruptedException
|
|
|
- {
|
|
|
+ public static void waitFor(Supplier<Boolean> check, int checkEveryMillis,
|
|
|
+ int waitForMillis) throws TimeoutException, InterruptedException {
|
|
|
+ Preconditions.checkNotNull(check, ERROR_MISSING_ARGUMENT);
|
|
|
+ Preconditions.checkArgument(waitForMillis > checkEveryMillis,
|
|
|
+ ERROR_INVALID_ARGUMENT);
|
|
|
+
|
|
|
long st = Time.now();
|
|
|
do {
|
|
|
boolean result = check.get();
|