Search in sources :

Example 1 with GetStreamResponse

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

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

the class TestRootRangeStoreImpl method testGetStreamInvalidName.

@Test
public void testGetStreamInvalidName() throws Exception {
    String nsName = name.getMethodName();
    String streamName = "";
    CompletableFuture<GetStreamResponse> getFuture = rootRangeStore.getStream(createGetStreamRequest(nsName, streamName));
    GetStreamResponse response = FutureUtils.result(getFuture);
    assertEquals(StatusCode.INVALID_STREAM_NAME, response.getCode());
}
Also used : GetStreamResponse(org.apache.bookkeeper.stream.proto.storage.GetStreamResponse) Test(org.junit.Test)

Example 3 with GetStreamResponse

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

the class TestRootRangeStoreImpl method testGetStreamNotFound.

@Test
public void testGetStreamNotFound() throws Exception {
    String nsName = name.getMethodName();
    String streamName = name.getMethodName();
    createNamespaceAndVerify(nsName, 0L);
    verifyStreamId(-1);
    CompletableFuture<GetStreamResponse> getFuture = rootRangeStore.getStream(createGetStreamRequest(nsName, streamName));
    GetStreamResponse response = FutureUtils.result(getFuture);
    assertEquals(StatusCode.STREAM_NOT_FOUND, response.getCode());
}
Also used : GetStreamResponse(org.apache.bookkeeper.stream.proto.storage.GetStreamResponse) Test(org.junit.Test)

Example 4 with GetStreamResponse

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

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

Aggregations

GetStreamResponse (org.apache.bookkeeper.stream.proto.storage.GetStreamResponse)9 Test (org.junit.Test)8 GetStreamRequest (org.apache.bookkeeper.stream.proto.storage.GetStreamRequest)5 ProtoUtils.createGetStreamRequest (org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createGetStreamRequest)3 StreamObserver (io.grpc.stub.StreamObserver)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)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 KeyValue (org.apache.bookkeeper.api.kv.result.KeyValue)1