michaeljmarshall commented on a change in pull request #14815:
URL: https://github.com/apache/pulsar/pull/14815#discussion_r834556792
##########
File path:
pulsar-metadata/src/test/java/org/apache/pulsar/metadata/BaseMetadataStoreTest.java
##########
@@ -103,4 +105,35 @@ static void assertException(CompletionException e,
Class<?> clazz) {
static void assertException(Throwable t, Class<?> clazz) {
assertTrue(clazz.isInstance(t), String.format("Exception %s is not of
type %s", t.getClass(), clazz));
}
+
+ public static void assertEqualsAndRetry(Supplier<Object> actual,
+ Object expected,
+ Object expectedAndRetry) throws
Exception {
+ assertEqualsAndRetry(actual, expected, expectedAndRetry, 5, 100);
+ }
+
+ public static void assertEqualsAndRetry(Supplier<Object> actual,
+ Object expected,
+ Object expectedAndRetry,
+ int retryCount,
+ long intSleepTimeInMillis) throws
Exception {
+ assertTrue(retryStrategically((__) -> {
+ if (actual.get().equals(expectedAndRetry)) {
+ return false;
+ }
+ assertEquals(actual.get(), expected);
+ return true;
+ }, retryCount, intSleepTimeInMillis));
+ }
+
+ public static boolean retryStrategically(Predicate<Void> predicate, int
retryCount, long intSleepTimeInMillis)
+ throws Exception {
+ for (int i = 0; i < retryCount; i++) {
+ if (predicate.test(null)) {
+ return true;
+ }
+ Thread.sleep(intSleepTimeInMillis + (intSleepTimeInMillis * i));
+ }
+ return false;
+ }
}
Review comment:
+1 - I think we should consolidate and only use `Awaitility` for these
kinds of tests.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]