3232import org .elasticsearch .threadpool .ThreadPool ;
3333import org .elasticsearch .watcher .ResourceWatcherService ;
3434
35- import java .util .Arrays ;
3635import java .util .Collection ;
3736import java .util .Collections ;
3837import java .util .List ;
4140import java .util .function .UnaryOperator ;
4241
4342import static org .elasticsearch .test .hamcrest .ElasticsearchAssertions .assertAcked ;
44- import static org .hamcrest .Matchers .empty ;
4543import static org .hamcrest .Matchers .equalTo ;
44+ import static org .hamcrest .Matchers .hasSize ;
4645
4746@ ESIntegTestCase .ClusterScope (scope = ESIntegTestCase .Scope .TEST )
4847public class TemplateUpgradeServiceIT extends ESIntegTestCase {
@@ -105,10 +104,15 @@ public void testTemplateUpdate() throws Exception {
105104 assertAcked (client ().admin ().indices ().preparePutTemplate ("test_removed_template" ).setOrder (1 )
106105 .setPatterns (Collections .singletonList ("*" )).get ());
107106
107+ AtomicInteger updateCount = new AtomicInteger ();
108108 // Wait for the templates to be updated back to normal
109109 assertBusy (() -> {
110+ // the updates only happen on cluster state updates, so we need to make sure that the cluster state updates are happening
111+ // so we need to simulate updates to make sure the template upgrade kicks in
112+ assertAcked (client ().admin ().cluster ().prepareUpdateSettings ().setTransientSettings (
113+ Settings .builder ().put (TestPlugin .UPDATE_TEMPLATE_DUMMY_SETTING .getKey (), updateCount .incrementAndGet ())
114+ ).get ());
110115 List <IndexTemplateMetaData > templates = client ().admin ().indices ().prepareGetTemplates ("test_*" ).get ().getIndexTemplates ();
111- assertThat (templates .size (), equalTo (3 ));
112116 boolean addedFound = false ;
113117 boolean changedFound = false ;
114118 boolean dummyFound = false ;
@@ -133,10 +137,10 @@ public void testTemplateUpdate() throws Exception {
133137 break ;
134138 }
135139 }
136-
137140 assertTrue (addedFound );
138141 assertTrue (changedFound );
139142 assertTrue (dummyFound );
143+ assertThat (templates .size (), equalTo (3 ));
140144 });
141145
142146 // Wipe out all templates
@@ -157,7 +161,6 @@ private void assertTemplates() throws Exception {
157161 ).get ());
158162
159163 List <IndexTemplateMetaData > templates = client ().admin ().indices ().prepareGetTemplates ("test_*" ).get ().getIndexTemplates ();
160- assertThat (templates .size (), equalTo (2 ));
161164 boolean addedFound = false ;
162165 boolean changedFound = false ;
163166 for (int i = 0 ; i < 2 ; i ++) {
@@ -180,6 +183,7 @@ private void assertTemplates() throws Exception {
180183
181184 assertTrue (addedFound );
182185 assertTrue (changedFound );
186+ assertThat (templates , hasSize (2 ));
183187 });
184188 }
185189
0 commit comments