use of org.apache.bookkeeper.stream.proto.storage.GetStreamResponse 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.GetStreamResponse in project bookkeeper by apache.
the class TestRootRangeStoreImpl method testGetStreamInvalidName.
@Test
public void testGetStreamInvalidName() throws Exception {
String nsName = name.getMethodName();
String streamName = "";
CompletableFuture<GetStreamResponse> getFuture = rootRangeStore.getStream(createGetStreamRequest(nsName, streamName));
GetStreamResponse response = FutureUtils.result(getFuture);
assertEquals(StatusCode.INVALID_STREAM_NAME, response.getCode());
}
use of org.apache.bookkeeper.stream.proto.storage.GetStreamResponse in project bookkeeper by apache.
the class TestRootRangeStoreImpl method testGetStreamNotFound.
@Test
public void testGetStreamNotFound() throws Exception {
String nsName = name.getMethodName();
String streamName = name.getMethodName();
createNamespaceAndVerify(nsName, 0L);
verifyStreamId(-1);
CompletableFuture<GetStreamResponse> getFuture = rootRangeStore.getStream(createGetStreamRequest(nsName, streamName));
GetStreamResponse response = FutureUtils.result(getFuture);
assertEquals(StatusCode.STREAM_NOT_FOUND, response.getCode());
}
use of org.apache.bookkeeper.stream.proto.storage.GetStreamResponse 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.GetStreamResponse 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());
});
}
Aggregations