Search in sources :

Example 11 with RangeStoreImpl

use of org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl 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 12 with RangeStoreImpl

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

the class TestGrpcRootRangeService method testGetStreamFailure.

@Test
public void testGetStreamFailure() throws Exception {
    RangeStoreImpl rangeService = mock(RangeStoreImpl.class);
    GrpcRootRangeService grpcService = new GrpcRootRangeService(rangeService);
    GetStreamResponse getResp = GetStreamResponse.newBuilder().setCode(StatusCode.INTERNAL_SERVER_ERROR).build();
    GetStreamRequest getReq = createGetStreamRequest(nsName, streamName);
    when(rangeService.getStream(getReq)).thenReturn(FutureUtils.exception(CAUSE));
    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());
    assertEquals(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)

Example 13 with RangeStoreImpl

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

the class TestGrpcRootRangeService method testDeleteStreamSuccess.

@Test
public void testDeleteStreamSuccess() throws Exception {
    RangeStoreImpl rangeService = mock(RangeStoreImpl.class);
    GrpcRootRangeService grpcService = new GrpcRootRangeService(rangeService);
    DeleteStreamResponse deleteResp = DeleteStreamResponse.newBuilder().setCode(StatusCode.SUCCESS).build();
    DeleteStreamRequest deleteReq = createDeleteStreamRequest(nsName, streamName);
    when(rangeService.deleteStream(deleteReq)).thenReturn(CompletableFuture.completedFuture(deleteResp));
    AtomicReference<DeleteStreamResponse> resultHolder = new AtomicReference<>();
    AtomicReference<Throwable> exceptionHolder = new AtomicReference<>();
    CountDownLatch latch = new CountDownLatch(1);
    StreamObserver<DeleteStreamResponse> streamObserver = new StreamObserver<DeleteStreamResponse>() {

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

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

        @Override
        public void onCompleted() {
            latch.countDown();
        }
    };
    grpcService.deleteStream(DeleteStreamRequest.newBuilder().setColName(nsName).setName(streamName).build(), streamObserver);
    latch.await();
    assertNull(exceptionHolder.get());
    assertNotNull(resultHolder.get());
    assertTrue(deleteResp == resultHolder.get());
    verify(rangeService, times(1)).deleteStream(deleteReq);
}
Also used : DeleteStreamRequest(org.apache.bookkeeper.stream.proto.storage.DeleteStreamRequest) ProtoUtils.createDeleteStreamRequest(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createDeleteStreamRequest) StreamObserver(io.grpc.stub.StreamObserver) DeleteStreamResponse(org.apache.bookkeeper.stream.proto.storage.DeleteStreamResponse) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) RangeStoreImpl(org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl) Test(org.junit.Test)

Example 14 with RangeStoreImpl

use of org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl 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 15 with RangeStoreImpl

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

the class TestGrpcRootRangeService method testCreateStreamSuccess.

// 
// Test Stream API
// 
@Test
public void testCreateStreamSuccess() throws Exception {
    RangeStoreImpl rangeService = mock(RangeStoreImpl.class);
    GrpcRootRangeService grpcService = new GrpcRootRangeService(rangeService);
    CreateStreamResponse createResp = CreateStreamResponse.newBuilder().setCode(StatusCode.SUCCESS).setStreamProps(streamProps).build();
    CreateStreamRequest createReq = createCreateStreamRequest(nsName, streamName, DEFAULT_STREAM_CONF);
    when(rangeService.createStream(createReq)).thenReturn(CompletableFuture.completedFuture(createResp));
    AtomicReference<CreateStreamResponse> resultHolder = new AtomicReference<>();
    AtomicReference<Throwable> exceptionHolder = new AtomicReference<>();
    CountDownLatch latch = new CountDownLatch(1);
    StreamObserver<CreateStreamResponse> streamObserver = new StreamObserver<CreateStreamResponse>() {

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

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

        @Override
        public void onCompleted() {
            latch.countDown();
        }
    };
    grpcService.createStream(CreateStreamRequest.newBuilder().setColName(nsName).setName(streamName).setStreamConf(DEFAULT_STREAM_CONF).build(), streamObserver);
    latch.await();
    assertNull(exceptionHolder.get());
    assertNotNull(resultHolder.get());
    assertTrue(createResp == resultHolder.get());
    verify(rangeService, times(1)).createStream(createReq);
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) CreateStreamRequest(org.apache.bookkeeper.stream.proto.storage.CreateStreamRequest) ProtoUtils.createCreateStreamRequest(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createCreateStreamRequest) CreateStreamResponse(org.apache.bookkeeper.stream.proto.storage.CreateStreamResponse) AtomicReference(java.util.concurrent.atomic.AtomicReference) 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