Search in sources :

Example 6 with RangeStoreImpl

use of org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl in project bookkeeper by apache.

the class TestGrpcRootRangeService method testCreateNamespaceSuccess.

// 
// Test Namespace API
// 
@Test
public void testCreateNamespaceSuccess() throws Exception {
    RangeStoreImpl rangeService = mock(RangeStoreImpl.class);
    GrpcRootRangeService grpcService = new GrpcRootRangeService(rangeService);
    CreateNamespaceResponse createResp = CreateNamespaceResponse.newBuilder().setCode(StatusCode.SUCCESS).setColProps(namespaceProps).build();
    CreateNamespaceRequest createReq = createCreateNamespaceRequest(nsName, namespaceConf);
    when(rangeService.createNamespace(createReq)).thenReturn(CompletableFuture.completedFuture(createResp));
    AtomicReference<CreateNamespaceResponse> resultHolder = new AtomicReference<>();
    AtomicReference<Throwable> exceptionHolder = new AtomicReference<>();
    CountDownLatch latch = new CountDownLatch(1);
    StreamObserver<CreateNamespaceResponse> streamObserver = new StreamObserver<CreateNamespaceResponse>() {

        @Override
        public void onNext(CreateNamespaceResponse resp) {
            resultHolder.set(resp);
        }

        @Override
        public void onError(Throwable t) {
            exceptionHolder.set(t);
            latch.countDown();
        }

        @Override
        public void onCompleted() {
            latch.countDown();
        }
    };
    grpcService.createNamespace(CreateNamespaceRequest.newBuilder().setName(nsName).setColConf(namespaceConf).build(), streamObserver);
    latch.await();
    assertNull(exceptionHolder.get());
    assertNotNull(resultHolder.get());
    assertTrue(createResp == resultHolder.get());
    verify(rangeService, times(1)).createNamespace(createReq);
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) RangeStoreImpl(org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl) CreateNamespaceResponse(org.apache.bookkeeper.stream.proto.storage.CreateNamespaceResponse) ProtoUtils.createCreateNamespaceRequest(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createCreateNamespaceRequest) CreateNamespaceRequest(org.apache.bookkeeper.stream.proto.storage.CreateNamespaceRequest) Test(org.junit.Test)

Example 7 with RangeStoreImpl

use of org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl in project bookkeeper by apache.

the class TestGrpcMetaRangeService method testGetActiveRangesException.

@Test
public void testGetActiveRangesException() throws Exception {
    RangeStoreImpl rangeService = mock(RangeStoreImpl.class);
    GrpcMetaRangeService grpcService = new GrpcMetaRangeService(rangeService);
    StorageContainerRequest request = StorageContainerRequest.newBuilder().setGetActiveRangesReq(GetActiveRangesRequest.newBuilder().setStreamId(23456L).build()).build();
    when(rangeService.getActiveRanges(request)).thenReturn(FutureUtils.exception(new StatusRuntimeException(Status.NOT_FOUND)));
    TestResponseObserver<StorageContainerResponse> responseObserver = new TestResponseObserver<>();
    grpcService.getActiveRanges(request, responseObserver);
    responseObserver.verifyException(Status.NOT_FOUND);
    verify(rangeService, times(1)).getActiveRanges(request);
}
Also used : StorageContainerRequest(org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest) TestResponseObserver(org.apache.bookkeeper.stream.server.TestResponseObserver) StatusRuntimeException(io.grpc.StatusRuntimeException) RangeStoreImpl(org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl) StorageContainerResponse(org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse) Test(org.junit.Test)

Example 8 with RangeStoreImpl

use of org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl in project bookkeeper by apache.

the class TestGrpcMetaRangeService method testGetActiveRangesFailure.

@Test
public void testGetActiveRangesFailure() throws Exception {
    RangeStoreImpl rangeService = mock(RangeStoreImpl.class);
    GrpcMetaRangeService grpcService = new GrpcMetaRangeService(rangeService);
    StorageContainerRequest request = StorageContainerRequest.newBuilder().setGetActiveRangesReq(GetActiveRangesRequest.newBuilder().setStreamId(23456L).build()).build();
    StorageContainerResponse response = StorageContainerResponse.newBuilder().setCode(StatusCode.INTERNAL_SERVER_ERROR).build();
    when(rangeService.getActiveRanges(request)).thenReturn(FutureUtils.exception(CAUSE));
    TestResponseObserver<StorageContainerResponse> responseObserver = new TestResponseObserver<>();
    grpcService.getActiveRanges(request, responseObserver);
    responseObserver.verifySuccess(response);
    verify(rangeService, times(1)).getActiveRanges(request);
}
Also used : StorageContainerRequest(org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest) TestResponseObserver(org.apache.bookkeeper.stream.server.TestResponseObserver) RangeStoreImpl(org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl) StorageContainerResponse(org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse) Test(org.junit.Test)

Example 9 with RangeStoreImpl

use of org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl in project bookkeeper by apache.

the class TestGrpcMetaRangeService method testGetActiveRangesSuccess.

