Skip to content

Commit e32623e

Browse files
authored
[7.x] Add test for component templates updated after cluster restart (#58883) (#58914)
This commit adds an integration test that component templates used to form a composite template can still be updated after a cluster restart. In #58643 an issue arose where mappings were causing problems because of the way we unwrap `_doc` in template mappings. This was also related to the mappings being merged manually rather than using the `MapperService` to do the merging. #58643 was fixed in 7.9 and master with the #58521 change, since mappings now are read and digested by the actual mapper service. This test passes for 7.x and master, and I intend to open a separate PR including this test for 7.8.1 along with a bug fix for #58643. This test is to ensure we don't have any regression in the future.
1 parent 6215285 commit e32623e

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.indices.template;
21+
22+
import org.elasticsearch.action.admin.indices.template.put.PutComponentTemplateAction;
23+
import org.elasticsearch.action.admin.indices.template.put.PutComposableIndexTemplateAction;
24+
import org.elasticsearch.cluster.metadata.ComponentTemplate;
25+
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
26+
import org.elasticsearch.cluster.metadata.Template;
27+
import org.elasticsearch.common.compress.CompressedXContent;
28+
import org.elasticsearch.test.ESIntegTestCase;
29+
30+
import java.util.Collections;
31+
32+
public class ComposableTemplateIT extends ESIntegTestCase {
33+
34+
// See: https://github.com/elastic/elasticsearch/issues/58643
35+
public void testComponentTemplatesCanBeUpdatedAfterRestart() throws Exception {
36+
ComponentTemplate ct = new ComponentTemplate(new Template(null, new CompressedXContent("{\n" +
37+
" \"dynamic\": false,\n" +
38+
" \"properties\": {\n" +
39+
" \"foo\": {\n" +
40+
" \"type\": \"text\"\n" +
41+
" }\n" +
42+
" }\n" +
43+
" }"), null), 3L, Collections.singletonMap("eggplant", "potato"));
44+
client().execute(PutComponentTemplateAction.INSTANCE, new PutComponentTemplateAction.Request("my-ct").componentTemplate(ct)).get();
45+
46+
ComposableIndexTemplate cit = new ComposableIndexTemplate(Collections.singletonList("coleslaw"),
47+
new Template(null, new CompressedXContent("{\n" +
48+
" \"dynamic\": false,\n" +
49+
" \"properties\": {\n" +
50+
" \"foo\": {\n" +
51+
" \"type\": \"keyword\"\n" +
52+
" }\n" +
53+
" }\n" +
54+
" }"), null), Collections.singletonList("my-ct"),
55+
4L, 5L, Collections.singletonMap("egg", "bread"));
56+
client().execute(PutComposableIndexTemplateAction.INSTANCE,
57+
new PutComposableIndexTemplateAction.Request("my-it").indexTemplate(cit)).get();
58+
59+
internalCluster().fullRestart();
60+
ensureGreen();
61+
62+
ComponentTemplate ct2 = new ComponentTemplate(new Template(null, new CompressedXContent("{\n" +
63+
" \"dynamic\": true,\n" +
64+
" \"properties\": {\n" +
65+
" \"foo\": {\n" +
66+
" \"type\": \"keyword\"\n" +
67+
" }\n" +
68+
" }\n" +
69+
" }"), null), 3L, Collections.singletonMap("eggplant", "potato"));
70+
client().execute(PutComponentTemplateAction.INSTANCE,
71+
new PutComponentTemplateAction.Request("my-ct").componentTemplate(ct2)).get();
72+
73+
ComposableIndexTemplate cit2 = new ComposableIndexTemplate(Collections.singletonList("coleslaw"),
74+
new Template(null, new CompressedXContent("{\n" +
75+
" \"dynamic\": true,\n" +
76+
" \"properties\": {\n" +
77+
" \"foo\": {\n" +
78+
" \"type\": \"integer\"\n" +
79+
" }\n" +
80+
" }\n" +
81+
" }"), null), Collections.singletonList("my-ct"),
82+
4L, 5L, Collections.singletonMap("egg", "bread"));
83+
client().execute(PutComposableIndexTemplateAction.INSTANCE,
84+
new PutComposableIndexTemplateAction.Request("my-it").indexTemplate(cit2)).get();
85+
}
86+
}

0 commit comments

Comments
 (0)