Skip to content

Commit

Permalink
Spotless Applied
Browse files Browse the repository at this point in the history
Signed-off-by: a-saksena <[email protected]>
  • Loading branch information
a-saksena committed Jul 24, 2024
1 parent 464c9b2 commit fc75185
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}
}
Original file line number Diff line number Diff line change
@@ -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<BlockStreamServiceGrpcProto.Block> responseObserver;
@Mock private StreamObserver<BlockStreamServiceGrpcProto.Block> responseObserver;

@Mock
private BlockPersistenceHandler<BlockStreamServiceGrpcProto.Block> 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());
}
}
}

0 comments on commit fc75185

Please sign in to comment.