Search in sources :

Example 1 with DeleteNamespaceRequest

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);
}
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 2 with DeleteNamespaceRequest

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);
}
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 DeleteNamespaceRequest

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());
}
Also used : DeleteNamespaceRequest(org.apache.bookkeeper.stream.proto.storage.DeleteNamespaceRequest) ProtoUtils.createDeleteNamespaceRequest(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createDeleteNamespaceRequest) Test(org.junit.Test)

Example 4 with DeleteNamespaceRequest

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());
}
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 DeleteNamespaceRequest

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));
}
Also used : DeleteNamespaceRequest(org.apache.bookkeeper.stream.proto.storage.DeleteNamespaceRequest) DeleteNamespaceResponse(org.apache.bookkeeper.stream.proto.storage.DeleteNamespaceResponse) Test(org.junit.Test)

Aggregations

DeleteNamespaceRequest (org.apache.bookkeeper.stream.proto.storage.DeleteNamespaceRequest)5 Test (org.junit.Test)5 DeleteNamespaceResponse (org.apache.bookkeeper.stream.proto.storage.DeleteNamespaceResponse)4 ProtoUtils.createDeleteNamespaceRequest (org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createDeleteNamespaceRequest)4 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