Search in sources :

Example 1 with GetNamespaceRequest

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

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);
}
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 3 with GetNamespaceRequest

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

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

Example 5 with GetNamespaceRequest

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

Aggregations

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