Improvements to ManagerAssignmentIT#3318
Conversation
| } while (never.goal != TabletHostingGoal.NEVER && never.current != null); | ||
| Predicate<TabletLocationState> neverHostedOrCurrentNull = | ||
| t -> (t.goal == TabletHostingGoal.NEVER) || (t.current == null); | ||
| assertTrue(Wait.waitFor( |
There was a problem hiding this comment.
Not sure if this is workable. I was wondering if this could be shortened with a new waitfor method like the following.
public static <T> T waitFor(Supplier<T> supplier, Predicate<T> predicate) {
var obj = supplier.get();
while(!predicate.test(obj)) {
TimeUnit.MILLISECONDS.sleep(10);
obj = supplier.get();
}
return obj;
}Then maybe could do something like the following.
TabletLocationState never = Wait.waitFor(()->getTabletLocationState(c, tableId), t -> (t.goal == TabletHostingGoal.NEVER) || (t.current == null));There was a problem hiding this comment.
Yea I was trying to think of a way to streamline things in the case where we want to wait for a condition of a variable and then use that variable later. Right now the wait for method returns a boolean which is then checked in the test to determine whether the condition was satisfied and if the timeout elapsed.
In the suggested method, there is no check if the timeout has elapsed. Another idea could be to return an Optional. An empty optional would be returned in place of false in the current implementation, else it would contain the value we are testing against. That way we could check the return value to see if the condition was true or not. I'll look into this a bit.
There was a problem hiding this comment.
See comment. I think there is some consolidation that could occur here.
There was a problem hiding this comment.
If this test looks okay I might merge it in and create a follow on ticket for consolidating/reworking the wait/retry functionality
# Conflicts: # test/src/main/java/org/apache/accumulo/test/functional/ManagerAssignmentIT.java
Fixes #3311
This PR adds the following changes to ManagerAssignmentIT
Wait.waitFor()blocks in place of while loopsNote: this PR targets the elasticity branch since this test is only in that branch.