Search in sources :

Example 16 with RangeStoreImpl

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

the class TestGrpcRootRangeService method testGetStreamSuccess.

@Test
public void testGetStreamSuccess() throws Exception {
    RangeStoreImpl rangeService = mock(RangeStoreImpl.class);
    GrpcRootRangeService grpcService = new GrpcRootRangeService(rangeService);
    GetStreamResponse getResp = GetStreamResponse.newBuilder().setCode(StatusCode.SUCCESS).setStreamProps(streamProps).build();
    GetStreamRequest getReq = createGetStreamRequest(nsName, streamName);
    when(rangeService.getStream(getReq)).thenReturn(CompletableFuture.completedFuture(getResp));
    AtomicReference<GetStreamResponse> resultHolder = new AtomicReference<>();
    AtomicReference<Throwable> exceptionHolder = new AtomicReference<>();
    CountDownLatch latch = new CountDownLatch(1);
    StreamObserver<GetStreamResponse> streamObserver = new StreamObserver<GetStreamResponse>() {

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

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

        @Override
        public void onCompleted() {
            latch.countDown();
        }
    };
    grpcService.getStream(GetStreamRequest.newBuilder().setStreamName(StreamName.newBuilder().setColName(nsName).setStreamName(streamName)).build(), streamObserver);
    latch.await();
    assertNull(exceptionHolder.get());
    assertNotNull(resultHolder.get());
    assertTrue(getResp == resultHolder.get());
    verify(rangeService, times(1)).getStream(getReq);
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) AtomicReference(java.util.concurrent.atomic.AtomicReference) GetStreamResponse(org.apache.bookkeeper.stream.proto.storage.GetStreamResponse) GetStreamRequest(org.apache.bookkeeper.stream.proto.storage.GetStreamRequest) ProtoUtils.createGetStreamRequest(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createGetStreamRequest) CountDownLatch(java.util.concurrent.CountDownLatch) RangeStoreImpl(org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl) 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