Search in sources :

Example 1 with GetNamespaceResponse

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

Example 2 with GetNamespaceResponse

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

Example 3 with GetNamespaceResponse

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

Example 4 with GetNamespaceResponse

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

Example 5 with GetNamespaceResponse

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

Aggregations

GetNamespaceResponse (org.apache.bookkeeper.stream.proto.storage.GetNamespaceResponse)7 Test (org.junit.Test)6 GetNamespaceRequest (org.apache.bookkeeper.stream.proto.storage.GetNamespaceRequest)4 ProtoUtils.createGetNamespaceRequest (org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createGetNamespaceRequest)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