Search in sources :

Example 1 with GetStreamRequest

use of org.apache.bookkeeper.stream.proto.storage.GetStreamRequest in project bookkeeper by apache.

the class TestRangeStoreImpl method testGetStreamMockRootStorageContainerStore.

@Test
public void testGetStreamMockRootStorageContainerStore() throws Exception {
    String colName = "test-get-namespace-no-root-storage-container-store";
    String streamName = colName;
    StorageContainer scStore = mock(StorageContainer.class);
    when(scStore.stop()).thenReturn(FutureUtils.value(null));
    rangeStore.getRegistry().setStorageContainer(ROOT_STORAGE_CONTAINER_ID, scStore);
    GetStreamResponse getResp = GetStreamResponse.newBuilder().setCode(StatusCode.STREAM_NOT_FOUND).build();
    GetStreamRequest getReq = createGetStreamRequest(colName, streamName);
    when(scStore.getStream(getReq)).thenReturn(CompletableFuture.completedFuture(getResp));
    CompletableFuture<GetStreamResponse> getRespFuture = rangeStore.getStream(getReq);
    verify(scStore, times(1)).getStream(getReq);
    assertTrue(getResp == getRespFuture.get());
}
Also used : ByteString(com.google.protobuf.ByteString) GetStreamResponse(org.apache.bookkeeper.stream.proto.storage.GetStreamResponse) ProtoUtils.createGetStreamRequest(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createGetStreamRequest) GetStreamRequest(org.apache.bookkeeper.stream.proto.storage.GetStreamRequest) StorageContainer(org.apache.bookkeeper.stream.storage.api.sc.StorageContainer) Test(org.junit.Test)

Example 2 with GetStreamRequest

use of org.apache.bookkeeper.stream.proto.storage.GetStreamRequest in project bookkeeper by apache.

the class StorageContainerImplTest method testGetStream.

@Test
public void testGetStream() throws Exception {
    mockStorageContainer(SCID);
    GetStreamResponse expectedResp = GetStreamResponse.getDefaultInstance();
    when(rrStore.getStream(any(GetStreamRequest.class))).thenReturn(FutureUtils.value(expectedResp));
    GetStreamRequest expectedReq = GetStreamRequest.getDefaultInstance();
    assertSame(expectedResp, FutureUtils.result(rrStore.getStream(expectedReq)));
    verify(rrStore, times(1)).getStream(same(expectedReq));
}
Also used : GetStreamResponse(org.apache.bookkeeper.stream.proto.storage.GetStreamResponse) GetStreamRequest(org.apache.bookkeeper.stream.proto.storage.GetStreamRequest) Test(org.junit.Test)

Example 3 with GetStreamRequest

use of org.apache.bookkeeper.stream.proto.storage.GetStreamRequest in project bookkeeper by apache.

the class RootRangeStoreImpl method getStream.