// 
// Meta KeyRange Server Requests tests
// 
@Test
public void testGetActiveRangesSuccess() throws Exception {
    RangeStoreImpl rangeService = mock(RangeStoreImpl.class);
    GrpcMetaRangeService grpcService = new GrpcMetaRangeService(rangeService);
    StorageContainerRequest request = StorageContainerRequest.newBuilder().setGetActiveRangesReq(GetActiveRangesRequest.newBuilder().setStreamId(23456L).build()).build();
    StorageContainerResponse response = StorageContainerResponse.newBuilder().setCode(StatusCode.SUCCESS).setGetActiveRangesResp(GetActiveRangesResponse.newBuilder()).build();
    when(rangeService.getActiveRanges(request)).thenReturn(CompletableFuture.completedFuture(response));
    TestResponseObserver<StorageContainerResponse> responseObserver = new TestResponseObserver<>();
    grpcService.getActiveRanges(request, responseObserver);
    responseObserver.verifySuccess(response);
    verify(rangeService, times(1)).getActiveRanges(request);
}
Also used : StorageContainerRequest(org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest) TestResponseObserver(org.apache.bookkeeper.stream.server.TestResponseObserver) RangeStoreImpl(org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl) StorageContainerResponse(org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse) Test(org.junit.Test)

Example 10 with RangeStoreImpl

use of org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl in project bookkeeper by apache.

the class TestGrpcRootRangeService method testCreateNamespaceFailure.

@Test
public void testCreateNamespaceFailure() throws Exception {
    RangeStoreImpl rangeService = mock(RangeStoreImpl.class);
    GrpcRootRangeService grpcService = new GrpcRootRangeService(rangeService);
    CreateNamespaceResponse createResp = CreateNamespaceResponse.newBuilder().setCode(StatusCode.INTERNAL_SERVER_ERROR).build();
    CreateNamespaceRequest createReq = createCreateNamespaceRequest(nsName, namespaceConf);
    when(rangeService.createNamespace(createReq)).thenReturn(FutureUtils.exception(CAUSE));
    AtomicReference<CreateNamespaceResponse> resultHolder = new AtomicReference<>();
    AtomicReference<Throwable> exceptionHolder = new AtomicReference<>();
    CountDownLatch latch = new CountDownLatch(1);
    StreamObserver<CreateNamespaceResponse> streamObserver = new StreamObserver<CreateNamespaceResponse>() {

        @Override
        public void onNext(CreateNamespaceResponse resp) {
            resultHolder.set(resp);
        }

        @Override
        public void onError(Throwable t) {
            exceptionHolder.set(t);
            latch.countDown();
        }

        @Override
        public void onCompleted() {
            latch.countDown();
        }
    };
    grpcService.createNamespace(CreateNamespaceRequest.newBuilder().setName(nsName).setColConf(namespaceConf).build(), streamObserver);
    latch.await();
    assertNull(exceptionHolder.get());
    assertNotNull(resultHolder.get());
    assertEquals(createResp, resultHolder.get());
    verify(rangeService, times(1)).createNamespace(createReq);
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) RangeStoreImpl(org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl) CreateNamespaceResponse(org.apache.bookkeeper.stream.proto.storage.CreateNamespaceResponse) ProtoUtils.createCreateNamespaceRequest(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createCreateNamespaceRequest) CreateNamespaceRequest(org.apache.bookkeeper.stream.proto.storage.CreateNamespaceRequest) Test(org.junit.Test)

Aggregations

RangeStoreImpl (org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl)16 Test (org.junit.Test)16 StreamObserver (io.grpc.stub.StreamObserver)12 CountDownLatch (java.util.concurrent.CountDownLatch)12 AtomicReference (java.util.concurrent.atomic.AtomicReference)12 StorageContainerRequest (org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest)3 StorageContainerResponse (org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse)3 TestResponseObserver (org.apache.bookkeeper.stream.server.TestResponseObserver)3 CreateNamespaceRequest (org.apache.bookkeeper.stream.proto.storage.CreateNamespaceRequest)2 CreateNamespaceResponse (org.apache.bookkeeper.stream.proto.storage.CreateNamespaceResponse)2 CreateStreamRequest (org.apache.bookkeeper.stream.proto.storage.CreateStreamRequest)2 CreateStreamResponse (org.apache.bookkeeper.stream.proto.storage.CreateStreamResponse)2 DeleteNamespaceRequest (org.apache.bookkeeper.stream.proto.storage.DeleteNamespaceRequest)2 DeleteNamespaceResponse (org.apache.bookkeeper.stream.proto.storage.DeleteNamespaceResponse)2 DeleteStreamRequest (org.apache.bookkeeper.stream.proto.storage.DeleteStreamRequest)2 DeleteStreamResponse (org.apache.bookkeeper.stream.proto.storage.DeleteStreamResponse)2 GetNamespaceRequest (org.apache.bookkeeper.stream.proto.storage.GetNamespaceRequest)2 GetNamespaceResponse (org.apache.bookkeeper.stream.proto.storage.GetNamespaceResponse)2 GetStreamRequest (org.apache.bookkeeper.stream.proto.storage.GetStreamRequest)2 GetStreamResponse (org.apache.bookkeeper.stream.proto.storage.GetStreamResponse)2