use of org.apache.bookkeeper.stream.proto.storage.GetStreamRequest in project bookkeeper by apache.
the class TestRangeStoreImpl method testGetStreamMockRootStorageContainerStore.
@Test
public void testGetStreamMockRootStorageContainerStore() throws Exception {
String colName = "test-get-namespace-no-root-storage-container-store";
String streamName = colName;
StorageContainer scStore = mock(StorageContainer.class);
when(scStore.stop()).thenReturn(FutureUtils.value(null));
rangeStore.getRegistry().setStorageContainer(ROOT_STORAGE_CONTAINER_ID, scStore);
GetStreamResponse getResp = GetStreamResponse.newBuilder().setCode(StatusCode.STREAM_NOT_FOUND).build();
GetStreamRequest getReq = createGetStreamRequest(colName, streamName);
when(scStore.getStream(getReq)).thenReturn(CompletableFuture.completedFuture(getResp));
CompletableFuture<GetStreamResponse> getRespFuture = rangeStore.getStream(getReq);
verify(scStore, times(1)).getStream(getReq);
assertTrue(getResp == getRespFuture.get());
}
use of org.apache.bookkeeper.stream.proto.storage.GetStreamRequest in project bookkeeper by apache.
the class StorageContainerImplTest method testGetStream.
@Test
public void testGetStream() throws Exception {
mockStorageContainer(SCID);
GetStreamResponse expectedResp = GetStreamResponse.getDefaultInstance();
when(rrStore.getStream(any(GetStreamRequest.class))).thenReturn(FutureUtils.value(expectedResp));
GetStreamRequest expectedReq = GetStreamRequest.getDefaultInstance();
assertSame(expectedResp, FutureUtils.result(rrStore.getStream(expectedReq)));
verify(rrStore, times(1)).getStream(same(expectedReq));
}
use of org.apache.bookkeeper.stream.proto.storage.GetStreamRequest in project bookkeeper by apache.
the class RootRangeStoreImpl method getStream.
@Override
public CompletableFuture<GetStreamResponse> getStream(GetStreamRequest request) {
StreamName streamName = request.getStreamName();
StatusCode code = verifyStreamRequest(streamName.getColName(), streamName.getStreamName());
if (StatusCode.SUCCESS != code) {
return FutureUtils.value(GetStreamResponse.newBuilder().setCode(code).build());
}
byte[] nsNameKey = getNamespaceNameKey(streamName.getColName());
GetStreamResponse.Builder respBuilder = GetStreamResponse.newBuilder();
return store.get(nsNameKey).thenCompose(nsIdBytes -> {
if (null == nsIdBytes) {
return FutureUtils.value(respBuilder.setCode(StatusCode.NAMESPACE_NOT_FOUND).build());
}
long nsId = Bytes.toLong(nsIdBytes, 0);
return getStreamProps(nsId, streamName.getStreamName()).thenCompose(streamProps -> {
if (null == streamProps) {
return FutureUtils.value(respBuilder.setCode(StatusCode.STREAM_NOT_FOUND).build());
} else {
return FutureUtils.value(respBuilder.setCode(StatusCode.SUCCESS).setStreamProps(streamProps).build());
}
}).exceptionally(cause -> respBuilder.setCode(StatusCode.INTERNAL_SERVER_ERROR).build());
});
}
use of org.apache.bookkeeper.stream.proto.storage.GetStreamRequest in project bookkeeper by apache.
the class TestGrpcRootRangeService method testGetStreamFailure.
@Test
public void testGetStreamFailure() throws Exception {
RangeStoreImpl rangeService = mock(RangeStoreImpl.class);
GrpcRootRangeService grpcService = new GrpcRootRangeService(rangeService);
GetStreamResponse getResp = GetStreamResponse.newBuilder().setCode(StatusCode.INTERNAL_SERVER_ERROR).build();
GetStreamRequest getReq = createGetStreamRequest(nsName, streamName);
when(rangeService.getStream(getReq)).thenReturn(FutureUtils.exception(CAUSE));
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());
assertEquals(getResp, resultHolder.get());
verify(rangeService, times(1)).getStream(getReq);
}
use of org.apache.bookkeeper.stream.proto.storage.GetStreamRequest 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