use of org.apache.bookkeeper.stream.proto.storage.DeleteNamespaceRequest in project bookkeeper by apache.
the class TestGrpcRootRangeService method testDeleteNamespaceSuccess.
@Test
public void testDeleteNamespaceSuccess() throws Exception {
RangeStoreImpl rangeService = mock(RangeStoreImpl.class);
GrpcRootRangeService grpcService = new GrpcRootRangeService(rangeService);
DeleteNamespaceResponse deleteResp = DeleteNamespaceResponse.newBuilder().setCode(StatusCode.SUCCESS).build();
DeleteNamespaceRequest deleteReq = createDeleteNamespaceRequest(nsName);
when(rangeService.deleteNamespace(deleteReq)).thenReturn(CompletableFuture.completedFuture(deleteResp));
AtomicReference<DeleteNamespaceResponse> resultHolder = new AtomicReference<>();
AtomicReference<Throwable> exceptionHolder = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
StreamObserver<DeleteNamespaceResponse> streamObserver = new StreamObserver<DeleteNamespaceResponse>() {
@Override
public void onNext(DeleteNamespaceResponse resp) {
resultHolder.set(resp);
}
@Override
public void onError(Throwable t) {
exceptionHolder.set(t);
latch.countDown();
}
@Override
public void onCompleted() {
latch.countDown();
}
};
grpcService.deleteNamespace(DeleteNamespaceRequest.newBuilder().setName(nsName).build(), streamObserver);
latch.await();
assertNull(exceptionHolder.get());
assertNotNull(resultHolder.get());
assertTrue(deleteResp == resultHolder.get());
verify(rangeService, times(1)).deleteNamespace(deleteReq);
}
use of org.apache.bookkeeper.stream.proto.storage.DeleteNamespaceRequest in project bookkeeper by apache.
the class TestGrpcRootRangeService method testDeleteNamespaceFailure.
@Test
public void testDeleteNamespaceFailure() throws Exception {
RangeStoreImpl rangeService = mock(RangeStoreImpl.class);
GrpcRootRangeService grpcService = new GrpcRootRangeService(rangeService);
DeleteNamespaceResponse deleteResp = DeleteNamespaceResponse.newBuilder().setCode(StatusCode.INTERNAL_SERVER_ERROR).build();
DeleteNamespaceRequest deleteReq = createDeleteNamespaceRequest(nsName);
when(rangeService.deleteNamespace(deleteReq)).thenReturn(FutureUtils.exception(CAUSE));
AtomicReference<DeleteNamespaceResponse> resultHolder = new AtomicReference<>();
AtomicReference<Throwable> exceptionHolder = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
StreamObserver<DeleteNamespaceResponse> streamObserver = new StreamObserver<DeleteNamespaceResponse>() {
@Override
public void onNext(DeleteNamespaceResponse resp) {
resultHolder.set(resp);
}
@Override
public void onError(Throwable t) {
exceptionHolder.set(t);
latch.countDown();
}
@Override
public void onCompleted() {
latch.countDown();
}
};
grpcService.deleteNamespace(DeleteNamespaceRequest.newBuilder().setName(nsName).build(), streamObserver);
latch.await();
assertNull(exceptionHolder.get());
assertNotNull(resultHolder.get());
assertEquals(deleteResp, resultHolder.get());
verify(rangeService, times(1)).deleteNamespace(deleteReq);
}
use of org.apache.bookkeeper.stream.proto.storage.DeleteNamespaceRequest in project bookkeeper by apache.
the class TestProtoUtils method testCreateDeleteNamespaceRequest.
@Test
public void testCreateDeleteNamespaceRequest() {
DeleteNamespaceRequest request = createDeleteNamespaceRequest(name.getMethodName());
assertEquals(name.getMethodName(), request.getName());
}
use of org.apache.bookkeeper.stream.proto.storage.DeleteNamespaceRequest in project bookkeeper by apache.
the class TestRangeStoreImpl method testDeleteNamespaceMockRootStorageContainerStore.
@Test
public void testDeleteNamespaceMockRootStorageContainerStore() throws Exception {
String colName = "test-delete-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);
DeleteNamespaceResponse deleteResp = DeleteNamespaceResponse.newBuilder().setCode(StatusCode.NAMESPACE_NOT_FOUND).build();
DeleteNamespaceRequest request = createDeleteNamespaceRequest(colName);
when(scStore.deleteNamespace(request)).thenReturn(CompletableFuture.completedFuture(deleteResp));
CompletableFuture<DeleteNamespaceResponse> deleteRespFuture = rangeStore.deleteNamespace(request);
verify(scStore, times(1)).deleteNamespace(request);
assertTrue(deleteResp == deleteRespFuture.get());
}
use of org.apache.bookkeeper.stream.proto.storage.DeleteNamespaceRequest in project bookkeeper by apache.
the class StorageContainerImplTest method testDeleteNamespace.
@Test
public void testDeleteNamespace() throws Exception {
mockStorageContainer(SCID);
DeleteNamespaceResponse expectedResp = DeleteNamespaceResponse.getDefaultInstance();
when(rrStore.deleteNamespace(any(DeleteNamespaceRequest.class))).thenReturn(FutureUtils.value(expectedResp));
DeleteNamespaceRequest expectedReq = DeleteNamespaceRequest.getDefaultInstance();
assertSame(expectedResp, FutureUtils.result(rrStore.deleteNamespace(expectedReq)));
verify(rrStore, times(1)).deleteNamespace(same(expectedReq));
}
Aggregations