Skip to content

Commit

Permalink
increasing UT Coverage for edge cases for diff number
Browse files Browse the repository at this point in the history
Signed-off-by: Alfredo Gutierrez Grajeda <[email protected]>
  • Loading branch information
AlfredoG87 committed Mar 11, 2025
1 parent 04f0375 commit 7738e4e
Showing 1 changed file with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,52 @@ public void testDuplicateBlockReceived_NullAckVariation() {
verify(publisher, never()).publish(any());
}

@Test
@DisplayName("Test duplicate block items with different ACK number variation")
public void testDuplicateBlockReceived_DiffAckNumberVariation() {

// given
when(serviceStatus.isRunning()).thenReturn(true);
long latestAckedBlockNumber = 10L;
long latestReceivedBlockNumber = 11L;
Bytes fakeHash = Bytes.wrap("fake_hash");
BlockInfo latestAckedBlock = new BlockInfo(latestAckedBlockNumber);
latestAckedBlock.setBlockHash(fakeHash);
when(serviceStatus.getLatestAckedBlock()).thenReturn(latestAckedBlock);
when(serviceStatus.getLatestReceivedBlockNumber()).thenReturn(latestReceivedBlockNumber);

final List<BlockItemUnparsed> blockItems = generateBlockItemsUnparsedForWithBlockNumber(latestReceivedBlockNumber);
final ProducerBlockItemObserver producerBlockItemObserver = new ProducerBlockItemObserver(
testClock,
publisher,
subscriptionHandler,
helidonPublishPipeline,
serviceStatus,
consumerConfig,
metricsService);

// when
producerBlockItemObserver.onNext(blockItems);

// then
final BlockAcknowledgement blockAcknowledgement = BlockAcknowledgement.newBuilder()
.blockNumber(latestReceivedBlockNumber)
.blockAlreadyExists(true)
.build();

final Acknowledgement acknowledgement =
Acknowledgement.newBuilder().blockAck(blockAcknowledgement).build();

final PublishStreamResponse publishStreamResponse = PublishStreamResponse.newBuilder()
.acknowledgement(acknowledgement)
.build();

// verify helidonPublishPipeline.onNext() is called once with publishStreamResponse
verify(helidonPublishPipeline, timeout(testTimeout).times(1)).onNext(publishStreamResponse);
// verify that the duplicate block is not published
verify(publisher, never()).publish(any());
}

@Test
@DisplayName("Test future (ahead of expected) block received")
public void testFutureBlockReceived() {
Expand Down

0 comments on commit 7738e4e

Please sign in to comment.