|
13 | 13 | import org.elasticsearch.cluster.metadata.Metadata;
|
14 | 14 | import org.elasticsearch.common.Strings;
|
15 | 15 | import org.elasticsearch.common.bytes.BytesArray;
|
| 16 | +import org.elasticsearch.common.collect.ImmutableOpenMap; |
16 | 17 | import org.elasticsearch.common.settings.Settings;
|
17 | 18 | import org.elasticsearch.common.xcontent.XContentBuilder;
|
18 | 19 | import org.elasticsearch.common.xcontent.XContentType;
|
|
21 | 22 | import org.elasticsearch.ingest.IngestService;
|
22 | 23 | import org.elasticsearch.test.ESTestCase;
|
23 | 24 | import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
|
24 |
| -import org.hamcrest.Matchers; |
25 | 25 |
|
26 | 26 | import java.io.IOException;
|
27 | 27 | import java.util.Collections;
|
|
32 | 32 | import static org.elasticsearch.xpack.core.ilm.LifecycleSettings.LIFECYCLE_POLL_INTERVAL_SETTING;
|
33 | 33 | import static org.elasticsearch.xpack.deprecation.DeprecationChecks.CLUSTER_SETTINGS_CHECKS;
|
34 | 34 | import static org.elasticsearch.xpack.deprecation.IndexDeprecationChecksTests.addRandomFields;
|
| 35 | +import static org.hamcrest.Matchers.equalTo; |
| 36 | +import static org.hamcrest.Matchers.hasSize; |
35 | 37 |
|
36 | 38 | public class ClusterDeprecationChecksTests extends ESTestCase {
|
37 | 39 |
|
@@ -272,7 +274,41 @@ public void testPollIntervalTooLow() {
|
272 | 274 | .metadata(okMetadata)
|
273 | 275 | .build();
|
274 | 276 | List<DeprecationIssue> noIssues = DeprecationChecks.filterChecks(CLUSTER_SETTINGS_CHECKS, c -> c.apply(okState));
|
275 |
| - assertThat(noIssues, Matchers.hasSize(0)); |
| 277 | + assertThat(noIssues, hasSize(0)); |
276 | 278 | }
|
277 | 279 | }
|
| 280 | + |
| 281 | + public void testIndexTemplatesWithMultipleTypes() throws IOException { |
| 282 | + |
| 283 | + IndexTemplateMetadata multipleTypes = IndexTemplateMetadata.builder("multiple-types") |
| 284 | + .patterns(Collections.singletonList("foo")) |
| 285 | + .putMapping("type1", "{\"type1\":{}}") |
| 286 | + .putMapping("type2", "{\"type2\":{}}") |
| 287 | + .build(); |
| 288 | + IndexTemplateMetadata singleType = IndexTemplateMetadata.builder("single-type") |
| 289 | + .patterns(Collections.singletonList("foo")) |
| 290 | + .putMapping("type1", "{\"type1\":{}}") |
| 291 | + .build(); |
| 292 | + ImmutableOpenMap<String, IndexTemplateMetadata> templates = ImmutableOpenMap.<String, IndexTemplateMetadata>builder() |
| 293 | + .fPut("multiple-types", multipleTypes) |
| 294 | + .fPut("single-type", singleType) |
| 295 | + .build(); |
| 296 | + Metadata badMetadata = Metadata.builder() |
| 297 | + .templates(templates) |
| 298 | + .build(); |
| 299 | + ClusterState badState = ClusterState.builder(new ClusterName("test")).metadata(badMetadata).build(); |
| 300 | + List<DeprecationIssue> issues = DeprecationChecks.filterChecks(CLUSTER_SETTINGS_CHECKS, c -> c.apply(badState)); |
| 301 | + assertThat(issues, hasSize(1)); |
| 302 | + assertThat(issues.get(0).getDetails(), |
| 303 | + equalTo("Index templates [multiple-types] define multiple types and so will cause errors when used in index creation")); |
| 304 | + |
| 305 | + Metadata goodMetadata = Metadata.builder() |
| 306 | + .templates(ImmutableOpenMap.<String, IndexTemplateMetadata>builder().fPut("single-type", singleType).build()) |
| 307 | + .build(); |
| 308 | + ClusterState goodState = ClusterState.builder(new ClusterName("test")).metadata(goodMetadata).build(); |
| 309 | + assertThat( |
| 310 | + DeprecationChecks.filterChecks(CLUSTER_SETTINGS_CHECKS, c -> c.apply(goodState)), |
| 311 | + hasSize(0) |
| 312 | + ); |
| 313 | + } |
278 | 314 | }
|
0 commit comments