@Override
public CompletableFuture<GetStreamResponse> getStream(GetStreamRequest request) {
    StreamName streamName = request.getStreamName();
    StatusCode code = verifyStreamRequest(streamName.getColName(), streamName.getStreamName());
    if (StatusCode.SUCCESS != code) {
        return FutureUtils.value(GetStreamResponse.newBuilder().setCode(code).build());
    }
    byte[] nsNameKey = getNamespaceNameKey(streamName.getColName());
    GetStreamResponse.Builder respBuilder = GetStreamResponse.newBuilder();
    return store.get(nsNameKey).thenCompose(nsIdBytes -> {
        if (null == nsIdBytes) {
            return FutureUtils.value(respBuilder.setCode(StatusCode.NAMESPACE_NOT_FOUND).build());
        }
        long nsId = Bytes.toLong(nsIdBytes, 0);
        return getStreamProps(nsId, streamName.getStreamName()).thenCompose(streamProps -> {
            if (null == streamProps) {
                return FutureUtils.value(respBuilder.setCode(StatusCode.STREAM_NOT_FOUND).build());
            } else {
                return FutureUtils.value(respBuilder.setCode(StatusCode.SUCCESS).setStreamProps(streamProps).build());
            }
        }).exceptionally(cause -> respBuilder.setCode(StatusCode.INTERNAL_SERVER_ERROR).build());
    });
}
Also used : ProtoUtils.validateStreamName(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.validateStreamName) GetStreamRequest(org.apache.bookkeeper.stream.proto.storage.GetStreamRequest) Options(org.apache.bookkeeper.api.kv.options.Options) DeleteNamespaceRequest(org.apache.bookkeeper.stream.proto.storage.DeleteNamespaceRequest) CompletableFuture(java.util.concurrent.CompletableFuture) CreateStreamRequest(org.apache.bookkeeper.stream.proto.storage.CreateStreamRequest) GetStreamResponse(org.apache.bookkeeper.stream.proto.storage.GetStreamResponse) DeleteStreamRequest(org.apache.bookkeeper.stream.proto.storage.DeleteStreamRequest) UTF_8(com.google.common.base.Charsets.UTF_8) MIN_DATA_STREAM_ID(org.apache.bookkeeper.stream.protocol.ProtocolConstants.MIN_DATA_STREAM_ID) StreamName(org.apache.bookkeeper.stream.proto.StreamName) CreateStreamResponse(org.apache.bookkeeper.stream.proto.storage.CreateStreamResponse) DeleteStreamResponse(org.apache.bookkeeper.stream.proto.storage.DeleteStreamResponse) MVCCAsyncStore(org.apache.bookkeeper.statelib.api.mvcc.MVCCAsyncStore) TxnOp(org.apache.bookkeeper.api.kv.op.TxnOp) NamespaceProperties(org.apache.bookkeeper.stream.proto.NamespaceProperties) NamespaceMetadata(org.apache.bookkeeper.stream.proto.NamespaceMetadata) DeleteNamespaceResponse(org.apache.bookkeeper.stream.proto.storage.DeleteNamespaceResponse) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) KeyValue(org.apache.bookkeeper.api.kv.result.KeyValue) URI(java.net.URI) StatusCode(org.apache.bookkeeper.stream.proto.storage.StatusCode) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) StorageContainerPlacementPolicy(org.apache.bookkeeper.stream.protocol.util.StorageContainerPlacementPolicy) CreateNamespaceResponse(org.apache.bookkeeper.stream.proto.storage.CreateNamespaceResponse) RangeOp(org.apache.bookkeeper.api.kv.op.RangeOp) RootRangeStore(org.apache.bookkeeper.stream.storage.api.metadata.RootRangeStore) StreamConfiguration(org.apache.bookkeeper.stream.proto.StreamConfiguration) Bytes(org.apache.bookkeeper.common.util.Bytes) FutureUtils(org.apache.bookkeeper.common.concurrent.FutureUtils) Slf4j(lombok.extern.slf4j.Slf4j) CreateNamespaceRequest(org.apache.bookkeeper.stream.proto.storage.CreateNamespaceRequest) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) StreamProperties(org.apache.bookkeeper.stream.proto.StreamProperties) CompareResult(org.apache.bookkeeper.api.kv.op.CompareResult) ProtoUtils.validateNamespaceName(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.validateNamespaceName) GetNamespaceRequest(org.apache.bookkeeper.stream.proto.storage.GetNamespaceRequest) GetNamespaceResponse(org.apache.bookkeeper.stream.proto.storage.GetNamespaceResponse) ProtoUtils.validateStreamName(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.validateStreamName) StreamName(org.apache.bookkeeper.stream.proto.StreamName) GetStreamResponse(org.apache.bookkeeper.stream.proto.storage.GetStreamResponse) StatusCode(org.apache.bookkeeper.stream.proto.storage.StatusCode)

Example 4 with GetStreamRequest

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

use of org.apache.bookkeeper.stream.proto.storage.GetStreamRequest 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

GetStreamRequest (org.apache.bookkeeper.stream.proto.storage.GetStreamRequest)6 GetStreamResponse (org.apache.bookkeeper.stream.proto.storage.GetStreamResponse)5 Test (org.junit.Test)5 StreamObserver (io.grpc.stub.StreamObserver)3 ProtoUtils.createGetStreamRequest (org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createGetStreamRequest)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 StreamProperties (org.apache.bookkeeper.stream.proto.StreamProperties)2 RangeStoreImpl (org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl)2 UTF_8 (com.google.common.base.Charsets.UTF_8)1 ByteString (com.google.protobuf.ByteString)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 URI (java.net.URI)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 Slf4j (lombok.extern.slf4j.Slf4j)1 CompareResult (org.apache.bookkeeper.api.kv.op.CompareResult)1 RangeOp (org.apache.bookkeeper.api.kv.op.RangeOp)1 TxnOp (org.apache.bookkeeper.api.kv.op.TxnOp)1 Options (org.apache.bookkeeper.api.kv.options.Options)1