Skip to content

Commit 2beba92

Browse files
committed
Tests for ignoring
1 parent db65d61 commit 2beba92

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/DataStreamDeprecationChecksTests.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import static java.util.Map.entry;
3333
import static java.util.Map.ofEntries;
3434
import static org.elasticsearch.index.IndexModule.INDEX_STORE_TYPE_SETTING;
35+
import static org.elasticsearch.xpack.core.deprecation.DeprecatedIndexPredicate.MINIMUM_WRITEABLE_VERSION_AFTER_UPGRADE;
3536
import static org.elasticsearch.xpack.deprecation.DeprecationChecks.DATA_STREAM_CHECKS;
3637
import static org.hamcrest.Matchers.equalTo;
3738

@@ -49,15 +50,17 @@ public void testOldIndicesCheck() {
4950
Settings.Builder settings = settings(IndexVersion.fromId(7170099));
5051

5152
String indexName = "old-data-stream-index-" + i;
52-
if (expectedIndices.isEmpty() == false && randomIntBetween(0, 2) == 0) {
53+
int randomInt = randomIntBetween(0, 2);
54+
if (expectedIndices.isEmpty() == false && randomInt == 0) {
5355
settings.put(INDEX_STORE_TYPE_SETTING.getKey(), SearchableSnapshotsSettings.SEARCHABLE_SNAPSHOT_STORE_TYPE);
56+
} else if (expectedIndices.isEmpty() == false && randomInt == 1) {
57+
settings.put(IndexMetadata.INDEX_IGNORE_DEPRECATION_WARNING_FOR_VERSION_KEY, MINIMUM_WRITEABLE_VERSION_AFTER_UPGRADE.id());
5458
} else {
5559
expectedIndices.add(indexName);
5660
}
5761

58-
Settings.Builder settingsBuilder = settings;
5962
IndexMetadata oldIndexMetadata = IndexMetadata.builder(indexName)
60-
.settings(settingsBuilder)
63+
.settings(settings)
6164
.numberOfShards(1)
6265
.numberOfReplicas(0)
6366
.build();
@@ -104,6 +107,7 @@ public void testOldIndicesCheck() {
104107
false,
105108
ofEntries(
106109
entry("reindex_required", true),
110+
entry("minimum_writable_version_after_upgrade", MINIMUM_WRITEABLE_VERSION_AFTER_UPGRADE.id()),
107111
entry("total_backing_indices", oldIndexCount + newIndexCount),
108112
entry("indices_requiring_upgrade_count", expectedIndices.size()),
109113
entry("indices_requiring_upgrade", expectedIndices)

x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecksTests.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,19 @@
2222
import org.elasticsearch.index.engine.frozen.FrozenEngine;
2323
import org.elasticsearch.snapshots.SearchableSnapshotsSettings;
2424
import org.elasticsearch.test.ESTestCase;
25+
import org.elasticsearch.xpack.core.deprecation.DeprecatedIndexPredicate;
2526
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
2627

2728
import java.io.IOException;
2829
import java.util.List;
2930
import java.util.Map;
3031

3132
import static java.util.Collections.singletonList;
32-
import static java.util.Collections.singletonMap;
33+
import static java.util.Map.entry;
34+
import static java.util.Map.ofEntries;
35+
import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_IGNORE_DEPRECATION_WARNING_FOR_VERSION_KEY;
3336
import static org.elasticsearch.index.IndexModule.INDEX_STORE_TYPE_SETTING;
37+
import static org.elasticsearch.xpack.core.deprecation.DeprecatedIndexPredicate.MINIMUM_WRITEABLE_VERSION_AFTER_UPGRADE;
3438
import static org.elasticsearch.xpack.deprecation.DeprecationChecks.INDEX_SETTINGS_CHECKS;
3539
import static org.hamcrest.Matchers.empty;
3640
import static org.hamcrest.Matchers.equalTo;
@@ -54,7 +58,10 @@ public void testOldIndicesCheck() {
5458
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-9.0.html",
5559
"This index has version: " + createdWith.toReleaseVersion(),
5660
false,
57-
singletonMap("reindex_required", true)
61+
ofEntries(
62+
entry("reindex_required", true),
63+
entry("minimum_writable_version_after_upgrade", DeprecatedIndexPredicate.MINIMUM_WRITEABLE_VERSION_AFTER_UPGRADE.id())
64+
)
5865
);
5966
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(indexMetadata, clusterState));
6067
assertEquals(singletonList(expected), issues);
@@ -116,6 +123,20 @@ public void testOldIndicesCheckSnapshotIgnored() {
116123
assertThat(issues, empty());
117124
}
118125

126+
public void testIgnoredIndex() {
127+
IndexVersion createdWith = IndexVersion.fromId(7170099);
128+
Settings.Builder settings = settings(createdWith);
129+
settings.put(INDEX_IGNORE_DEPRECATION_WARNING_FOR_VERSION_KEY, MINIMUM_WRITEABLE_VERSION_AFTER_UPGRADE.id());
130+
IndexMetadata indexMetadata = IndexMetadata.builder("test").settings(settings).numberOfShards(1).numberOfReplicas(0).build();
131+
ClusterState clusterState = ClusterState.builder(ClusterState.EMPTY_STATE)
132+
.metadata(Metadata.builder().put(indexMetadata, true))
133+
.build();
134+
135+
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(indexMetadata, clusterState));
136+
137+
assertThat(issues, empty());
138+
}
139+
119140
public void testTranslogRetentionSettings() {
120141
Settings.Builder settings = settings(IndexVersion.current());
121142
settings.put(IndexSettings.INDEX_TRANSLOG_RETENTION_AGE_SETTING.getKey(), randomPositiveTimeValue());

0 commit comments

Comments
 (0)