Skip to content

Commit 2c26069

Browse files
committed
SNAPSHOT - Tests
1 parent c2cf6c5 commit 2c26069

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

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

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.elasticsearch.cluster.metadata.DataStreamOptions;
1414
import org.elasticsearch.cluster.metadata.IndexMetadata;
1515
import org.elasticsearch.cluster.metadata.Metadata;
16+
import org.elasticsearch.cluster.metadata.MetadataIndexStateService;
1617
import org.elasticsearch.common.settings.Settings;
1718
import org.elasticsearch.index.Index;
1819
import org.elasticsearch.index.IndexMode;
@@ -115,4 +116,80 @@ public void testOldIndicesCheck() {
115116
assertThat(issues, equalTo(singletonList(expected)));
116117
}
117118

119+
public void testOldIndicesIgnoredWarningCheck() {
120+
int oldIndexCount = randomIntBetween(1, 100);
121+
int newIndexCount = randomIntBetween(1, 100);
122+
123+
List<Index> allIndices = new ArrayList<>();
124+
Map<String, IndexMetadata> nameToIndexMetadata = new HashMap<>();
125+
Set<String> expectedIndices = new HashSet<>();
126+
127+
for (int i = 0; i < oldIndexCount; i++) {
128+
Settings.Builder settings = settings(IndexVersion.fromId(7170099));
129+
130+
String indexName = "old-data-stream-index-" + i;
131+
settings.put(MetadataIndexStateService.VERIFIED_READ_ONLY_SETTING.getKey(), true);
132+
expectedIndices.add(indexName);
133+
134+
Settings.Builder settingsBuilder = settings;
135+
IndexMetadata oldIndexMetadata = IndexMetadata.builder(indexName)
136+
.settings(settingsBuilder)
137+
.numberOfShards(1)
138+
.numberOfReplicas(0)
139+
.build();
140+
allIndices.add(oldIndexMetadata.getIndex());
141+
nameToIndexMetadata.put(oldIndexMetadata.getIndex().getName(), oldIndexMetadata);
142+
}
143+
144+
for (int i = 0; i < newIndexCount; i++) {
145+
Settings.Builder settingsBuilder = settings(IndexVersion.current());
146+
IndexMetadata newIndexMetadata = IndexMetadata.builder("new-data-stream-index-" + i)
147+
.settings(settingsBuilder)
148+
.numberOfShards(1)
149+
.numberOfReplicas(0)
150+
.build();
151+
allIndices.add(newIndexMetadata.getIndex());
152+
nameToIndexMetadata.put(newIndexMetadata.getIndex().getName(), newIndexMetadata);
153+
}
154+
155+
DataStream dataStream = new DataStream(
156+
randomAlphaOfLength(10),
157+
allIndices,
158+
randomNegativeLong(),
159+
Map.of(),
160+
randomBoolean(),
161+
false,
162+
false,
163+
randomBoolean(),
164+
randomFrom(IndexMode.values()),
165+
null,
166+
randomFrom(DataStreamOptions.EMPTY, DataStreamOptions.FAILURE_STORE_DISABLED, DataStreamOptions.FAILURE_STORE_ENABLED, null),
167+
List.of(),
168+
randomBoolean(),
169+
null
170+
);
171+
172+
Metadata metadata = Metadata.builder().indices(nameToIndexMetadata).build();
173+
ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).metadata(metadata).build();
174+
175+
DeprecationIssue expected = new DeprecationIssue(
176+
DeprecationIssue.Level.WARNING,
177+
"Old data stream with a compatibility version < 9.0 Have Been Ignored",
178+
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-9.0.html",
179+
"This data stream has backing indices that were created before Elasticsearch 9.0.0 and have been marked as OK to"
180+
+ "become read-only after upgrade",
181+
false,
182+
ofEntries(
183+
entry("reindex_required", true),
184+
entry("total_backing_indices", oldIndexCount + newIndexCount),
185+
entry("ignored_indices_requiring_upgrade_count", expectedIndices.size()),
186+
entry("ignored_indices_requiring_upgrade", expectedIndices)
187+
)
188+
);
189+
190+
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(DATA_STREAM_CHECKS, c -> c.apply(dataStream, clusterState));
191+
192+
assertThat(issues, equalTo(singletonList(expected)));
193+
}
194+
118195
}

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.elasticsearch.cluster.metadata.DataStreamOptions;
1414
import org.elasticsearch.cluster.metadata.IndexMetadata;
1515
import org.elasticsearch.cluster.metadata.Metadata;
16+
import org.elasticsearch.cluster.metadata.MetadataIndexStateService;
1617
import org.elasticsearch.common.collect.ImmutableOpenMap;
1718
import org.elasticsearch.common.settings.Settings;
1819
import org.elasticsearch.index.IndexMode;
@@ -116,6 +117,31 @@ public void testOldIndicesCheckSnapshotIgnored() {
116117
assertThat(issues, empty());
117118
}
118119

120+
public void testOldIndicesIgnoredWarningCheck() {
121+
IndexVersion createdWith = IndexVersion.fromId(7170099);
122+
Settings.Builder settings = settings(createdWith).put(MetadataIndexStateService.VERIFIED_READ_ONLY_SETTING.getKey(), true);
123+
IndexMetadata indexMetadata = IndexMetadata.builder("test")
124+
.settings(settings)
125+
.numberOfShards(1)
126+
.numberOfReplicas(0)
127+
.build();
128+
ClusterState clusterState = ClusterState.builder(ClusterState.EMPTY_STATE)
129+
.metadata(Metadata.builder().put(indexMetadata, true))
130+
.build();
131+
DeprecationIssue expected = new DeprecationIssue(
132+
DeprecationIssue.Level.WARNING,
133+
"Old index with a compatibility version < 9.0 Has Been Ignored",
134+
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-9.0.html",
135+
"This index has version: "
136+
+ createdWith.toReleaseVersion()
137+
+ " and has been marked as OK to become read-only after upgrade",
138+
false,
139+
singletonMap("reindex_required", true)
140+
);
141+
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(indexMetadata, clusterState));
142+
assertEquals(singletonList(expected), issues);
143+
}
144+
119145
public void testTranslogRetentionSettings() {
120146
Settings.Builder settings = settings(IndexVersion.current());
121147
settings.put(IndexSettings.INDEX_TRANSLOG_RETENTION_AGE_SETTING.getKey(), randomPositiveTimeValue());

0 commit comments

Comments
 (0)