diff --git a/server/src/main/java/com/hedera/block/server/BlockStreamService.java b/server/src/main/java/com/hedera/block/server/BlockStreamService.java index 20d8e4d81..956f8213a 100644 --- a/server/src/main/java/com/hedera/block/server/BlockStreamService.java +++ b/server/src/main/java/com/hedera/block/server/BlockStreamService.java @@ -26,7 +26,6 @@ import com.hedera.block.server.mediator.StreamMediator; import com.hedera.block.server.persistence.BlockPersistenceHandler; import com.hedera.block.server.producer.ProducerBlockStreamObserver; -import io.grpc.Status; import io.grpc.stub.StreamObserver; import io.helidon.webserver.grpc.GrpcService; import java.time.Clock; @@ -169,7 +168,8 @@ void getBlock( responseBlock.get()); // TODO: Should return int and not quoted string } else { LOGGER.log(System.Logger.Level.INFO, "DID NOT FIND YOUR BLOCK"); - responseObserver.onNext(BlockStreamServiceGrpcProto.Block.newBuilder().setId(0).build()); + responseObserver.onNext( + BlockStreamServiceGrpcProto.Block.newBuilder().setId(0).build()); } } } 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 6da7436fb..fffb58847 100644 --- a/server/src/test/java/com/hedera/block/server/BlockStreamServiceTest.java +++ b/server/src/test/java/com/hedera/block/server/BlockStreamServiceTest.java @@ -1,53 +1,74 @@ +/* + * Copyright (C) 2024 Hedera Hashgraph, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.hedera.block.server; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; + import com.hedera.block.protos.BlockStreamServiceGrpcProto; import com.hedera.block.server.mediator.StreamMediator; import com.hedera.block.server.persistence.BlockPersistenceHandler; -import io.grpc.Status; import io.grpc.stub.StreamObserver; +import java.util.Optional; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import java.util.Optional; - -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.*; - @ExtendWith(MockitoExtension.class) class BlockStreamServiceTest { private final long TIMEOUT_THRESHOLD_MILLIS = 52L; - - @Mock - private StreamObserver responseObserver; + @Mock private StreamObserver responseObserver; @Mock private BlockPersistenceHandler blockPersistenceHandler; @Mock private StreamMediator< - BlockStreamServiceGrpcProto.Block, - BlockStreamServiceGrpcProto.BlockResponse> + BlockStreamServiceGrpcProto.Block, BlockStreamServiceGrpcProto.BlockResponse> streamMediator; @Test void getBlockHappyPath() { - BlockStreamServiceGrpcProto.Block block = BlockStreamServiceGrpcProto.Block.newBuilder().setId(1).build(); - BlockStreamService blockStreamService = new BlockStreamService(TIMEOUT_THRESHOLD_MILLIS, streamMediator, blockPersistenceHandler); - when(blockPersistenceHandler.read(1)).thenReturn(Optional.of(BlockStreamServiceGrpcProto.Block.newBuilder().setId(1).build())); + BlockStreamServiceGrpcProto.Block block = + BlockStreamServiceGrpcProto.Block.newBuilder().setId(1).build(); + BlockStreamService blockStreamService = + new BlockStreamService( + TIMEOUT_THRESHOLD_MILLIS, streamMediator, blockPersistenceHandler); + when(blockPersistenceHandler.read(1)) + .thenReturn( + Optional.of( + BlockStreamServiceGrpcProto.Block.newBuilder().setId(1).build())); blockStreamService.getBlock(block, responseObserver); verify(responseObserver, times(1)).onNext(block); } @Test void getBlockErrorPath() { - BlockStreamServiceGrpcProto.Block block = BlockStreamServiceGrpcProto.Block.newBuilder().setId(1).build(); - BlockStreamService blockStreamService = new BlockStreamService(TIMEOUT_THRESHOLD_MILLIS, streamMediator, blockPersistenceHandler); + BlockStreamServiceGrpcProto.Block block = + BlockStreamServiceGrpcProto.Block.newBuilder().setId(1).build(); + BlockStreamService blockStreamService = + new BlockStreamService( + TIMEOUT_THRESHOLD_MILLIS, streamMediator, blockPersistenceHandler); when(blockPersistenceHandler.read(1)).thenReturn(Optional.empty()); blockStreamService.getBlock(block, responseObserver); - verify(responseObserver, times(1)).onNext(BlockStreamServiceGrpcProto.Block.newBuilder().setId(0).build()); + verify(responseObserver, times(1)) + .onNext(BlockStreamServiceGrpcProto.Block.newBuilder().setId(0).build()); } -} \ No newline at end of file +}