use of org.apache.bookkeeper.stream.proto.storage.GetNamespaceResponse in project bookkeeper by apache.
the class TestRangeStoreImpl method testGetNamespaceMockRootStorageContainerStore.
@Test
public void testGetNamespaceMockRootStorageContainerStore() throws Exception {
String colName = "test-get-namespace-no-root-storage-container-store";
StorageContainer scStore = mock(StorageContainer.class);
when(scStore.stop()).thenReturn(FutureUtils.value(null));
rangeStore.getRegistry().setStorageContainer(ROOT_STORAGE_CONTAINER_ID, scStore);
GetNamespaceResponse getResp = GetNamespaceResponse.newBuilder().setCode(StatusCode.NAMESPACE_NOT_FOUND).build();
GetNamespaceRequest request = createGetNamespaceRequest(colName);
when(scStore.getNamespace(request)).thenReturn(CompletableFuture.completedFuture(getResp));
CompletableFuture<GetNamespaceResponse> getRespFuture = rangeStore.getNamespace(request);
verify(scStore, times(1)).getNamespace(request);
assertTrue(getResp == getRespFuture.get());
}
use of org.apache.bookkeeper.stream.proto.storage.GetNamespaceResponse in project bookkeeper by apache.
the class TestRootRangeStoreImpl method getNamespaceAndVerify.
private void getNamespaceAndVerify(String nsName, long expectedNsId, StreamConfiguration streamConf) throws Exception {
CompletableFuture<GetNamespaceResponse> getFuture = rootRangeStore.getNamespace(createGetNamespaceRequest(nsName));
GetNamespaceResponse getResp = FutureUtils.result(getFuture);
assertEquals(expectedNsId, getResp.getColProps().getNamespaceId());
assertEquals(streamConf, getResp.getColProps().getDefaultStreamConf());
}
use of org.apache.bookkeeper.stream.proto.storage.GetNamespaceResponse in project bookkeeper by apache.
the class TestGrpcRootRangeService method testGetNamespaceSuccess.
@Test
public void testGetNamespaceSuccess() throws Exception {
RangeStoreImpl rangeService = mock(RangeStoreImpl.class);
GrpcRootRangeService grpcService = new GrpcRootRangeService(rangeService);
GetNamespaceResponse getResp = GetNamespaceResponse.newBuilder().setCode(StatusCode.SUCCESS).setColProps(namespaceProps).build();
GetNamespaceRequest getReq = createGetNamespaceRequest(nsName);
when(rangeService.getNamespace(getReq)).thenReturn(CompletableFuture.completedFuture(getResp));
AtomicReference<GetNamespaceResponse> resultHolder = new AtomicReference<>();
AtomicReference<Throwable> exceptionHolder = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
StreamObserver<GetNamespaceResponse> streamObserver = new StreamObserver<GetNamespaceResponse>() {
@Override
public void onNext(GetNamespaceResponse resp) {
resultHolder.set(resp);
}
@Override
public void onError(Throwable t) {
exceptionHolder.set(t);
latch.countDown();
}
@Override
public void onCompleted() {
latch.countDown();
}
};
grpcService.getNamespace(GetNamespaceRequest.newBuilder().setName(nsName).build(), streamObserver);
latch.await();
assertNull(exceptionHolder.get());
assertNotNull(resultHolder.get());
assertTrue(getResp == resultHolder.get());
verify(rangeService, times(1)).getNamespace(getReq);
}
use of org.apache.bookkeeper.stream.proto.storage.GetNamespaceResponse in project bookkeeper by apache.
the class TestGrpcRootRangeService method testGetNamespaceFailure.
@Test
public void testGetNamespaceFailure() throws Exception {
RangeStoreImpl rangeService = mock(RangeStoreImpl.class);
GrpcRootRangeService grpcService = new GrpcRootRangeService(rangeService);
GetNamespaceResponse getResp = GetNamespaceResponse.newBuilder().setCode(StatusCode.INTERNAL_SERVER_ERROR).build();
GetNamespaceRequest getReq = createGetNamespaceRequest(nsName);
when(rangeService.getNamespace(getReq)).thenReturn(FutureUtils.exception(CAUSE));
AtomicReference<GetNamespaceResponse> resultHolder = new AtomicReference<>();
AtomicReference<Throwable> exceptionHolder = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
StreamObserver<GetNamespaceResponse> streamObserver = new StreamObserver<GetNamespaceResponse>() {
@Override
public void onNext(GetNamespaceResponse resp) {
resultHolder.set(resp);
}
@Override
public void onError(Throwable t) {
exceptionHolder.set(t);
latch.countDown();
}
@Override
public void onCompleted() {
latch.countDown();
}
};
grpcService.getNamespace(GetNamespaceRequest.newBuilder().setName(nsName).build(), streamObserver);
latch.await();
assertNull(exceptionHolder.get());
assertNotNull(resultHolder.get());
assertEquals(getResp, resultHolder.get());
verify(rangeService, times(1)).getNamespace(getReq);
}
use of org.apache.bookkeeper.stream.proto.storage.GetNamespaceResponse in project bookkeeper by apache.
the class TestRootRangeStoreImpl method testGetNamespaceInvalidName.
@Test
public void testGetNamespaceInvalidName() throws Exception {
String nsName = "";
CompletableFuture<GetNamespaceResponse> getFuture = rootRangeStore.getNamespace(createGetNamespaceRequest(nsName));
GetNamespaceResponse response = FutureUtils.result(getFuture);
assertEquals(StatusCode.INVALID_NAMESPACE_NAME, response.getCode());
}
Aggregations