### Question:
GrpcMetaRangeService extends MetaRangeServiceImplBase { @Override public void getActiveRanges(GetActiveRangesRequest request, StreamObserver<GetActiveRangesResponse> responseObserver) { rangeStore.getActiveRanges(request).whenComplete( new ResponseHandler<GetActiveRangesResponse>(responseObserver) { @Override protected GetActiveRangesResponse createErrorResp(Throwable cause) { return GetActiveRangesResponse.newBuilder() .setCode(StatusCode.INTERNAL_SERVER_ERROR) .build(); } }); } GrpcMetaRangeService(RangeStoreService service); @Override void getActiveRanges(GetActiveRangesRequest request,
                                StreamObserver<GetActiveRangesResponse> responseObserver);  }### Answer:
@Test public void testGetActiveRangesSuccess() throws Exception { RangeStoreService rangeService = mock(RangeStoreService.class); GrpcMetaRangeService grpcService = new GrpcMetaRangeService(rangeService); GetActiveRangesRequest request = GetActiveRangesRequest .newBuilder() .setStreamId(23456L) .build(); GetActiveRangesResponse response = GetActiveRangesResponse.newBuilder() .setCode(StatusCode.SUCCESS) .build(); when(rangeService.getActiveRanges(request)).thenReturn( CompletableFuture.completedFuture(response)); TestResponseObserver<GetActiveRangesResponse> responseObserver = new TestResponseObserver<>(); grpcService.getActiveRanges( request, responseObserver); responseObserver.verifySuccess(response); verify(rangeService, times(1)).getActiveRanges(request); }
@Test public void testGetActiveRangesFailure() throws Exception { RangeStoreService rangeService = mock(RangeStoreService.class); GrpcMetaRangeService grpcService = new GrpcMetaRangeService(rangeService); GetActiveRangesRequest request = GetActiveRangesRequest .newBuilder() .setStreamId(23456L) .build(); GetActiveRangesResponse response = GetActiveRangesResponse.newBuilder() .setCode(StatusCode.INTERNAL_SERVER_ERROR) .build(); when(rangeService.getActiveRanges(request)).thenReturn( FutureUtils.exception(CAUSE)); TestResponseObserver<GetActiveRangesResponse> responseObserver = new TestResponseObserver<>(); grpcService.getActiveRanges( request, responseObserver); responseObserver.verifySuccess(response); verify(rangeService, times(1)).getActiveRanges(request); }
@Test public void testGetActiveRangesException() throws Exception { RangeStoreService rangeService = mock(RangeStoreService.class); GrpcMetaRangeService grpcService = new GrpcMetaRangeService(rangeService); GetActiveRangesRequest request = GetActiveRangesRequest .newBuilder() .setStreamId(23456L) .build(); when(rangeService.getActiveRanges(request)).thenReturn( FutureUtils.exception(new StatusRuntimeException(Status.NOT_FOUND))); TestResponseObserver<GetActiveRangesResponse> responseObserver = new TestResponseObserver<>(); grpcService.getActiveRanges( request, responseObserver); responseObserver.verifyException(Status.NOT_FOUND); verify(rangeService, times(1)).getActiveRanges(request); }