-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Remove test usages of getDefaultBackingIndexName in CCR tests
#127693
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,13 +16,11 @@ | |
| import org.elasticsearch.client.Response; | ||
| import org.elasticsearch.client.ResponseException; | ||
| import org.elasticsearch.client.RestClient; | ||
| import org.elasticsearch.cluster.metadata.DataStream; | ||
| import org.elasticsearch.cluster.metadata.DataStreamTestHelper; | ||
| import org.elasticsearch.common.Strings; | ||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.common.util.LazyInitializable; | ||
| import org.elasticsearch.common.xcontent.XContentHelper; | ||
| import org.elasticsearch.common.xcontent.support.XContentMapValues; | ||
| import org.elasticsearch.rest.RestStatus; | ||
| import org.elasticsearch.test.cluster.ElasticsearchCluster; | ||
| import org.elasticsearch.test.rest.ESRestTestCase; | ||
| import org.elasticsearch.xcontent.ToXContent; | ||
|
|
@@ -31,7 +29,6 @@ | |
| import org.junit.Before; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Comparator; | ||
| import java.util.HashSet; | ||
|
|
@@ -46,7 +43,6 @@ | |
| import static org.hamcrest.Matchers.equalTo; | ||
| import static org.hamcrest.Matchers.greaterThan; | ||
| import static org.hamcrest.Matchers.greaterThanOrEqualTo; | ||
| import static org.hamcrest.Matchers.hasSize; | ||
|
|
||
| @TestCaseOrdering(AbstractCCRRestTestCase.TargetClusterTestOrdering.class) | ||
| public abstract class AbstractCCRRestTestCase extends ESRestTestCase { | ||
|
|
@@ -354,33 +350,16 @@ protected Set<CcrNodeTask> getCcrNodeTasks() throws IOException { | |
|
|
||
| protected record CcrNodeTask(String remoteCluster, String leaderIndex, String followerIndex, int shardId) {} | ||
|
|
||
| protected static boolean indexExists(String index) throws IOException { | ||
| Response response = adminClient().performRequest(new Request("HEAD", "/" + index)); | ||
| return RestStatus.OK.getStatus() == response.getStatusLine().getStatusCode(); | ||
| } | ||
|
|
||
| protected static List<String> verifyDataStream(final RestClient client, final String name, final String... expectedBackingIndices) | ||
| /** | ||
| * Verify that the specified data stream has the expected backing index generations. | ||
| */ | ||
| protected static List<String> verifyDataStream(final RestClient client, final String name, final int... expectedBackingIndices) | ||
| throws IOException { | ||
| Request request = new Request("GET", "/_data_stream/" + name); | ||
| Map<String, ?> response = toMap(client.performRequest(request)); | ||
| List<?> retrievedDataStreams = (List<?>) response.get("data_streams"); | ||
| assertThat(retrievedDataStreams, hasSize(1)); | ||
| List<?> actualBackingIndexItems = (List<?>) ((Map<?, ?>) retrievedDataStreams.get(0)).get("indices"); | ||
| assertThat(actualBackingIndexItems, hasSize(expectedBackingIndices.length)); | ||
| final List<String> actualBackingIndices = new ArrayList<>(); | ||
| final List<String> actualBackingIndices = getDataStreamBackingIndexNames(client, name); | ||
| for (int i = 0; i < expectedBackingIndices.length; i++) { | ||
| Map<?, ?> actualBackingIndexItem = (Map<?, ?>) actualBackingIndexItems.get(i); | ||
| String actualBackingIndex = (String) actualBackingIndexItem.get("index_name"); | ||
| String expectedBackingIndex = expectedBackingIndices[i]; | ||
|
|
||
| String actualDataStreamName = actualBackingIndex.substring(5, actualBackingIndex.indexOf('-', 5)); | ||
| String expectedDataStreamName = expectedBackingIndex.substring(5, expectedBackingIndex.indexOf('-', 5)); | ||
| assertThat(actualDataStreamName, equalTo(expectedDataStreamName)); | ||
|
|
||
| int actualGeneration = Integer.parseInt(actualBackingIndex.substring(actualBackingIndex.lastIndexOf('-'))); | ||
| int expectedGeneration = Integer.parseInt(expectedBackingIndex.substring(expectedBackingIndex.lastIndexOf('-'))); | ||
| assertThat(actualGeneration, equalTo(expectedGeneration)); | ||
| actualBackingIndices.add(actualBackingIndex); | ||
| String actualBackingIndex = actualBackingIndices.get(i); | ||
| int expectedBackingIndexGeneration = expectedBackingIndices[i]; | ||
| assertThat(actualBackingIndex, DataStreamTestHelper.backingIndexEqualTo(name, expectedBackingIndexGeneration)); | ||
| } | ||
| return List.copyOf(actualBackingIndices); | ||
| } | ||
|
|
@@ -408,17 +387,6 @@ protected static void createAutoFollowPattern( | |
| assertOK(client.performRequest(request)); | ||
| } | ||
|
|
||
| /** | ||
| * Fix point in time when data stream backing index is first time queried. | ||
| * This is required to avoid failures when running test at midnight. | ||
| * (index is created for day0, but assertions are executed for day1 assuming different time based index name that does not exist) | ||
| */ | ||
| private final LazyInitializable<Long, RuntimeException> time = new LazyInitializable<>(System::currentTimeMillis); | ||
|
Comment on lines
-411
to
-416
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. The idea here is nice, but it doesn't completely avoid any issues, as the cluster(s) don't use this time supplier. |
||
|
|
||
| protected String backingIndexName(String dataStreamName, int generation) { | ||
| return DataStream.getDefaultBackingIndexName(dataStreamName, generation, time.getOrCompute()); | ||
| } | ||
|
|
||
| protected RestClient buildLeaderClient() throws IOException { | ||
| assert targetCluster != TargetCluster.LEADER; | ||
| return buildClient(getLeaderCluster().getHttpAddresses()); | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This method was already defined (with a better implementation) in
ESRestTestCase.