Skip to content

Commit

Permalink
Added unit test to make sure BlockItems are dropped if none contain a…
Browse files Browse the repository at this point in the history
… Header

Signed-off-by: Matt Peterson <[email protected]>
  • Loading branch information
mattp-swirldslabs committed Jul 17, 2024
1 parent 713beed commit 827347e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

package com.hedera.block.server.consumer;

import static com.hedera.block.protos.BlockStreamService.BlockItem;
import static com.hedera.block.protos.BlockStreamService.SubscribeStreamResponse;
import static com.hedera.block.protos.BlockStreamService.*;
import static com.hedera.block.server.util.TestClock.buildClockInsideWindow;
import static com.hedera.block.server.util.TestClock.buildClockOutsideWindow;
import static org.mockito.Mockito.*;
Expand Down Expand Up @@ -83,4 +82,44 @@ public void testProducerTimeoutOutsideWindow() throws InterruptedException {
consumerBlockItemObserver.onEvent(objectEvent, 0, true);
verify(streamMediator).unsubscribe(consumerBlockItemObserver);
}

@Test
public void testStuff() throws InterruptedException {
final var consumerBlockItemObserver =
new ConsumerBlockItemObserver(
TIMEOUT_THRESHOLD_MILLIS,
buildClockInsideWindow(TEST_TIME, TIMEOUT_THRESHOLD_MILLIS),
streamMediator,
responseStreamObserver);

for (int i = 1; i <= 10; i++) {

if (i % 2 == 0) {
final EventMetadata eventMetadata =
EventMetadata.newBuilder().setCreatorId(i).build();
final BlockItem blockItem =
BlockItem.newBuilder().setStartEvent(eventMetadata).build();
when(objectEvent.get()).thenReturn(blockItem);
} else {
final BlockProof blockProof = BlockProof.newBuilder().setBlock(i).build();
final BlockItem blockItem =
BlockItem.newBuilder().setStateProof(blockProof).build();
when(objectEvent.get()).thenReturn(blockItem);
}

consumerBlockItemObserver.onEvent(objectEvent, 0, true);
}

final BlockItem blockItem = BlockItem.newBuilder().build();
final SubscribeStreamResponse subscribeStreamResponse =
SubscribeStreamResponse.newBuilder().setBlockItem(blockItem).build();

synchronized (responseStreamObserver) {
responseStreamObserver.wait(2000);
}

// Confirm that the observer was called with the next BlockItem
// since we never send a BlockItem with a Header to start the stream.
verify(responseStreamObserver, never()).onNext(subscribeStreamResponse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public TestClock(Long... millis) {

@Override
public long millis() {
LOGGER.log(System.Logger.Level.INFO, "millis() called");
long value = millis[index];

// cycle through the provided millis
Expand Down

0 comments on commit 827347e

Please sign in to comment.