From f34a0342da37b908be14dbdf58aa137b16e5624d Mon Sep 17 00:00:00 2001 From: georgi-l95 Date: Mon, 11 Nov 2024 16:21:45 +0200 Subject: [PATCH] test: unit test Signed-off-by: georgi-l95 --- .../simulator/BlockStreamSimulatorTest.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/simulator/src/test/java/com/hedera/block/simulator/BlockStreamSimulatorTest.java b/simulator/src/test/java/com/hedera/block/simulator/BlockStreamSimulatorTest.java index 2e93f0c8c..a233de21b 100644 --- a/simulator/src/test/java/com/hedera/block/simulator/BlockStreamSimulatorTest.java +++ b/simulator/src/test/java/com/hedera/block/simulator/BlockStreamSimulatorTest.java @@ -18,7 +18,9 @@ import static com.hedera.block.simulator.TestUtils.getTestMetrics; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; @@ -26,6 +28,7 @@ import static org.mockito.Mockito.when; import com.hedera.block.simulator.config.data.BlockStreamConfig; +import com.hedera.block.simulator.config.data.StreamStatus; import com.hedera.block.simulator.exception.BlockSimulatorParsingException; import com.hedera.block.simulator.generator.BlockStreamManager; import com.hedera.block.simulator.grpc.PublishStreamGrpcClient; @@ -238,6 +241,29 @@ void constructor_throwsExceptionForNullSimulatorMode() { }); } + @Test + void testGetStreamStatus() { + int expectedPublishedBlocks = 5; + List expectedLastKnownStatuses = List.of("Status1", "Status2"); + + when(publishStreamGrpcClient.getPublishedBlocks()).thenReturn(expectedPublishedBlocks); + when(publishStreamGrpcClient.getLastKnownStatuses()).thenReturn(expectedLastKnownStatuses); + + StreamStatus streamStatus = blockStreamSimulator.getStreamStatus(); + + assertNotNull(streamStatus, "StreamStatus should not be null"); + assertEquals(expectedPublishedBlocks, streamStatus.publishedBlocks(), "Published blocks should match"); + assertEquals( + expectedLastKnownStatuses, + streamStatus.lastKnownPublisherStatuses(), + "Last known statuses should match"); + assertEquals(0, streamStatus.consumedBlocks(), "Consumed blocks should be 0 by default"); + assertEquals( + 0, + streamStatus.lastKnownConsumersStatuses().size(), + "Last known consumers statuses should be empty by default"); + } + private List captureLogs() { // Capture logs Logger logger = Logger.getLogger(PublisherModeHandler.class.getName());