Skip to content

Commit 6758723

Browse files
committed
Tests for excluding snapshots
1 parent ad352b1 commit 6758723

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

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

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,21 @@
1717
import org.elasticsearch.index.Index;
1818
import org.elasticsearch.index.IndexMode;
1919
import org.elasticsearch.index.IndexVersion;
20+
import org.elasticsearch.snapshots.SearchableSnapshotsSettings;
2021
import org.elasticsearch.test.ESTestCase;
2122
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
2223

2324
import java.util.ArrayList;
2425
import java.util.HashMap;
26+
import java.util.HashSet;
2527
import java.util.List;
2628
import java.util.Map;
27-
import java.util.stream.Collectors;
29+
import java.util.Set;
2830

2931
import static java.util.Collections.singletonList;
3032
import static java.util.Map.entry;
3133
import static java.util.Map.ofEntries;
34+
import static org.elasticsearch.index.IndexModule.INDEX_STORE_TYPE_SETTING;
3235
import static org.elasticsearch.xpack.deprecation.DeprecationChecks.DATA_STREAM_CHECKS;
3336
import static org.hamcrest.Matchers.equalTo;
3437

@@ -40,10 +43,20 @@ public void testOldIndicesCheck() {
4043

4144
List<Index> allIndices = new ArrayList<>();
4245
Map<String, IndexMetadata> nameToIndexMetadata = new HashMap<>();
46+
Set<String> expectedIndices = new HashSet<>();
4347

4448
for (int i = 0; i < oldIndexCount; i++) {
45-
Settings.Builder settingsBuilder = settings(IndexVersion.fromId(7170099));
46-
IndexMetadata oldIndexMetadata = IndexMetadata.builder("old-data-stream-index-" + i)
49+
Settings.Builder settings = settings(IndexVersion.fromId(7170099));
50+
51+
String indexName = "old-data-stream-index-" + i;
52+
if (expectedIndices.isEmpty() == false && randomIntBetween(0, 2) == 0) {
53+
settings.put(INDEX_STORE_TYPE_SETTING.getKey(), SearchableSnapshotsSettings.SEARCHABLE_SNAPSHOT_STORE_TYPE);
54+
} else {
55+
expectedIndices.add(indexName);
56+
}
57+
58+
Settings.Builder settingsBuilder = settings;
59+
IndexMetadata oldIndexMetadata = IndexMetadata.builder(indexName)
4760
.settings(settingsBuilder)
4861
.numberOfShards(1)
4962
.numberOfReplicas(0)
@@ -92,14 +105,8 @@ public void testOldIndicesCheck() {
92105
ofEntries(
93106
entry("reindex_required", true),
94107
entry("total_backing_indices", oldIndexCount + newIndexCount),
95-
entry("indices_requiring_upgrade_count", oldIndexCount),
96-
entry(
97-
"indices_requiring_upgrade",
98-
nameToIndexMetadata.keySet()
99-
.stream()
100-
.filter(name -> name.startsWith("old-data-stream-index-"))
101-
.collect(Collectors.toUnmodifiableSet())
102-
)
108+
entry("indices_requiring_upgrade_count", expectedIndices.size()),
109+
entry("indices_requiring_upgrade", expectedIndices)
103110
)
104111
);
105112

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.elasticsearch.index.IndexSettings;
2121
import org.elasticsearch.index.IndexVersion;
2222
import org.elasticsearch.index.engine.frozen.FrozenEngine;
23+
import org.elasticsearch.snapshots.SearchableSnapshotsSettings;
2324
import org.elasticsearch.test.ESTestCase;
2425
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
2526

@@ -29,6 +30,7 @@
2930

3031
import static java.util.Collections.singletonList;
3132
import static java.util.Collections.singletonMap;
33+
import static org.elasticsearch.index.IndexModule.INDEX_STORE_TYPE_SETTING;
3234
import static org.elasticsearch.xpack.deprecation.DeprecationChecks.INDEX_SETTINGS_CHECKS;
3335
import static org.hamcrest.Matchers.empty;
3436
import static org.hamcrest.Matchers.equalTo;
@@ -100,6 +102,20 @@ public void testOldIndicesCheckDataStreamIndex() {
100102
assertThat(issues.size(), equalTo(0));
101103
}
102104

105+
public void testOldIndicesCheckSnapshotIgnored() {
106+
IndexVersion createdWith = IndexVersion.fromId(7170099);
107+
Settings.Builder settings = settings(createdWith);
108+
settings.put(INDEX_STORE_TYPE_SETTING.getKey(), SearchableSnapshotsSettings.SEARCHABLE_SNAPSHOT_STORE_TYPE);
109+
IndexMetadata indexMetadata = IndexMetadata.builder("test").settings(settings).numberOfShards(1).numberOfReplicas(0).build();
110+
ClusterState clusterState = ClusterState.builder(ClusterState.EMPTY_STATE)
111+
.metadata(Metadata.builder().put(indexMetadata, true))
112+
.build();
113+
114+
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(indexMetadata, clusterState));
115+
116+
assertThat(issues, empty());
117+
}
118+
103119
public void testTranslogRetentionSettings() {
104120
Settings.Builder settings = settings(IndexVersion.current());
105121
settings.put(IndexSettings.INDEX_TRANSLOG_RETENTION_AGE_SETTING.getKey(), randomPositiveTimeValue());

0 commit comments

Comments
 (0)