Search in sources :

Example 1 with DeleteNamespaceResponse

use of org.apache.bookkeeper.stream.proto.storage.DeleteNamespaceResponse in project bookkeeper by apache.

the class TestRootRangeStoreImpl method testDeleteNamespaceNotFound.

@Test
public void testDeleteNamespaceNotFound() throws Exception {
    String nsName = name.getMethodName();
    CompletableFuture<DeleteNamespaceResponse> deleteFuture = rootRangeStore.deleteNamespace(createDeleteNamespaceRequest(nsName));
    // create first namespace
    DeleteNamespaceResponse response = FutureUtils.result(deleteFuture);
    assertEquals(StatusCode.NAMESPACE_NOT_FOUND, response.getCode());
    verifyNamespaceNotExists(nsName, 0L);
    verifyNamespaceId(-1L);
}
Also used : DeleteNamespaceResponse(org.apache.bookkeeper.stream.proto.storage.DeleteNamespaceResponse) Test(org.junit.Test)

Example 2 with DeleteNamespaceResponse

use of org.apache.bookkeeper.stream.proto.storage.DeleteNamespaceResponse 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);
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) DeleteNamespaceRequest(org.apache.bookkeeper.stream.proto.storage.DeleteNamespaceRequest) ProtoUtils.createDeleteNamespaceRequest(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createDeleteNamespaceRequest) AtomicReference(java.util.concurrent.atomic.AtomicReference) DeleteNamespaceResponse(org.apache.bookkeeper.stream.proto.storage.DeleteNamespaceResponse) CountDownLatch(java.util.concurrent.CountDownLatch) RangeStoreImpl(org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl) Test(org.junit.Test)

Example 3 with DeleteNamespaceResponse

use of org.apache.bookkeeper.stream.proto.storage.DeleteNamespaceResponse 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);
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) DeleteNamespaceRequest(org.apache.bookkeeper.stream.proto.storage.DeleteNamespaceRequest) ProtoUtils.createDeleteNamespaceRequest(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createDeleteNamespaceRequest) AtomicReference(java.util.concurrent.atomic.AtomicReference) DeleteNamespaceResponse(org.apache.bookkeeper.stream.proto.storage.DeleteNamespaceResponse) CountDownLatch(java.util.concurrent.CountDownLatch) RangeStoreImpl(org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl) Test(org.junit.Test)

Example 4 with DeleteNamespaceResponse

use of org.apache.bookkeeper.stream.proto.storage.DeleteNamespaceResponse 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());
}
Also used : DeleteNamespaceRequest(org.apache.bookkeeper.stream.proto.storage.DeleteNamespaceRequest) ProtoUtils.createDeleteNamespaceRequest(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createDeleteNamespaceRequest) ByteString(com.google.protobuf.ByteString) DeleteNamespaceResponse(org.apache.bookkeeper.stream.proto.storage.DeleteNamespaceResponse) StorageContainer(org.apache.bookkeeper.stream.storage.api.sc.StorageContainer) Test(org.junit.Test)

Example 5 with DeleteNamespaceResponse

use of org.apache.bookkeeper.stream.proto.storage.DeleteNamespaceResponse in project bookkeeper by apache.

the class TestRootRangeStoreImpl method testDeleteNamespaceInvalidName.

@Test
public void testDeleteNamespaceInvalidName() throws Exception {
    String nsName = "";
    CompletableFuture<DeleteNamespaceResponse> deleteFuture = rootRangeStore.deleteNamespace(createDeleteNamespaceRequest(nsName));
    DeleteNamespaceResponse response = FutureUtils.result(deleteFuture);
    assertEquals(StatusCode.INVALID_NAMESPACE_NAME, response.getCode());
}
Also used : DeleteNamespaceResponse(org.apache.bookkeeper.stream.proto.storage.DeleteNamespaceResponse) Test(org.junit.Test)

Aggregations

DeleteNamespaceResponse (org.apache.bookkeeper.stream.proto.storage.DeleteNamespaceResponse)7 Test (org.junit.Test)6 DeleteNamespaceRequest (org.apache.bookkeeper.stream.proto.storage.DeleteNamespaceRequest)4 ProtoUtils.createDeleteNamespaceRequest (org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createDeleteNamespaceRequest)3 StreamObserver (io.grpc.stub.StreamObserver)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 RangeStoreImpl (org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl)2 ByteString (com.google.protobuf.ByteString)1 StorageContainer (org.apache.bookkeeper.stream.storage.api.sc.StorageContainer)1