Search in sources :

Example 26 with StorageContainerResponse

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

the class TestStorageContainerResponseHandler method testStatusRuntimeException.

@SuppressWarnings("unchecked")
@Test
public void testStatusRuntimeException() {
    StreamObserver<StorageContainerResponse> observer = mock(StreamObserver.class);
    StorageContainerResponseHandler handler = StorageContainerResponseHandler.of(observer);
    StatusRuntimeException exception = new StatusRuntimeException(Status.NOT_FOUND);
    handler.accept(null, exception);
    verify(observer, times(0)).onNext(any());
    verify(observer, times(0)).onCompleted();
    verify(observer, times(1)).onError(exception);
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) StorageContainerResponse(org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse) Test(org.junit.Test)

Example 27 with StorageContainerResponse

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

the class TestGrpcMetaRangeService method testGetActiveRangesException.

@Test
public void testGetActiveRangesException() throws Exception {
    RangeStoreImpl rangeService = mock(RangeStoreImpl.class);
    GrpcMetaRangeService grpcService = new GrpcMetaRangeService(rangeService);
    StorageContainerRequest request = StorageContainerRequest.newBuilder().setGetActiveRangesReq(GetActiveRangesRequest.newBuilder().setStreamId(23456L).build()).build();
    when(rangeService.getActiveRanges(request)).thenReturn(FutureUtils.exception(new StatusRuntimeException(Status.NOT_FOUND)));
    TestResponseObserver<StorageContainerResponse> responseObserver = new TestResponseObserver<>();
    grpcService.getActiveRanges(request, responseObserver);
    responseObserver.verifyException(Status.NOT_FOUND);
    verify(rangeService, times(1)).getActiveRanges(request);
}
Also used : StorageContainerRequest(org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest) TestResponseObserver(org.apache.bookkeeper.stream.server.TestResponseObserver) StatusRuntimeException(io.grpc.StatusRuntimeException) RangeStoreImpl(org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl) StorageContainerResponse(org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse) Test(org.junit.Test)

Example 28 with StorageContainerResponse

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

the class TestGrpcMetaRangeService method testGetActiveRangesFailure.

@Test
public void testGetActiveRangesFailure() throws Exception {
    RangeStoreImpl rangeService = mock(RangeStoreImpl.class);
    GrpcMetaRangeService grpcService = new GrpcMetaRangeService(rangeService);
    StorageContainerRequest request = StorageContainerRequest.newBuilder().setGetActiveRangesReq(GetActiveRangesRequest.newBuilder().setStreamId(23456L).build()).build();
    StorageContainerResponse response = StorageContainerResponse.newBuilder().setCode(StatusCode.INTERNAL_SERVER_ERROR).build();
    when(rangeService.getActiveRanges(request)).thenReturn(FutureUtils.exception(CAUSE));
    TestResponseObserver<StorageContainerResponse> responseObserver = new TestResponseObserver<>();
    grpcService.getActiveRanges(request, responseObserver);
    responseObserver.verifySuccess(response);
    verify(rangeService, times(1)).getActiveRanges(request);
}
Also used : StorageContainerRequest(org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest) TestResponseObserver(org.apache.bookkeeper.stream.server.TestResponseObserver) RangeStoreImpl(org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl) StorageContainerResponse(org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse) Test(org.junit.Test)

Example 29 with StorageContainerResponse

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

the class TestGrpcMetaRangeService method testGetActiveRangesSuccess.

// 
// Meta KeyRange Server Requests tests
// 
@Test
public void testGetActiveRangesSuccess() throws Exception {
    RangeStoreImpl rangeService = mock(RangeStoreImpl.class);
    GrpcMetaRangeService grpcService = new GrpcMetaRangeService(rangeService);
    StorageContainerRequest request = StorageContainerRequest.newBuilder().setGetActiveRangesReq(GetActiveRangesRequest.newBuilder().setStreamId(23456L).build()).build();
    StorageContainerResponse response = StorageContainerResponse.newBuilder().setCode(StatusCode.SUCCESS).setGetActiveRangesResp(GetActiveRangesResponse.newBuilder()).build();
    when(rangeService.getActiveRanges(request)).thenReturn(CompletableFuture.completedFuture(response));
    TestResponseObserver<StorageContainerResponse> responseObserver = new TestResponseObserver<>();
    grpcService.getActiveRanges(request, responseObserver);
    responseObserver.verifySuccess(response);
    verify(rangeService, times(1)).getActiveRanges(request);
}
Also used : StorageContainerRequest(org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest) TestResponseObserver(org.apache.bookkeeper.stream.server.TestResponseObserver) RangeStoreImpl(org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl) StorageContainerResponse(org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse) Test(org.junit.Test)

Example 30 with StorageContainerResponse

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

the class TestGrpcTableService method testDeleteException.

@Test
public void testDeleteException() throws Exception {
    RangeStore rangeService = mock(RangeStore.class);
    GrpcTableService grpcService = new GrpcTableService(rangeService);
    StorageContainerRequest request = StorageContainerRequest.newBuilder().setKvDeleteReq(DeleteRangeRequest.newBuilder().setKey(TEST_KEY).setHeader(ROUTING_HEADER)).build();
    when(rangeService.delete(request)).thenReturn(FutureUtils.exception(new StatusRuntimeException(Status.NOT_FOUND)));
    TestResponseObserver<StorageContainerResponse> responseObserver = new TestResponseObserver<>();
    grpcService.delete(request, responseObserver);
    responseObserver.verifyException(Status.NOT_FOUND);
    verify(rangeService, times(1)).delete(request);
}
Also used : StorageContainerRequest(org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest) TestResponseObserver(org.apache.bookkeeper.stream.server.TestResponseObserver) StatusRuntimeException(io.grpc.StatusRuntimeException) RangeStore(org.apache.bookkeeper.stream.storage.api.RangeStore) StorageContainerResponse(org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse) Test(org.junit.Test)

Aggregations

StorageContainerResponse (org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse)42 Test (org.junit.Test)33 StorageContainerRequest (org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest)27 TestResponseObserver (org.apache.bookkeeper.stream.server.TestResponseObserver)12 RangeStore (org.apache.bookkeeper.stream.storage.api.RangeStore)9 StatusRuntimeException (io.grpc.StatusRuntimeException)6 DeleteRangeResponse (org.apache.bookkeeper.stream.proto.kv.rpc.DeleteRangeResponse)5 StorageContainer (org.apache.bookkeeper.stream.storage.api.sc.StorageContainer)4 StreamObserver (io.grpc.stub.StreamObserver)3 RangeResponse (org.apache.bookkeeper.stream.proto.kv.rpc.RangeResponse)3 GetActiveRangesResponse (org.apache.bookkeeper.stream.proto.storage.GetActiveRangesResponse)3 RangeStoreImpl (org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl)3 StatusException (io.grpc.StatusException)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 StorageServerChannel (org.apache.bookkeeper.clients.impl.channel.StorageServerChannel)2 PutResponse (org.apache.bookkeeper.stream.proto.kv.rpc.PutResponse)2 Status (io.grpc.Status)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 Cleanup (lombok.Cleanup)1