Skip to content

Commit

Permalink
[Java] Additional Tests await method.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeb01 committed Sep 15, 2024
1 parent 252ba1b commit 4ada470
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions aeron-test-support/src/main/java/io/aeron/test/Tests.java
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,20 @@ public static void await(
}
}

/**
* Await a condition with and check for thread interrupt.
*
* @param conditionSupplier for the condition to be awaited.
* @param errorMessageSupplier supplier of error message if interrupt signalled
*/
public static void await(final BooleanSupplier conditionSupplier, final Supplier<String> errorMessageSupplier)
{
while (!conditionSupplier.getAsBoolean())
{
Tests.yieldingIdle(errorMessageSupplier);
}
}

/**
* Await a condition with a timeout and also check for thread interrupt.
*
Expand Down Expand Up @@ -455,6 +469,26 @@ public static <T> void await(
}
}

/**
* Await a condition with and check for thread interrupt.
*
* @param argSupplier argument for the condition + message.
* @param conditionsPredicate for the condition to be awaited.
* @param errorMessageCreator supplier of error message if timeout reached
* @param <T> type of argument to condition + message
*/
public static <T> void await(
final Supplier<T> argSupplier,
final Predicate<T> conditionsPredicate,
final Function<T, String> errorMessageCreator)
{
final Supplier<String> msg = () -> errorMessageCreator.apply(argSupplier.get());
while (!conditionsPredicate.test(argSupplier.get()))
{
Tests.yieldingIdle(msg);
}
}

/**
* Await a condition with a check for thread interrupt.
*
Expand Down

0 comments on commit 4ada470

Please sign in to comment.