Skip to content

Commit

Permalink
fix: added 2 more tests
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Peterson <[email protected]>
  • Loading branch information
mattp-swirldslabs committed Aug 2, 2024
1 parent a08c333 commit fb44e2b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<BlockItem, Block> buildBlockPersistenceHandler()
throws IOException {
BlockReader<Block> blockReader = new BlockAsDirReader(JUNIT, testConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit fb44e2b

Please sign in to comment.