-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[Test] Reconcile TestProjectResolvers #124988
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 2 commits
bfa4203
1425f49
854558e
e3bf4af
aceb634
a6db641
84368ce
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 |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
| import org.elasticsearch.common.util.concurrent.ThreadContext; | ||
| import org.elasticsearch.core.CheckedRunnable; | ||
| import org.elasticsearch.tasks.Task; | ||
| import org.elasticsearch.test.ESTestCase; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.Objects; | ||
|
|
@@ -60,7 +61,7 @@ public boolean supportsMultipleProjects() { | |
| * with the executeOnProject method. This is mostly useful in places where we just need a placeholder to satisfy | ||
| * the constructor signature. | ||
| */ | ||
| public static ProjectResolver singleProjectOnly() { | ||
| public static ProjectResolver mustExecuteFirst() { | ||
|
Comment on lines
-63
to
+62
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. This method is used in quite a few places in tests. Majority of them (if not all) really just need a projectResolver as a placehoder. The choice of using this variant is probably based on the method name and has no need for its execute behaviour. I renamed this method and added a new |
||
| return new ProjectResolver() { | ||
|
|
||
| private ProjectId enforceProjectId = null; | ||
|
|
@@ -102,12 +103,25 @@ public boolean supportsMultipleProjects() { | |
|
|
||
| /** | ||
| * This method returns a ProjectResolver that gives back the specified project-id when its getProjectId method is called. | ||
| * It also assumes it is the only project in the cluster state and throws if that is not the case. | ||
| * The ProjectResolver can work with cluster state containing multiple projects and its supportsMultipleProjects returns true. | ||
| */ | ||
| public static ProjectResolver singleProject(ProjectId projectId) { | ||
| return singleProject(projectId, false); | ||
| } | ||
|
|
||
| /** | ||
| * This method returns a ProjectResolver that returns a random unique project-id. | ||
| * It also assumes it is the only project in the cluster state and throws if that is not the case. | ||
| * In addition, the ProjectResolvers returns false for supportsMultipleProjects. | ||
| */ | ||
| public static ProjectResolver singleProjectOnly() { | ||
| return singleProjectOnly(ESTestCase.randomUniqueProjectId()); | ||
| } | ||
|
||
|
|
||
| public static ProjectResolver singleProjectOnly(ProjectId projectId) { | ||
|
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. Can we add a bit of Javadoc explaining this method as well? |
||
| return singleProject(projectId, true); | ||
| } | ||
|
|
||
| private static ProjectResolver singleProject(ProjectId projectId, boolean only) { | ||
| Objects.requireNonNull(projectId); | ||
| return new ProjectResolver() { | ||
|
|
@@ -144,7 +158,7 @@ public <E extends Exception> void executeOnProject(ProjectId otherProjectId, Che | |
|
|
||
| @Override | ||
| public boolean supportsMultipleProjects() { | ||
| return true; | ||
| return only == false; | ||
| } | ||
| }; | ||
| } | ||
|
|
||
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.
Nit: I think we should remove the last sentence. The "placeholder usage" is
singleProjectOnly.mustExecuteFirsthas a pretty niche use case.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.
Yeah it's a leftover that should be removed.