Skip to content

Commit

Permalink
fix: added test coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Peterson <[email protected]>
  • Loading branch information
mattp-swirldslabs committed Jul 30, 2024
1 parent 92cbe23 commit 001f8a9
Showing 1 changed file with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ void testSingleBlockNotFoundPath() throws IOException {
}

@Test
void testSingleBlockServiceNotAvailable() throws IOException {
// Call the service
void testSingleBlockServiceNotAvailable() {

final BlockStreamService blockStreamService =
new BlockStreamService(
TIMEOUT_THRESHOLD_MILLIS,
Expand All @@ -212,6 +212,29 @@ void testSingleBlockServiceNotAvailable() throws IOException {
verify(responseObserver, times(1)).onNext(expectedNotAvailable);
}

@Test
public void testSingleBlockIOExceptionPath() throws IOException {
final BlockStreamService blockStreamService =
new BlockStreamService(
TIMEOUT_THRESHOLD_MILLIS,
itemAckBuilder,
streamMediator,
blockPersistenceHandler,
serviceStatus);

// Set the service status to not running
when(serviceStatus.isRunning()).thenReturn(true);
when(blockPersistenceHandler.retrieve(1)).thenThrow(new IOException("Test exception"));

final SingleBlockResponse expectedNotAvailable = buildSingleBlockNotAvailableResponse();

// Build a request to invoke the service
final SingleBlockRequest singleBlockRequest =
SingleBlockRequest.newBuilder().setBlockNumber(1).build();
blockStreamService.singleBlock(singleBlockRequest, responseObserver);
verify(responseObserver, times(1)).onNext(expectedNotAvailable);
}

private BlockPersistenceHandler<BlockItem, Block> buildBlockPersistenceHandler()
throws IOException {
BlockReader<Block> blockReader = new BlockAsDirReader(JUNIT, testConfig);
Expand Down

0 comments on commit 001f8a9

Please sign in to comment.