use of org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl in project bookkeeper by apache.
the class TestGrpcRootRangeService method testGetStreamSuccess.
@Test
public void testGetStreamSuccess() throws Exception {
RangeStoreImpl rangeService = mock(RangeStoreImpl.class);
GrpcRootRangeService grpcService = new GrpcRootRangeService(rangeService);
GetStreamResponse getResp = GetStreamResponse.newBuilder().setCode(StatusCode.SUCCESS).setStreamProps(streamProps).build();
GetStreamRequest getReq = createGetStreamRequest(nsName, streamName);
when(rangeService.getStream(getReq)).thenReturn(CompletableFuture.completedFuture(getResp));
AtomicReference<GetStreamResponse> resultHolder = new AtomicReference<>();
AtomicReference<Throwable> exceptionHolder = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
StreamObserver<GetStreamResponse> streamObserver = new StreamObserver<GetStreamResponse>() {
@Override
public void onNext(GetStreamResponse resp) {
resultHolder.set(resp);
}
@Override
public void onError(Throwable t) {
exceptionHolder.set(t);
latch.countDown();
}
@Override
public void onCompleted() {
latch.countDown();
}
};
grpcService.getStream(GetStreamRequest.newBuilder().setStreamName(StreamName.newBuilder().setColName(nsName).setStreamName(streamName)).build(), streamObserver);
latch.await();
assertNull(exceptionHolder.get());
assertNotNull(resultHolder.get());
assertTrue(getResp == resultHolder.get());
verify(rangeService, times(1)).getStream(getReq);
}
Aggregations