diff --git a/server/src/test/java/org/opensearch/cluster/routing/allocation/allocator/TimeBoundBalancedShardsAllocatorTests.java b/server/src/test/java/org/opensearch/cluster/routing/allocation/allocator/TimeBoundBalancedShardsAllocatorTests.java index c6705a678e077..8899b4ee8f68d 100644 --- a/server/src/test/java/org/opensearch/cluster/routing/allocation/allocator/TimeBoundBalancedShardsAllocatorTests.java +++ b/server/src/test/java/org/opensearch/cluster/routing/allocation/allocator/TimeBoundBalancedShardsAllocatorTests.java @@ -46,6 +46,7 @@ import static org.opensearch.cluster.routing.ShardRoutingState.INITIALIZING; import static org.opensearch.cluster.routing.ShardRoutingState.STARTED; import static org.opensearch.cluster.routing.allocation.allocator.BalancedShardsAllocator.ALLOCATOR_TIMEOUT_SETTING; +import static org.opensearch.cluster.routing.allocation.allocator.BalancedShardsAllocator.FOLLOW_UP_REROUTE_PRIORITY_SETTING; public class TimeBoundBalancedShardsAllocatorTests extends OpenSearchAllocationTestCase { @@ -604,6 +605,32 @@ public void testAllocatorTimeout() { assertEquals(-1, ALLOCATOR_TIMEOUT_SETTING.get(build).getMillis()); } + public void testFollowupPriorityValues() { + String settingKey = "cluster.routing.allocation.balanced_shards_allocator.schedule_reroute.priority"; + Settings build = Settings.builder().put(settingKey, "normal").build(); + assertEquals(Priority.NORMAL, FOLLOW_UP_REROUTE_PRIORITY_SETTING.get(build)); + + build = Settings.builder().put(settingKey, "high").build(); + assertEquals(Priority.HIGH, FOLLOW_UP_REROUTE_PRIORITY_SETTING.get(build)); + + build = Settings.builder().put(settingKey, "urgent").build(); + assertEquals(Priority.URGENT, FOLLOW_UP_REROUTE_PRIORITY_SETTING.get(build)); + + Settings wrongPriority = Settings.builder().put(settingKey, "immediate").build(); + IllegalArgumentException iae = expectThrows( + IllegalArgumentException.class, + () -> FOLLOW_UP_REROUTE_PRIORITY_SETTING.get(wrongPriority) + ); + assertEquals("priority [IMMEDIATE] not supported for [" + FOLLOW_UP_REROUTE_PRIORITY_SETTING.getKey() + "]", iae.getMessage()); + + Settings wrongPriority2 = Settings.builder().put(settingKey, "random").build(); + IllegalArgumentException iae2 = expectThrows( + IllegalArgumentException.class, + () -> FOLLOW_UP_REROUTE_PRIORITY_SETTING.get(wrongPriority2) + ); + assertEquals("No enum constant org.opensearch.common.Priority.RANDOM", iae2.getMessage()); + } + private RoutingTable buildRoutingTable(Metadata metadata) { RoutingTable.Builder routingTableBuilder = RoutingTable.builder(); for (Map.Entry entry : metadata.getIndices().entrySet()) { diff --git a/server/src/test/java/org/opensearch/gateway/GatewayAllocatorTests.java b/server/src/test/java/org/opensearch/gateway/GatewayAllocatorTests.java index be2486846d401..7a3b5f576449c 100644 --- a/server/src/test/java/org/opensearch/gateway/GatewayAllocatorTests.java +++ b/server/src/test/java/org/opensearch/gateway/GatewayAllocatorTests.java @@ -540,6 +540,35 @@ public void testCollectTimedOutShardsAndScheduleReroute_Failure() throws Interru clusterService.close(); } + public void testFollowupPriorityValues() { + String settingKey = "cluster.routing.allocation.shards_batch_gateway_allocator.schedule_reroute.priority"; + Settings build = Settings.builder().put(settingKey, "normal").build(); + assertEquals(Priority.NORMAL, ShardsBatchGatewayAllocator.FOLLOW_UP_REROUTE_PRIORITY_SETTING.get(build)); + + build = Settings.builder().put(settingKey, "high").build(); + assertEquals(Priority.HIGH, ShardsBatchGatewayAllocator.FOLLOW_UP_REROUTE_PRIORITY_SETTING.get(build)); + + build = Settings.builder().put(settingKey, "urgent").build(); + assertEquals(Priority.URGENT, ShardsBatchGatewayAllocator.FOLLOW_UP_REROUTE_PRIORITY_SETTING.get(build)); + + Settings wrongPriority = Settings.builder().put(settingKey, "immediate").build(); + IllegalArgumentException iae = expectThrows( + IllegalArgumentException.class, + () -> ShardsBatchGatewayAllocator.FOLLOW_UP_REROUTE_PRIORITY_SETTING.get(wrongPriority) + ); + assertEquals( + "priority [IMMEDIATE] not supported for [" + ShardsBatchGatewayAllocator.FOLLOW_UP_REROUTE_PRIORITY_SETTING.getKey() + "]", + iae.getMessage() + ); + + Settings wrongPriority2 = Settings.builder().put(settingKey, "random").build(); + IllegalArgumentException iae2 = expectThrows( + IllegalArgumentException.class, + () -> ShardsBatchGatewayAllocator.FOLLOW_UP_REROUTE_PRIORITY_SETTING.get(wrongPriority2) + ); + assertEquals("No enum constant org.opensearch.common.Priority.RANDOM", iae2.getMessage()); + } + private void createIndexAndUpdateClusterState(int count, int numberOfShards, int numberOfReplicas) { if (count == 0) return; Metadata.Builder metadata = Metadata.builder();