Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
Signed-off-by: Rishab Nahata <[email protected]>
  • Loading branch information
imRishN committed Oct 28, 2024
1 parent 2ba604d commit 6e3b4d0
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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<String, IndexMetadata> entry : metadata.getIndices().entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 6e3b4d0

Please sign in to comment.