From fb44e2bc13d32affdd45fa7784532212b9fa66b7 Mon Sep 17 00:00:00 2001 From: Matt Peterson Date: Thu, 1 Aug 2024 19:32:42 -0600 Subject: [PATCH] fix: added 2 more tests Signed-off-by: Matt Peterson --- .../block/server/BlockStreamServiceTest.java | 25 +++++++++++++++++++ .../mediator/LiveStreamMediatorImplTest.java | 20 +++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/server/src/test/java/com/hedera/block/server/BlockStreamServiceTest.java b/server/src/test/java/com/hedera/block/server/BlockStreamServiceTest.java index 1df68cc23..b2593e65e 100644 --- a/server/src/test/java/com/hedera/block/server/BlockStreamServiceTest.java +++ b/server/src/test/java/com/hedera/block/server/BlockStreamServiceTest.java @@ -19,6 +19,7 @@ import static com.hedera.block.protos.BlockStreamService.*; import static com.hedera.block.server.BlockStreamService.buildSingleBlockNotAvailableResponse; import static com.hedera.block.server.BlockStreamService.buildSingleBlockNotFoundResponse; +import static com.hedera.block.server.Constants.*; import static com.hedera.block.server.util.PersistTestUtils.generateBlockItems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; @@ -36,6 +37,7 @@ import com.hedera.block.server.persistence.storage.BlockWriter; import com.hedera.block.server.producer.ItemAckBuilder; import com.hedera.block.server.util.TestUtils; +import io.grpc.stub.ServerCalls; import io.grpc.stub.StreamObserver; import io.helidon.config.Config; import io.helidon.config.MapConfigSource; @@ -47,6 +49,10 @@ import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.function.BiConsumer; + +import io.helidon.webserver.Routing; +import io.helidon.webserver.grpc.GrpcService; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -246,6 +252,25 @@ public void testSingleBlockIOExceptionPath() throws IOException { verify(responseObserver, times(1)).onNext(expectedNotAvailable); } + @Test + public void testUpdateInvokesRoutingWithLambdas() { + + final BlockStreamService blockStreamService = + new BlockStreamService( + TIMEOUT_THRESHOLD_MILLIS, + itemAckBuilder, + streamMediator, + blockPersistenceHandler, + serviceStatus); + + GrpcService.Routing routing = mock(GrpcService.Routing.class); + blockStreamService.update(routing); + + verify(routing, timeout(50).times(1)).bidi(eq(CLIENT_STREAMING_METHOD_NAME), any(ServerCalls.BidiStreamingMethod.class)); + verify(routing, timeout(50).times(1)).serverStream(eq(SERVER_STREAMING_METHOD_NAME), any(ServerCalls.ServerStreamingMethod.class)); + verify(routing, timeout(50).times(1)).unary(eq(SINGLE_BLOCK_METHOD_NAME), any(ServerCalls.UnaryMethod.class)); + } + private BlockPersistenceHandler buildBlockPersistenceHandler() throws IOException { BlockReader blockReader = new BlockAsDirReader(JUNIT, testConfig); diff --git a/server/src/test/java/com/hedera/block/server/mediator/LiveStreamMediatorImplTest.java b/server/src/test/java/com/hedera/block/server/mediator/LiveStreamMediatorImplTest.java index 9d0a3d33a..b94491556 100644 --- a/server/src/test/java/com/hedera/block/server/mediator/LiveStreamMediatorImplTest.java +++ b/server/src/test/java/com/hedera/block/server/mediator/LiveStreamMediatorImplTest.java @@ -295,6 +295,26 @@ public void testMediatorBlocksPublishAfterException() throws IOException, Interr } } + @Test + public void testUnsubscribeWhenNotSubscribed() { + final var streamMediator = new LiveStreamMediatorImpl(blockPersistenceHandler); + final var testConsumerBlockItemObserver = + new TestConsumerBlockItemObserver( + TIMEOUT_THRESHOLD_MILLIS, + testClock, + streamMediator, + serverCallStreamObserver); + + // Confirm the observer is not subscribed + assertFalse(streamMediator.isSubscribed(testConsumerBlockItemObserver)); + + // Attempt to unsubscribe the observer + streamMediator.unsubscribe(testConsumerBlockItemObserver); + + // Confirm the observer is still not subscribed + assertFalse(streamMediator.isSubscribed(testConsumerBlockItemObserver)); + } + private static class TestConsumerBlockItemObserver extends ConsumerBlockItemObserver { public TestConsumerBlockItemObserver( long timeoutThresholdMillis,