@@ -243,6 +243,14 @@ public void setupCreateIndexRequestAndAliasValidator() {
243
243
);
244
244
}
245
245
246
+ @ After
247
+ public void tearDown () throws Exception {
248
+ super .tearDown ();
249
+ // clear any FeatureFlags needed for individual tests
250
+ FeatureFlags .initializeFeatureFlags (Settings .EMPTY );
251
+ clusterSettings = null ;
252
+ }
253
+
246
254
private ClusterState createClusterState (String name , int numShards , int numReplicas , Settings settings ) {
247
255
int numRoutingShards = settings .getAsInt (IndexMetadata .INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING .getKey (), numShards );
248
256
Metadata .Builder metaBuilder = Metadata .builder ();
@@ -2304,6 +2312,8 @@ public void testIndexCreationWithIndexStoreTypeRemoteStoreThrowsException() {
2304
2312
}
2305
2313
2306
2314
public void testCreateIndexWithContextDisabled () throws Exception {
2315
+ // Explicitly disable the FF
2316
+ FeatureFlags .initializeFeatureFlags (Settings .builder ().put (FeatureFlags .APPLICATION_BASED_CONFIGURATION_TEMPLATES , false ).build ());
2307
2317
request = new CreateIndexClusterStateUpdateRequest ("create index" , "test" , "test" ).context (new Context (randomAlphaOfLength (5 )));
2308
2318
withTemporaryClusterService ((clusterService , threadPool ) -> {
2309
2319
MetadataCreateIndexService checkerService = new MetadataCreateIndexService (
@@ -2337,42 +2347,35 @@ public void testCreateIndexWithContextDisabled() throws Exception {
2337
2347
2338
2348
public void testCreateIndexWithContextAbsent () throws Exception {
2339
2349
FeatureFlags .initializeFeatureFlags (Settings .builder ().put (FeatureFlags .APPLICATION_BASED_CONFIGURATION_TEMPLATES , true ).build ());
2340
- try {
2341
- request = new CreateIndexClusterStateUpdateRequest ("create index" , "test" , "test" ).context (new Context (randomAlphaOfLength (5 )));
2342
- withTemporaryClusterService ((clusterService , threadPool ) -> {
2343
- MetadataCreateIndexService checkerService = new MetadataCreateIndexService (
2344
- Settings .EMPTY ,
2345
- clusterService ,
2346
- indicesServices ,
2347
- null ,
2348
- null ,
2349
- createTestShardLimitService (randomIntBetween (1 , 1000 ), false , clusterService ),
2350
- mock (Environment .class ),
2351
- IndexScopedSettings .DEFAULT_SCOPED_SETTINGS ,
2352
- threadPool ,
2353
- null ,
2354
- new SystemIndices (Collections .emptyMap ()),
2355
- false ,
2356
- new AwarenessReplicaBalance (Settings .EMPTY , clusterService .getClusterSettings ()),
2357
- DefaultRemoteStoreSettings .INSTANCE ,
2358
- repositoriesServiceSupplier
2359
- );
2360
- CountDownLatch counter = new CountDownLatch (1 );
2361
- InvalidIndexContextException exception = expectThrows (
2362
- InvalidIndexContextException .class ,
2363
- () -> checkerService .validateContext (request )
2364
- );
2365
- assertTrue (
2366
- "Invalid exception message." + exception .getMessage (),
2367
- exception .getMessage ().contains ("index specifies a context which is not loaded on the cluster." )
2368
- );
2369
- });
2370
- } finally {
2371
- // Disable so that other tests which are not dependent on this are not impacted.
2372
- FeatureFlags .initializeFeatureFlags (
2373
- Settings .builder ().put (FeatureFlags .APPLICATION_BASED_CONFIGURATION_TEMPLATES , false ).build ()
2350
+ request = new CreateIndexClusterStateUpdateRequest ("create index" , "test" , "test" ).context (new Context (randomAlphaOfLength (5 )));
2351
+ withTemporaryClusterService ((clusterService , threadPool ) -> {
2352
+ MetadataCreateIndexService checkerService = new MetadataCreateIndexService (
2353
+ Settings .EMPTY ,
2354
+ clusterService ,
2355
+ indicesServices ,
2356
+ null ,
2357
+ null ,
2358
+ createTestShardLimitService (randomIntBetween (1 , 1000 ), false , clusterService ),
2359
+ mock (Environment .class ),
2360
+ IndexScopedSettings .DEFAULT_SCOPED_SETTINGS ,
2361
+ threadPool ,
2362
+ null ,
2363
+ new SystemIndices (Collections .emptyMap ()),
2364
+ false ,
2365
+ new AwarenessReplicaBalance (Settings .EMPTY , clusterService .getClusterSettings ()),
2366
+ DefaultRemoteStoreSettings .INSTANCE ,
2367
+ repositoriesServiceSupplier
2374
2368
);
2375
- }
2369
+ CountDownLatch counter = new CountDownLatch (1 );
2370
+ InvalidIndexContextException exception = expectThrows (
2371
+ InvalidIndexContextException .class ,
2372
+ () -> checkerService .validateContext (request )
2373
+ );
2374
+ assertTrue (
2375
+ "Invalid exception message." + exception .getMessage (),
2376
+ exception .getMessage ().contains ("index specifies a context which is not loaded on the cluster." )
2377
+ );
2378
+ });
2376
2379
}
2377
2380
2378
2381
public void testApplyContext () throws IOException {
@@ -2420,63 +2423,56 @@ public void testApplyContext() throws IOException {
2420
2423
}
2421
2424
2422
2425
String contextName = randomAlphaOfLength (5 );
2423
- try {
2424
- request = new CreateIndexClusterStateUpdateRequest ("create index" , "test" , "test" ).context (new Context (contextName ));
2425
- withTemporaryClusterService ((clusterService , threadPool ) -> {
2426
- MetadataCreateIndexService checkerService = new MetadataCreateIndexService (
2427
- Settings .EMPTY ,
2428
- clusterService ,
2429
- indicesServices ,
2430
- null ,
2431
- null ,
2432
- createTestShardLimitService (randomIntBetween (1 , 1000 ), false , clusterService ),
2433
- mock (Environment .class ),
2434
- IndexScopedSettings .DEFAULT_SCOPED_SETTINGS ,
2435
- threadPool ,
2436
- null ,
2437
- new SystemIndices (Collections .emptyMap ()),
2438
- false ,
2439
- new AwarenessReplicaBalance (Settings .EMPTY , clusterService .getClusterSettings ()),
2440
- DefaultRemoteStoreSettings .INSTANCE ,
2441
- repositoriesServiceSupplier
2442
- );
2426
+ request = new CreateIndexClusterStateUpdateRequest ("create index" , "test" , "test" ).context (new Context (contextName ));
2427
+ withTemporaryClusterService ((clusterService , threadPool ) -> {
2428
+ MetadataCreateIndexService checkerService = new MetadataCreateIndexService (
2429
+ Settings .EMPTY ,
2430
+ clusterService ,
2431
+ indicesServices ,
2432
+ null ,
2433
+ null ,
2434
+ createTestShardLimitService (randomIntBetween (1 , 1000 ), false , clusterService ),
2435
+ mock (Environment .class ),
2436
+ IndexScopedSettings .DEFAULT_SCOPED_SETTINGS ,
2437
+ threadPool ,
2438
+ null ,
2439
+ new SystemIndices (Collections .emptyMap ()),
2440
+ false ,
2441
+ new AwarenessReplicaBalance (Settings .EMPTY , clusterService .getClusterSettings ()),
2442
+ DefaultRemoteStoreSettings .INSTANCE ,
2443
+ repositoriesServiceSupplier
2444
+ );
2443
2445
2444
- ClusterState mockState = mock (ClusterState .class );
2445
- Metadata metadata = mock (Metadata .class );
2446
-
2447
- when (mockState .metadata ()).thenReturn (metadata );
2448
- when (metadata .systemTemplatesLookup ()).thenReturn (Map .of (contextName , new TreeMap <>() {
2449
- {
2450
- put (1L , contextName );
2451
- }
2452
- }));
2453
- when (metadata .componentTemplates ()).thenReturn (Map .of (contextName , componentTemplate .get ()));
2454
-
2455
- try {
2456
- Template template = checkerService .applyContext (request , mockState , allMappings , settingsBuilder );
2457
- assertEquals (componentTemplate .get ().template (), template );
2458
-
2459
- assertEquals (2 , allMappings .size ());
2460
- assertEquals (mappings , allMappings .get (0 ));
2461
- assertEquals (
2462
- MapperService .parseMapping (NamedXContentRegistry .EMPTY , componentTemplate .get ().template ().mappings ().toString ()),
2463
- allMappings .get (1 )
2464
- );
2465
-
2466
- assertEquals ("60s" , settingsBuilder .get (INDEX_REFRESH_INTERVAL_SETTING .getKey ()));
2467
- assertEquals ("log_byte_size" , settingsBuilder .get (INDEX_MERGE_POLICY .getKey ()));
2468
- assertEquals ("best_compression" , settingsBuilder .get (EngineConfig .INDEX_CODEC_SETTING .getKey ()));
2469
- assertEquals ("false" , settingsBuilder .get (INDEX_SOFT_DELETES_SETTING .getKey ()));
2470
- } catch (IOException ex ) {
2471
- throw new AssertionError (ex );
2446
+ ClusterState mockState = mock (ClusterState .class );
2447
+ Metadata metadata = mock (Metadata .class );
2448
+
2449
+ when (mockState .metadata ()).thenReturn (metadata );
2450
+ when (metadata .systemTemplatesLookup ()).thenReturn (Map .of (contextName , new TreeMap <>() {
2451
+ {
2452
+ put (1L , contextName );
2472
2453
}
2473
- });
2474
- } finally {
2475
- // Disable so that other tests which are not dependent on this are not impacted.
2476
- FeatureFlags .initializeFeatureFlags (
2477
- Settings .builder ().put (FeatureFlags .APPLICATION_BASED_CONFIGURATION_TEMPLATES , false ).build ()
2478
- );
2479
- }
2454
+ }));
2455
+ when (metadata .componentTemplates ()).thenReturn (Map .of (contextName , componentTemplate .get ()));
2456
+
2457
+ try {
2458
+ Template template = checkerService .applyContext (request , mockState , allMappings , settingsBuilder );
2459
+ assertEquals (componentTemplate .get ().template (), template );
2460
+
2461
+ assertEquals (2 , allMappings .size ());
2462
+ assertEquals (mappings , allMappings .get (0 ));
2463
+ assertEquals (
2464
+ MapperService .parseMapping (NamedXContentRegistry .EMPTY , componentTemplate .get ().template ().mappings ().toString ()),
2465
+ allMappings .get (1 )
2466
+ );
2467
+
2468
+ assertEquals ("60s" , settingsBuilder .get (INDEX_REFRESH_INTERVAL_SETTING .getKey ()));
2469
+ assertEquals ("log_byte_size" , settingsBuilder .get (INDEX_MERGE_POLICY .getKey ()));
2470
+ assertEquals ("best_compression" , settingsBuilder .get (EngineConfig .INDEX_CODEC_SETTING .getKey ()));
2471
+ assertEquals ("false" , settingsBuilder .get (INDEX_SOFT_DELETES_SETTING .getKey ()));
2472
+ } catch (IOException ex ) {
2473
+ throw new AssertionError (ex );
2474
+ }
2475
+ });
2480
2476
}
2481
2477
2482
2478
public void testApplyContextWithSettingsOverlap () throws IOException {
@@ -2508,55 +2504,48 @@ public void testApplyContextWithSettingsOverlap() throws IOException {
2508
2504
}
2509
2505
2510
2506
String contextName = randomAlphaOfLength (5 );
2511
- try {
2512
- request = new CreateIndexClusterStateUpdateRequest ("create index" , "test" , "test" ).context (new Context (contextName ));
2513
- withTemporaryClusterService ((clusterService , threadPool ) -> {
2514
- MetadataCreateIndexService checkerService = new MetadataCreateIndexService (
2515
- Settings .EMPTY ,
2516
- clusterService ,
2517
- indicesServices ,
2518
- null ,
2519
- null ,
2520
- createTestShardLimitService (randomIntBetween (1 , 1000 ), false , clusterService ),
2521
- mock (Environment .class ),
2522
- IndexScopedSettings .DEFAULT_SCOPED_SETTINGS ,
2523
- threadPool ,
2524
- null ,
2525
- new SystemIndices (Collections .emptyMap ()),
2526
- false ,
2527
- new AwarenessReplicaBalance (Settings .EMPTY , clusterService .getClusterSettings ()),
2528
- DefaultRemoteStoreSettings .INSTANCE ,
2529
- repositoriesServiceSupplier
2530
- );
2507
+ request = new CreateIndexClusterStateUpdateRequest ("create index" , "test" , "test" ).context (new Context (contextName ));
2508
+ withTemporaryClusterService ((clusterService , threadPool ) -> {
2509
+ MetadataCreateIndexService checkerService = new MetadataCreateIndexService (
2510
+ Settings .EMPTY ,
2511
+ clusterService ,
2512
+ indicesServices ,
2513
+ null ,
2514
+ null ,
2515
+ createTestShardLimitService (randomIntBetween (1 , 1000 ), false , clusterService ),
2516
+ mock (Environment .class ),
2517
+ IndexScopedSettings .DEFAULT_SCOPED_SETTINGS ,
2518
+ threadPool ,
2519
+ null ,
2520
+ new SystemIndices (Collections .emptyMap ()),
2521
+ false ,
2522
+ new AwarenessReplicaBalance (Settings .EMPTY , clusterService .getClusterSettings ()),
2523
+ DefaultRemoteStoreSettings .INSTANCE ,
2524
+ repositoriesServiceSupplier
2525
+ );
2531
2526
2532
- ClusterState mockState = mock (ClusterState .class );
2533
- Metadata metadata = mock (Metadata .class );
2527
+ ClusterState mockState = mock (ClusterState .class );
2528
+ Metadata metadata = mock (Metadata .class );
2534
2529
2535
- when (mockState .metadata ()).thenReturn (metadata );
2536
- when (metadata .systemTemplatesLookup ()).thenReturn (Map .of (contextName , new TreeMap <>() {
2537
- {
2538
- put (1L , contextName );
2539
- }
2540
- }));
2541
- when (metadata .componentTemplates ()).thenReturn (Map .of (contextName , componentTemplate .get ()));
2530
+ when (mockState .metadata ()).thenReturn (metadata );
2531
+ when (metadata .systemTemplatesLookup ()).thenReturn (Map .of (contextName , new TreeMap <>() {
2532
+ {
2533
+ put (1L , contextName );
2534
+ }
2535
+ }));
2536
+ when (metadata .componentTemplates ()).thenReturn (Map .of (contextName , componentTemplate .get ()));
2542
2537
2543
- ValidationException validationException = expectThrows (
2544
- ValidationException .class ,
2545
- () -> checkerService .applyContext (request , mockState , List .of (), settingsBuilder )
2546
- );
2547
- assertEquals (1 , validationException .validationErrors ().size ());
2548
- assertTrue (
2549
- "Invalid exception message: " + validationException .getMessage (),
2550
- validationException .getMessage ()
2551
- .contains ("Cannot apply context template as user provide settings have overlap with the included context template" )
2552
- );
2553
- });
2554
- } finally {
2555
- // Disable so that other tests which are not dependent on this are not impacted.
2556
- FeatureFlags .initializeFeatureFlags (
2557
- Settings .builder ().put (FeatureFlags .APPLICATION_BASED_CONFIGURATION_TEMPLATES , false ).build ()
2538
+ ValidationException validationException = expectThrows (
2539
+ ValidationException .class ,
2540
+ () -> checkerService .applyContext (request , mockState , List .of (), settingsBuilder )
2558
2541
);
2559
- }
2542
+ assertEquals (1 , validationException .validationErrors ().size ());
2543
+ assertTrue (
2544
+ "Invalid exception message: " + validationException .getMessage (),
2545
+ validationException .getMessage ()
2546
+ .contains ("Cannot apply context template as user provide settings have overlap with the included context template" )
2547
+ );
2548
+ });
2560
2549
}
2561
2550
2562
2551
private IndexTemplateMetadata addMatchingTemplate (Consumer <IndexTemplateMetadata .Builder > configurator ) {
@@ -2632,9 +2621,4 @@ private DiscoveryNode getRemoteNode() {
2632
2621
);
2633
2622
}
2634
2623
2635
- @ After
2636
- public void shutdown () throws Exception {
2637
- clusterSettings = null ;
2638
- }
2639
-
2640
2624
}
0 commit comments