use of org.apache.bookkeeper.stream.proto.storage.GetNamespaceRequest 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.GetNamespaceRequest 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.GetNamespaceRequest 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.GetNamespaceRequest in project bookkeeper by apache.
the class TestProtoUtils method testCreateGetNamespaceRequest.
@Test
public void testCreateGetNamespaceRequest() {
GetNamespaceRequest request = createGetNamespaceRequest(name.getMethodName());
assertEquals(name.getMethodName(), request.getName());
}
use of org.apache.bookkeeper.stream.proto.storage.GetNamespaceRequest in project bookkeeper by apache.
the class StorageContainerImplTest method testGetNamespace.
@Test
public void testGetNamespace() throws Exception {
mockStorageContainer(SCID);
GetNamespaceResponse expectedResp = GetNamespaceResponse.getDefaultInstance();
when(rrStore.getNamespace(any(GetNamespaceRequest.class))).thenReturn(FutureUtils.value(expectedResp));
GetNamespaceRequest expectedReq = GetNamespaceRequest.getDefaultInstance();
assertSame(expectedResp, FutureUtils.result(rrStore.getNamespace(expectedReq)));
verify(rrStore, times(1)).getNamespace(same(expectedReq));
}
Aggregations