5555import org .opensearch .common .settings .Settings ;
5656import org .opensearch .common .util .FeatureFlags ;
5757import org .opensearch .core .common .unit .ByteSizeValue ;
58- import org .opensearch .index .query .Rewriteable ;
59- import org .opensearch .index .query .RewriteableTests ;
6058import org .opensearch .index .shard .DocsStats ;
6159import org .opensearch .index .store .StoreStats ;
6260import org .opensearch .node .remotestore .RemoteStoreNodeService ;
6361import org .opensearch .snapshots .EmptySnapshotsInfoService ;
6462import org .opensearch .test .OpenSearchTestCase ;
6563import org .opensearch .test .gateway .TestGatewayAllocator ;
6664
67- import static org .hamcrest .CoreMatchers .startsWith ;
68- import static org .hamcrest .Matchers .*;
69- import static org .opensearch .cluster .metadata .IndexMetadata .SETTING_REMOTE_STORE_ENABLED ;
70- import static org .opensearch .node .remotestore .RemoteStoreNodeService .CompatibilityMode ;
71-
72-
7365import java .util .Arrays ;
7466import java .util .Collections ;
7567import java .util .HashSet ;
7668import java .util .Set ;
7769
7870import static java .util .Collections .emptyMap ;
71+ import static org .opensearch .cluster .metadata .IndexMetadata .SETTING_REMOTE_STORE_ENABLED ;
72+ import static org .opensearch .common .util .FeatureFlags .REMOTE_STORE_MIGRATION_EXPERIMENTAL ;
73+ import static org .opensearch .node .remotestore .RemoteStoreNodeService .CompatibilityMode ;
7974import static org .opensearch .node .remotestore .RemoteStoreNodeService .MIGRATION_DIRECTION_SETTING ;
8075import static org .opensearch .node .remotestore .RemoteStoreNodeService .REMOTE_STORE_COMPATIBILITY_MODE_SETTING ;
81- import static org .opensearch . common . util . FeatureFlags . REMOTE_STORE_MIGRATION_EXPERIMENTAL ;
76+ import static org .hamcrest . CoreMatchers . equalTo ;
8277
8378public class TransportResizeActionTests extends OpenSearchTestCase {
8479
@@ -108,10 +103,14 @@ private ClusterState createClusterState(String name, int numShards, int numRepli
108103 return clusterState ;
109104 }
110105
111- private ClusterSettings createClusterSettings (CompatibilityMode compatibilityMode , RemoteStoreNodeService .Direction migrationDirection ) {
106+ private ClusterSettings createClusterSettings (
107+ CompatibilityMode compatibilityMode ,
108+ RemoteStoreNodeService .Direction migrationDirection
109+ ) {
112110 ClusterSettings clusterSettings = new ClusterSettings (Settings .EMPTY , ClusterSettings .BUILT_IN_CLUSTER_SETTINGS );
113111 clusterSettings .applySettings (
114- (Settings .builder ().put (REMOTE_STORE_COMPATIBILITY_MODE_SETTING .getKey (), compatibilityMode )
112+ (Settings .builder ()
113+ .put (REMOTE_STORE_COMPATIBILITY_MODE_SETTING .getKey (), compatibilityMode )
115114 .put (MIGRATION_DIRECTION_SETTING .getKey (), migrationDirection )).build ()
116115 );
117116 return clusterSettings ;
@@ -124,7 +123,7 @@ public void testErrorCondition() {
124123 randomIntBetween (0 , 10 ),
125124 Settings .builder ().put ("index.blocks.write" , true ).build ()
126125 );
127- ClusterSettings clusterSettings = createClusterSettings (CompatibilityMode .STRICT ,RemoteStoreNodeService .Direction .NONE );
126+ ClusterSettings clusterSettings = createClusterSettings (CompatibilityMode .STRICT , RemoteStoreNodeService .Direction .NONE );
128127 assertTrue (
129128 expectThrows (
130129 IllegalStateException .class ,
@@ -216,7 +215,7 @@ public void testPassNumRoutingShards() {
216215 EmptyClusterInfoService .INSTANCE ,
217216 EmptySnapshotsInfoService .INSTANCE
218217 );
219- ClusterSettings clusterSettings = createClusterSettings (CompatibilityMode .STRICT ,RemoteStoreNodeService .Direction .NONE );
218+ ClusterSettings clusterSettings = createClusterSettings (CompatibilityMode .STRICT , RemoteStoreNodeService .Direction .NONE );
220219 RoutingTable routingTable = service .reroute (clusterState , "reroute" ).routingTable ();
221220 clusterState = ClusterState .builder (clusterState ).routingTable (routingTable ).build ();
222221 // now we start the shard
@@ -264,7 +263,7 @@ public void testPassNumRoutingShardsAndFail() {
264263 EmptySnapshotsInfoService .INSTANCE
265264 );
266265
267- ClusterSettings clusterSettings = createClusterSettings (CompatibilityMode .STRICT ,RemoteStoreNodeService .Direction .NONE );
266+ ClusterSettings clusterSettings = createClusterSettings (CompatibilityMode .STRICT , RemoteStoreNodeService .Direction .NONE );
268267 RoutingTable routingTable = service .reroute (clusterState , "reroute" ).routingTable ();
269268 clusterState = ClusterState .builder (clusterState ).routingTable (routingTable ).build ();
270269 // now we start the shard
@@ -318,7 +317,7 @@ public void testShrinkIndexSettings() {
318317 EmptySnapshotsInfoService .INSTANCE
319318 );
320319
321- ClusterSettings clusterSettings = createClusterSettings (CompatibilityMode .STRICT ,RemoteStoreNodeService .Direction .NONE );
320+ ClusterSettings clusterSettings = createClusterSettings (CompatibilityMode .STRICT , RemoteStoreNodeService .Direction .NONE );
322321 RoutingTable routingTable = service .reroute (clusterState , "reroute" ).routingTable ();
323322 clusterState = ClusterState .builder (clusterState ).routingTable (routingTable ).build ();
324323 // now we start the shard
@@ -360,7 +359,7 @@ public void testShrinkWithMaxShardSize() {
360359 EmptySnapshotsInfoService .INSTANCE
361360 );
362361
363- ClusterSettings clusterSettings = createClusterSettings (CompatibilityMode .STRICT ,RemoteStoreNodeService .Direction .NONE );
362+ ClusterSettings clusterSettings = createClusterSettings (CompatibilityMode .STRICT , RemoteStoreNodeService .Direction .NONE );
364363 RoutingTable routingTable = service .reroute (clusterState , "reroute" ).routingTable ();
365364 clusterState = ClusterState .builder (clusterState ).routingTable (routingTable ).build ();
366365 // now we start the shard
@@ -516,7 +515,7 @@ public void testIndexBlocks() {
516515 createClusterState (indexName , 10 , 0 , 40 , Settings .builder ().put ("index.blocks.read_only" , true ).build ())
517516 ).nodes (DiscoveryNodes .builder ().add (newNode ("node1" ))).build ();
518517
519- ClusterSettings clusterSettings = createClusterSettings (CompatibilityMode .STRICT ,RemoteStoreNodeService .Direction .NONE );
518+ ClusterSettings clusterSettings = createClusterSettings (CompatibilityMode .STRICT , RemoteStoreNodeService .Direction .NONE );
520519 // Target index will be blocked by [index.blocks.read_only=true] copied from the source index
521520 ResizeRequest resizeRequest = new ResizeRequest ("target" , indexName );
522521 ResizeType resizeType ;
@@ -604,24 +603,27 @@ public void testIndexBlocks() {
604603 }
605604
606605 public void testResizeFailuresDuringMigration () {
607- //We will keep all other settings correct for resize request,
608- //So we only need to test for the failures due to cluster setting validation while migration
606+ // We will keep all other settings correct for resize request,
607+ // So we only need to test for the failures due to cluster setting validation while migration
609608 final Settings directionEnabledNodeSettings = Settings .builder ().put (REMOTE_STORE_MIGRATION_EXPERIMENTAL , "true" ).build ();
610609 FeatureFlags .initializeFeatureFlags (directionEnabledNodeSettings );
611610 boolean isRemoteStoreEnabled = randomBoolean ();
612611 CompatibilityMode compatibilityMode = randomFrom (CompatibilityMode .values ());
613612 RemoteStoreNodeService .Direction migrationDirection = randomFrom (RemoteStoreNodeService .Direction .values ());
614- //If not mixed mode, then migration direction is NONE.
615- if (!compatibilityMode .equals (CompatibilityMode .MIXED )){
613+ // If not mixed mode, then migration direction is NONE.
614+ if (!compatibilityMode .equals (CompatibilityMode .MIXED )) {
616615 migrationDirection = RemoteStoreNodeService .Direction .NONE ;
617616 }
618- ClusterSettings clusterSettings = createClusterSettings (compatibilityMode ,migrationDirection );
617+ ClusterSettings clusterSettings = createClusterSettings (compatibilityMode , migrationDirection );
619618
620619 ClusterState clusterState = ClusterState .builder (
621- createClusterState ("source" , 10 , 0 ,40 ,
622- Settings .builder ().put ("index.blocks.write" , true )
623- .put (SETTING_REMOTE_STORE_ENABLED , isRemoteStoreEnabled )
624- .build ())
620+ createClusterState (
621+ "source" ,
622+ 10 ,
623+ 0 ,
624+ 40 ,
625+ Settings .builder ().put ("index.blocks.write" , true ).put (SETTING_REMOTE_STORE_ENABLED , isRemoteStoreEnabled ).build ()
626+ )
625627 ).nodes (DiscoveryNodes .builder ().add (newNode ("node1" ))).build ();
626628 AllocationService service = new AllocationService (
627629 new AllocationDeciders (Collections .singleton (new MaxRetryAllocationDecider ())),
@@ -662,14 +664,14 @@ public void testResizeFailuresDuringMigration() {
662664 .settings (Settings .builder ().put ("index.number_of_shards" , expectedShardsNum ).put ("index.blocks.read_only" , false ).build ());
663665 final ActiveShardCount activeShardCount = randomBoolean () ? ActiveShardCount .ALL : ActiveShardCount .ONE ;
664666 resizeRequest .setWaitForActiveShards (activeShardCount );
665- //startsWith("index Resizing for type [")
667+ // startsWith("index Resizing for type [")
666668 if (compatibilityMode == CompatibilityMode .MIXED
667669 && migrationDirection == RemoteStoreNodeService .Direction .REMOTE_STORE
668670 && !isRemoteStoreEnabled ) {
669671 ClusterState finalState = clusterState ;
670672 IllegalStateException ise = expectThrows (
671673 IllegalStateException .class ,
672- () ->TransportResizeAction .prepareCreateIndexRequest (
674+ () -> TransportResizeAction .prepareCreateIndexRequest (
673675 new ResizeRequest ("target" , "source" ),
674676 finalState ,
675677 (i ) -> stats ,
@@ -679,12 +681,12 @@ public void testResizeFailuresDuringMigration() {
679681 "target"
680682 )
681683 );
682- assertThat (
684+ assertEquals (
683685 ise .getMessage (),
684- allOf (
685- startsWith ( "index Resizing for type" ),
686- endsWith ( "Cluster mode is [Mixed] and migration direction is [Remote Store]" )
687- )
686+ "index Resizing for type ["
687+ + resizeType
688+ + "] is not allowed as Cluster mode is [Mixed]"
689+ + " and migration direction is [Remote Store]"
688690 );
689691 } else {
690692 CreateIndexClusterStateUpdateRequest request = TransportResizeAction .prepareCreateIndexRequest (
0 commit comments