Search in sources :

Example 1 with RangeStoreImpl

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

the class TestRangeStoreBuilder method testBuild.

@Test
public void testBuild() {
    RangeStore rangeStore = RangeStoreBuilder.newBuilder().withStorageConfiguration(mock(StorageConfiguration.class)).withStorageContainerManagerFactory(mock(StorageContainerManagerFactory.class)).withStorageResources(StorageResources.create()).withRangeStoreFactory(storeFactory).withDefaultBackendUri(uri).build();
    assertTrue(rangeStore instanceof RangeStoreImpl);
}
Also used : StorageContainerManagerFactory(org.apache.bookkeeper.stream.storage.api.sc.StorageContainerManagerFactory) RangeStore(org.apache.bookkeeper.stream.storage.api.RangeStore) RangeStoreImpl(org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl) Test(org.junit.Test)

Example 2 with RangeStoreImpl

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

the class TestGrpcRootRangeService method testCreateStreamFailure.

@Test
public void testCreateStreamFailure() throws Exception {
    RangeStoreImpl rangeService = mock(RangeStoreImpl.class);
    GrpcRootRangeService grpcService = new GrpcRootRangeService(rangeService);
    CreateStreamResponse createResp = CreateStreamResponse.newBuilder().setCode(StatusCode.INTERNAL_SERVER_ERROR).build();
    CreateStreamRequest createReq = createCreateStreamRequest(nsName, streamName, DEFAULT_STREAM_CONF);
    when(rangeService.createStream(createReq)).thenReturn(FutureUtils.exception(CAUSE));
    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());
    assertEquals(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)

Example 3 with RangeStoreImpl

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

the class TestGrpcRootRangeService method testDeleteNamespaceSuccess.

@Test
public void testDeleteNamespaceSuccess() throws Exception {
    RangeStoreImpl rangeService = mock(RangeStoreImpl.class);
    GrpcRootRangeService grpcService = new GrpcRootRangeService(rangeService);
    DeleteNamespaceResponse deleteResp = DeleteNamespaceResponse.newBuilder().setCode(StatusCode.SUCCESS).build();
    DeleteNamespaceRequest deleteReq = createDeleteNamespaceRequest(nsName);
    when(rangeService.deleteNamespace(deleteReq)).thenReturn(CompletableFuture.completedFuture(deleteResp));
    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());
    assertTrue(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 4 with RangeStoreImpl

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

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

the class TestGrpcRootRangeService method testDeleteStreamFailure.

@Test
public void testDeleteStreamFailure() throws Exception {
    RangeStoreImpl rangeService = mock(RangeStoreImpl.class);
    GrpcRootRangeService grpcService = new GrpcRootRangeService(rangeService);
    DeleteStreamResponse deleteResp = DeleteStreamResponse.newBuilder().setCode(StatusCode.INTERNAL_SERVER_ERROR).build();
    DeleteStreamRequest deleteReq = createDeleteStreamRequest(nsName, streamName);
    when(rangeService.deleteStream(deleteReq)).thenReturn(FutureUtils.exception(CAUSE));
    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());
    assertEquals(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)

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