Skip to content

Commit

Permalink
test: unit test
Browse files Browse the repository at this point in the history
Signed-off-by: georgi-l95 <[email protected]>
  • Loading branch information
georgi-l95 committed Nov 11, 2024
1 parent 5eff4f5 commit f34a034
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@

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;
import static org.mockito.Mockito.mock;
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;
Expand Down Expand Up @@ -238,6 +241,29 @@ void constructor_throwsExceptionForNullSimulatorMode() {
});
}

@Test
void testGetStreamStatus() {
int expectedPublishedBlocks = 5;
List<String> 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<LogRecord> captureLogs() {
// Capture logs
Logger logger = Logger.getLogger(PublisherModeHandler.class.getName());
Expand Down

0 comments on commit f34a034

Please sign in to comment.