-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add more addTemporaryStateListener utils
#125648
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -263,6 +263,15 @@ public void clusterStateProcessed(ClusterState initialState, ClusterState newSta | |
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a {@link ClusterStateListener} which subscribes to the given {@link ClusterService} and waits for it to apply a cluster state | ||
| * that satisfies {@code predicate}, at which point it unsubscribes itself. | ||
| * | ||
| * @return A {@link SubscribableListener} which is completed when the first cluster state matching {@code predicate} is applied by the | ||
| * given {@code clusterService}. If the current cluster state already matches {@code predicate} then the returned listener is | ||
| * already complete. If no matching cluster state is seen within {@link ESTestCase#SAFE_AWAIT_TIMEOUT} then the listener is | ||
| * completed exceptionally on the scheduler thread that belongs to {@code clusterService}. | ||
| */ | ||
| public static SubscribableListener<Void> addTemporaryStateListener(ClusterService clusterService, Predicate<ClusterState> predicate) { | ||
| final var listener = new SubscribableListener<Void>(); | ||
| final ClusterStateListener clusterStateListener = new ClusterStateListener() { | ||
|
|
@@ -291,4 +300,35 @@ public String toString() { | |
| } | ||
| return listener; | ||
| } | ||
|
|
||
| /** | ||
| * Creates a {@link ClusterStateListener} which subscribes to the {@link ClusterService} of one of the nodes in the | ||
| * {@link ESIntegTestCase#internalCluster()}. When the chosen {@link ClusterService} applies a state that satisfies {@code predicate} | ||
| * the listener unsubscribes itself. | ||
| * | ||
| * @return A {@link SubscribableListener} which is completed when the first cluster state matching {@code predicate} is applied by the | ||
| * {@link ClusterService} belonging to one of the nodes in the {@link ESIntegTestCase#internalCluster()}. If the current cluster | ||
| * state already matches {@code predicate} then the returned listener is already complete. If no matching cluster state is seen | ||
| * within {@link ESTestCase#SAFE_AWAIT_TIMEOUT} then the listener is completed exceptionally on the scheduler thread that | ||
| * belongs to the chosen node's {@link ClusterService}. | ||
| */ | ||
| public static SubscribableListener<Void> addTemporaryStateListener(Predicate<ClusterState> predicate) { | ||
| return addTemporaryStateListener(ESIntegTestCase.internalCluster().clusterService(), predicate); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a {@link ClusterStateListener} which subscribes to the {@link ClusterService} of the current elected master node in the | ||
| * {@link ESIntegTestCase#internalCluster()}. When this node's {@link ClusterService} applies a state that satisfies {@code predicate} | ||
| * the listener unsubscribes itself. | ||
| * | ||
| * @return A {@link SubscribableListener} which is completed when the first cluster state matching {@code predicate} is applied by the | ||
| * {@link ClusterService} belonging to the node that was the elected master node in the | ||
| * {@link ESIntegTestCase#internalCluster()} when this method was first called. If the current cluster state already matches | ||
| * {@code predicate} then the returned listener is already complete. If no matching cluster state is seen within | ||
| * {@link ESTestCase#SAFE_AWAIT_TIMEOUT} then the listener is completed exceptionally on the scheduler thread that belongs to | ||
| * the elected master node's {@link ClusterService}. | ||
| */ | ||
| public static SubscribableListener<Void> addMasterTemporaryStateListener(Predicate<ClusterState> predicate) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ++ on explicitly mentioning There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Conventionally we don't say |
||
| return addTemporaryStateListener(ESIntegTestCase.internalCluster().getCurrentMasterNodeInstance(ClusterService.class), predicate); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, for some reason I assumed
ESIntegTestCase#internalCluster()was only available inESIntegTestCaseand descendants. Realizing it's publicly available, I definitely agree we should try to keep utility methods outside ofESIntegTestCaseas that class is already huge. I'll move the data stream utility methods I recently added inESIntegTestCaseto a different class sometime.