Skip to content

Commit

Permalink
Add tests for ShardsBatchGatewayAllocator
Browse files Browse the repository at this point in the history
Signed-off-by: Rishab Nahata <[email protected]>
  • Loading branch information
imRishN committed Jul 24, 2024
1 parent b1a612e commit 07befa2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public BatchRunnableExecutor(List<TimeoutAwareRunnable> timeoutAwareRunnables, S
this.timeoutAwareRunnables = timeoutAwareRunnables;
}

// for tests
public List<TimeoutAwareRunnable> getTimeoutAwareRunnables() {
return this.timeoutAwareRunnables;
}

@Override
public void run() {
logger.debug("Starting execution of runnable of size [{}]", timeoutAwareRunnables.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,30 @@ public void testGetBatchIdNonExisting() {
allShardRoutings.forEach(shard -> assertNull(testShardsBatchGatewayAllocator.getBatchId(shard, shard.primary())));
}

public void testCreatePrimaryAndReplicaExecutorOfSizeOne() {
createIndexAndUpdateClusterState(1, 3, 2);
BatchRunnableExecutor executor = testShardsBatchGatewayAllocator.allocateAllUnassignedShards(testAllocation, true);
assertEquals(executor.getTimeoutAwareRunnables().size(), 1);
executor = testShardsBatchGatewayAllocator.allocateAllUnassignedShards(testAllocation, false);
assertEquals(executor.getTimeoutAwareRunnables().size(), 1);
}

public void testCreatePrimaryExecutorOfSizeOneAndReplicaExecutorOfSizeZero() {
createIndexAndUpdateClusterState(1, 3, 0);
BatchRunnableExecutor executor = testShardsBatchGatewayAllocator.allocateAllUnassignedShards(testAllocation, true);
assertEquals(executor.getTimeoutAwareRunnables().size(), 1);
executor = testShardsBatchGatewayAllocator.allocateAllUnassignedShards(testAllocation, false);
assertNull(executor);
}

public void testCreatePrimaryAndReplicaExecutorOfSizeTwo() {
createIndexAndUpdateClusterState(2, 1001, 1);
BatchRunnableExecutor executor = testShardsBatchGatewayAllocator.allocateAllUnassignedShards(testAllocation, true);
assertEquals(executor.getTimeoutAwareRunnables().size(), 2);
executor = testShardsBatchGatewayAllocator.allocateAllUnassignedShards(testAllocation, false);
assertEquals(executor.getTimeoutAwareRunnables().size(), 2);
}

private void createIndexAndUpdateClusterState(int count, int numberOfShards, int numberOfReplicas) {
if (count == 0) return;
Metadata.Builder metadata = Metadata.builder();
Expand Down

0 comments on commit 07befa2

Please sign in to comment.