Search in sources :

Example 1 with DeleteStreamResponse

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

the class TestRootRangeStoreImpl method testDeleteStreamNotFound.

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

Example 2 with DeleteStreamResponse

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

the class StorageContainerImplTest method testDeleteStream.

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

Example 3 with DeleteStreamResponse

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

the class TestGrpcRootRangeService method testDeleteStreamFailure.

@Test
public void testDeleteStreamFailure() throws Exception {
    RangeStoreImpl rangeService = mock(RangeStoreImpl.class);
    GrpcRootRangeService grpcService = new GrpcRootRangeService(rangeService);
    DeleteStreamResponse deleteResp = DeleteStreamResponse.newBuilder().setCode(StatusCode.INTERNAL_SERVER_ERROR).build();
    DeleteStreamRequest deleteReq = createDeleteStreamRequest(nsName, streamName);
    when(rangeService.deleteStream(deleteReq)).thenReturn(FutureUtils.exception(CAUSE));
    AtomicReference<DeleteStreamResponse> resultHolder = new AtomicReference<>();
    AtomicReference<Throwable> exceptionHolder = new AtomicReference<>();
    CountDownLatch latch = new CountDownLatch(1);
    StreamObserver<DeleteStreamResponse> streamObserver = new StreamObserver<DeleteStreamResponse>() {

        @Override
        public void onNext(DeleteStreamResponse resp) {
            resultHolder.set(resp);
        }

        @Override
        public void onError(Throwable t) {
            exceptionHolder.set(t);
            latch.countDown();
        }

        @Override
        public void onCompleted() {
            latch.countDown();
        }
    };
    grpcService.deleteStream(DeleteStreamRequest.newBuilder().setColName(nsName).setName(streamName).build(), streamObserver);
    latch.await();
    assertNull(exceptionHolder.get());
    assertNotNull(resultHolder.get());
    assertEquals(deleteResp, resultHolder.get());
    verify(rangeService, times(1)).deleteStream(deleteReq);
}
Also used : DeleteStreamRequest(org.apache.bookkeeper.stream.proto.storage.DeleteStreamRequest) ProtoUtils.createDeleteStreamRequest(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createDeleteStreamRequest) StreamObserver(io.grpc.stub.StreamObserver) DeleteStreamResponse(org.apache.bookkeeper.stream.proto.storage.DeleteStreamResponse) 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 DeleteStreamResponse

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

the class TestGrpcRootRangeService method testDeleteStreamSuccess.

@Test
public void testDeleteStreamSuccess() throws Exception {
    RangeStoreImpl rangeService = mock(RangeStoreImpl.class);
    GrpcRootRangeService grpcService = new GrpcRootRangeService(rangeService);
    DeleteStreamResponse deleteResp = DeleteStreamResponse.newBuilder().setCode(StatusCode.SUCCESS).build();
    DeleteStreamRequest deleteReq = createDeleteStreamRequest(nsName, streamName);
    when(rangeService.deleteStream(deleteReq)).thenReturn(CompletableFuture.completedFuture(deleteResp));
    AtomicReference<DeleteStreamResponse> resultHolder = new AtomicReference<>();
    AtomicReference<Throwable> exceptionHolder = new AtomicReference<>();
    CountDownLatch latch = new CountDownLatch(1);
    StreamObserver<DeleteStreamResponse> streamObserver = new StreamObserver<DeleteStreamResponse>() {

        @Override
        public void onNext(DeleteStreamResponse resp) {
            resultHolder.set(resp);
        }

        @Override
        public void onError(Throwable t) {
            exceptionHolder.set(t);
            latch.countDown();
        }

        @Override
        public void onCompleted() {
            latch.countDown();
        }
    };
    grpcService.deleteStream(DeleteStreamRequest.newBuilder().setColName(nsName).setName(streamName).build(), streamObserver);
    latch.await();
    assertNull(exceptionHolder.get());
    assertNotNull(resultHolder.get());
    assertTrue(deleteResp == resultHolder.get());
    verify(rangeService, times(1)).deleteStream(deleteReq);
}
Also used : DeleteStreamRequest(org.apache.bookkeeper.stream.proto.storage.DeleteStreamRequest) ProtoUtils.createDeleteStreamRequest(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createDeleteStreamRequest) StreamObserver(io.grpc.stub.StreamObserver) DeleteStreamResponse(org.apache.bookkeeper.stream.proto.storage.DeleteStreamResponse) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) RangeStoreImpl(org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl) Test(org.junit.Test)

Example 5 with DeleteStreamResponse

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

the class TestRangeStoreImpl method testDeleteStreamMockRootStorageContainerStore.

@Test
public void testDeleteStreamMockRootStorageContainerStore() throws Exception {
    String colName = "test-delete-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);
    DeleteStreamResponse deleteResp = DeleteStreamResponse.newBuilder().setCode(StatusCode.STREAM_NOT_FOUND).build();
    DeleteStreamRequest deleteReq = createDeleteStreamRequest(colName, streamName);
    when(scStore.deleteStream(deleteReq)).thenReturn(CompletableFuture.completedFuture(deleteResp));
    CompletableFuture<DeleteStreamResponse> deleteRespFuture = rangeStore.deleteStream(deleteReq);
    verify(scStore, times(1)).deleteStream(deleteReq);
    assertTrue(deleteResp == deleteRespFuture.get());
}
Also used : ProtoUtils.createDeleteStreamRequest(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createDeleteStreamRequest) DeleteStreamRequest(org.apache.bookkeeper.stream.proto.storage.DeleteStreamRequest) DeleteStreamResponse(org.apache.bookkeeper.stream.proto.storage.DeleteStreamResponse) ByteString(com.google.protobuf.ByteString) StorageContainer(org.apache.bookkeeper.stream.storage.api.sc.StorageContainer) Test(org.junit.Test)

Aggregations

DeleteStreamResponse (org.apache.bookkeeper.stream.proto.storage.DeleteStreamResponse)8 Test (org.junit.Test)8 DeleteStreamRequest (org.apache.bookkeeper.stream.proto.storage.DeleteStreamRequest)4 ProtoUtils.createDeleteStreamRequest (org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createDeleteStreamRequest)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 CreateNamespaceResponse (org.apache.bookkeeper.stream.proto.storage.CreateNamespaceResponse)1 StorageContainer (org.apache.bookkeeper.stream.storage.api.sc.StorageContainer)1