|
47 | 47 | import java.util.Set;
|
48 | 48 | import java.util.stream.Collectors;
|
49 | 49 |
|
| 50 | +import static org.opensearch.gateway.ShardsBatchGatewayAllocator.PRIMARY_BATCH_ALLOCATOR_TIMEOUT_SETTING; |
| 51 | +import static org.opensearch.gateway.ShardsBatchGatewayAllocator.PRIMARY_BATCH_ALLOCATOR_TIMEOUT_SETTING_KEY; |
| 52 | +import static org.opensearch.gateway.ShardsBatchGatewayAllocator.REPLICA_BATCH_ALLOCATOR_TIMEOUT_SETTING; |
| 53 | +import static org.opensearch.gateway.ShardsBatchGatewayAllocator.REPLICA_BATCH_ALLOCATOR_TIMEOUT_SETTING_KEY; |
| 54 | + |
50 | 55 | public class GatewayAllocatorTests extends OpenSearchAllocationTestCase {
|
51 | 56 |
|
52 | 57 | private final Logger logger = LogManager.getLogger(GatewayAllocatorTests.class);
|
@@ -368,6 +373,56 @@ public void testCreatePrimaryAndReplicaExecutorOfSizeTwo() {
|
368 | 373 | assertEquals(executor.getTimeoutAwareRunnables().size(), 2);
|
369 | 374 | }
|
370 | 375 |
|
| 376 | + public void testPrimaryAllocatorTimeout() { |
| 377 | + // Valid setting with timeout = 20s |
| 378 | + Settings build = Settings.builder().put(PRIMARY_BATCH_ALLOCATOR_TIMEOUT_SETTING_KEY, "20s").build(); |
| 379 | + assertEquals(20, PRIMARY_BATCH_ALLOCATOR_TIMEOUT_SETTING.get(build).getSeconds()); |
| 380 | + |
| 381 | + // Valid setting with timeout > 20s |
| 382 | + build = Settings.builder().put(PRIMARY_BATCH_ALLOCATOR_TIMEOUT_SETTING_KEY, "30000ms").build(); |
| 383 | + assertEquals(30, PRIMARY_BATCH_ALLOCATOR_TIMEOUT_SETTING.get(build).getSeconds()); |
| 384 | + |
| 385 | + // Invalid setting with timeout < 20s |
| 386 | + Settings lessThan20sSetting = Settings.builder().put(PRIMARY_BATCH_ALLOCATOR_TIMEOUT_SETTING_KEY, "10s").build(); |
| 387 | + IllegalArgumentException iae = expectThrows( |
| 388 | + IllegalArgumentException.class, |
| 389 | + () -> PRIMARY_BATCH_ALLOCATOR_TIMEOUT_SETTING.get(lessThan20sSetting) |
| 390 | + ); |
| 391 | + assertEquals( |
| 392 | + "Setting [" + PRIMARY_BATCH_ALLOCATOR_TIMEOUT_SETTING.getKey() + "] should be more than 20s or -1ms to disable timeout", |
| 393 | + iae.getMessage() |
| 394 | + ); |
| 395 | + |
| 396 | + // Valid setting with timeout = -1 |
| 397 | + build = Settings.builder().put(PRIMARY_BATCH_ALLOCATOR_TIMEOUT_SETTING_KEY, "-1").build(); |
| 398 | + assertEquals(-1, PRIMARY_BATCH_ALLOCATOR_TIMEOUT_SETTING.get(build).getMillis()); |
| 399 | + } |
| 400 | + |
| 401 | + public void testReplicaAllocatorTimeout() { |
| 402 | + // Valid setting with timeout = 20s |
| 403 | + Settings build = Settings.builder().put(REPLICA_BATCH_ALLOCATOR_TIMEOUT_SETTING_KEY, "20s").build(); |
| 404 | + assertEquals(20, REPLICA_BATCH_ALLOCATOR_TIMEOUT_SETTING.get(build).getSeconds()); |
| 405 | + |
| 406 | + // Valid setting with timeout > 20s |
| 407 | + build = Settings.builder().put(REPLICA_BATCH_ALLOCATOR_TIMEOUT_SETTING_KEY, "30000ms").build(); |
| 408 | + assertEquals(30, REPLICA_BATCH_ALLOCATOR_TIMEOUT_SETTING.get(build).getSeconds()); |
| 409 | + |
| 410 | + // Invalid setting with timeout < 20s |
| 411 | + Settings lessThan20sSetting = Settings.builder().put(REPLICA_BATCH_ALLOCATOR_TIMEOUT_SETTING_KEY, "10s").build(); |
| 412 | + IllegalArgumentException iae = expectThrows( |
| 413 | + IllegalArgumentException.class, |
| 414 | + () -> REPLICA_BATCH_ALLOCATOR_TIMEOUT_SETTING.get(lessThan20sSetting) |
| 415 | + ); |
| 416 | + assertEquals( |
| 417 | + "Setting [" + REPLICA_BATCH_ALLOCATOR_TIMEOUT_SETTING.getKey() + "] should be more than 20s or -1ms to disable timeout", |
| 418 | + iae.getMessage() |
| 419 | + ); |
| 420 | + |
| 421 | + // Valid setting with timeout = -1 |
| 422 | + build = Settings.builder().put(REPLICA_BATCH_ALLOCATOR_TIMEOUT_SETTING_KEY, "-1").build(); |
| 423 | + assertEquals(-1, REPLICA_BATCH_ALLOCATOR_TIMEOUT_SETTING.get(build).getMillis()); |
| 424 | + } |
| 425 | + |
371 | 426 | private void createIndexAndUpdateClusterState(int count, int numberOfShards, int numberOfReplicas) {
|
372 | 427 | if (count == 0) return;
|
373 | 428 | Metadata.Builder metadata = Metadata.builder();
|
|
0 commit comments