Search in sources :

Example 1 with CreateStreamRequest

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

the class StorageContainerImplTest method testCreateStream.

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

Example 2 with CreateStreamRequest

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

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

Example 4 with CreateStreamRequest

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

the class TestRangeStoreImpl method testCreateStreamMockRootStorageContainerStore.

@Test
public void testCreateStreamMockRootStorageContainerStore() throws Exception {
    String colName = "test-create-namespace-mock-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);
    CreateStreamResponse createResp = CreateStreamResponse.newBuilder().setCode(StatusCode.STREAM_EXISTS).build();
    CreateStreamRequest createReq = createCreateStreamRequest(colName, streamName, DEFAULT_STREAM_CONF);
    when(scStore.createStream(createReq)).thenReturn(CompletableFuture.completedFuture(createResp));
    CompletableFuture<CreateStreamResponse> createRespFuture = rangeStore.createStream(createReq);
    verify(scStore, times(1)).createStream(createReq);
    assertTrue(createResp == createRespFuture.get());
}
Also used : 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) ByteString(com.google.protobuf.ByteString) StorageContainer(org.apache.bookkeeper.stream.storage.api.sc.StorageContainer) Test(org.junit.Test)

Aggregations

CreateStreamRequest (org.apache.bookkeeper.stream.proto.storage.CreateStreamRequest)4 CreateStreamResponse (org.apache.bookkeeper.stream.proto.storage.CreateStreamResponse)4 Test (org.junit.Test)4 ProtoUtils.createCreateStreamRequest (org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createCreateStreamRequest)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 ByteString (com.google.protobuf.ByteString)1 StorageContainer (org.apache.bookkeeper.stream.storage.api.sc.StorageContainer)1