|
21 | 21 | import org.elasticsearch.cluster.metadata.MetadataIndexStateService;
|
22 | 22 | import org.elasticsearch.common.collect.ImmutableOpenMap;
|
23 | 23 | import org.elasticsearch.common.settings.Settings;
|
| 24 | +import org.elasticsearch.common.time.FormatNames; |
24 | 25 | import org.elasticsearch.core.TimeValue;
|
25 | 26 | import org.elasticsearch.index.IndexMode;
|
26 | 27 | import org.elasticsearch.index.IndexSettings;
|
|
36 | 37 |
|
37 | 38 | import java.util.ArrayList;
|
38 | 39 | import java.util.List;
|
| 40 | +import java.util.Locale; |
39 | 41 | import java.util.Map;
|
40 | 42 |
|
41 | 43 | import static java.util.Collections.singletonList;
|
@@ -234,6 +236,45 @@ public void testOldIndicesWithIncompatibleDateFormatsCheck() {
|
234 | 236 | assertEquals(singletonList(expected), issues);
|
235 | 237 | }
|
236 | 238 |
|
| 239 | + public void testOldIndicesWithCompatibleDateFormatter() { |
| 240 | + String pattern = randomFrom(FormatNames.values()).getName(); |
| 241 | + |
| 242 | + IndexMetadata indexMetadata = IndexMetadata.builder("test") |
| 243 | + .settings(settings(OLD_VERSION)) |
| 244 | + .numberOfShards(1) |
| 245 | + .numberOfReplicas(0) |
| 246 | + .state(indexMetdataState) |
| 247 | + .putMapping(String.format(Locale.ROOT, """ |
| 248 | + { |
| 249 | + "properties": { |
| 250 | + "date": { |
| 251 | + "type": "date", |
| 252 | + "format": "%s" |
| 253 | + } |
| 254 | + } |
| 255 | + }""", pattern)) |
| 256 | + .build(); |
| 257 | + ClusterState clusterState = ClusterState.builder(ClusterState.EMPTY_STATE) |
| 258 | + .metadata(Metadata.builder().put(indexMetadata, true)) |
| 259 | + .blocks(clusterBlocksForIndices(indexMetadata)) |
| 260 | + .build(); |
| 261 | + DeprecationIssue expected = new DeprecationIssue( |
| 262 | + DeprecationIssue.Level.CRITICAL, |
| 263 | + "Old index with a compatibility version < 8.0", |
| 264 | + "https://www.elastic.co/guide/en/elastic-stack/9.0/upgrading-elastic-stack.html", |
| 265 | + "This index has version: " + OLD_VERSION.toReleaseVersion(), |
| 266 | + false, |
| 267 | + singletonMap("reindex_required", true) |
| 268 | + ); |
| 269 | + Map<String, List<DeprecationIssue>> issuesByIndex = checker.check( |
| 270 | + clusterState, |
| 271 | + new DeprecationInfoAction.Request(TimeValue.THIRTY_SECONDS), |
| 272 | + emptyPrecomputedData |
| 273 | + ); |
| 274 | + List<DeprecationIssue> issues = issuesByIndex.get("test"); |
| 275 | + assertEquals(singletonList(expected), issues); |
| 276 | + } |
| 277 | + |
237 | 278 | private IndexMetadata indexMetadata(String indexName, IndexVersion indexVersion) {
|
238 | 279 | return IndexMetadata.builder(indexName)
|
239 | 280 | .settings(settings(indexVersion))
|
|
0 commit comments