Search in sources :

Example 6 with GetStreamResponse

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

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

Example 8 with GetStreamResponse

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

the class TestRootRangeStoreImpl method testGetStreamSuccess.

@Test
public void testGetStreamSuccess() throws Exception {
    String nsName = name.getMethodName();
    String streamName = name.getMethodName();
    createNamespaceAndVerify(nsName, 0L);
    createStreamAndVerify(nsName, streamName, MIN_DATA_STREAM_ID);
    verifyStreamId(MIN_DATA_STREAM_ID);
    CompletableFuture<GetStreamResponse> getFuture = rootRangeStore.getStream(createGetStreamRequest(nsName, streamName));
    GetStreamResponse getResp = FutureUtils.result(getFuture);
    assertEquals(StatusCode.SUCCESS, getResp.getCode());
    assertEquals(MIN_DATA_STREAM_ID, getResp.getStreamProps().getStreamId());
    assertEquals(streamName, getResp.getStreamProps().getStreamName());
    assertEquals(streamConf, getResp.getStreamProps().getStreamConf());
}
Also used : GetStreamResponse(org.apache.bookkeeper.stream.proto.storage.GetStreamResponse) Test(org.junit.Test)

Example 9 with GetStreamResponse

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

the class TestRootRangeStoreImpl method testGetStreamNamespaceNotFound.

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

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