Search in sources :

Example 6 with CreateStreamResponse

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

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

Example 8 with CreateStreamResponse

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

the class TestRootRangeStoreImpl method testCreateStreamExists.

@Test
public void testCreateStreamExists() throws Exception {
    String nsName = name.getMethodName();
    String streamName = name.getMethodName();
    CreateNamespaceResponse createResp = createNamespaceAndVerify(nsName, 0L);
    createStreamAndVerify(nsName, streamName, MIN_DATA_STREAM_ID);
    verifyStreamExists(createResp.getColProps().getNamespaceId(), streamName, MIN_DATA_STREAM_ID);
    verifyStreamId(MIN_DATA_STREAM_ID);
    // create the namespace with same name will fail
    CreateStreamResponse response2 = FutureUtils.result(rootRangeStore.createStream(createCreateStreamRequest(nsName, streamName, streamConf)));
    // TODO: change it later
    assertEquals(StatusCode.INTERNAL_SERVER_ERROR, response2.getCode());
    verifyStreamId(MIN_DATA_STREAM_ID);
}
Also used : CreateStreamResponse(org.apache.bookkeeper.stream.proto.storage.CreateStreamResponse) CreateNamespaceResponse(org.apache.bookkeeper.stream.proto.storage.CreateNamespaceResponse) Test(org.junit.Test)

Example 9 with CreateStreamResponse

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

the class TestRootRangeStoreImpl method testCreateStreamNamespaceNotFound.

@Test
public void testCreateStreamNamespaceNotFound() throws Exception {
    String nsName = name.getMethodName();
    String streamName = name.getMethodName();
    CompletableFuture<CreateStreamResponse> createFuture = rootRangeStore.createStream(createCreateStreamRequest(nsName, streamName, streamConf));
    CreateStreamResponse response = FutureUtils.result(createFuture);
    assertEquals(StatusCode.NAMESPACE_NOT_FOUND, response.getCode());
}
Also used : CreateStreamResponse(org.apache.bookkeeper.stream.proto.storage.CreateStreamResponse) Test(org.junit.Test)

Aggregations

CreateStreamResponse (org.apache.bookkeeper.stream.proto.storage.CreateStreamResponse)9 Test (org.junit.Test)7 CreateStreamRequest (org.apache.bookkeeper.stream.proto.storage.CreateStreamRequest)5 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 CreateNamespaceResponse (org.apache.bookkeeper.stream.proto.storage.CreateNamespaceResponse)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