Search in sources :

Example 6 with TestResponseObserver

use of org.apache.bookkeeper.stream.server.TestResponseObserver in project bookkeeper by apache.

the class TestGrpcTableService method testDeleteSuccess.

@Test
public void testDeleteSuccess() 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();
    StorageContainerResponse response = StorageContainerResponse.newBuilder().setCode(StatusCode.SUCCESS).setKvDeleteResp(DeleteRangeResponse.newBuilder()).build();
    when(rangeService.delete(request)).thenReturn(CompletableFuture.completedFuture(response));
    TestResponseObserver<StorageContainerResponse> responseObserver = new TestResponseObserver<>();
    grpcService.delete(request, responseObserver);
    responseObserver.verifySuccess(response);
    verify(rangeService, times(1)).delete(request);
}
Also used : StorageContainerRequest(org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest) TestResponseObserver(org.apache.bookkeeper.stream.server.TestResponseObserver) RangeStore(org.apache.bookkeeper.stream.storage.api.RangeStore) StorageContainerResponse(org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse) Test(org.junit.Test)

Example 7 with TestResponseObserver

use of org.apache.bookkeeper.stream.server.TestResponseObserver in project bookkeeper by apache.

the class TestGrpcTableService method testPutException.

@Test
public void testPutException() throws Exception {
    RangeStore rangeService = mock(RangeStore.class);
    GrpcTableService grpcService = new GrpcTableService(rangeService);
    StorageContainerRequest request = StorageContainerRequest.newBuilder().setKvPutReq(PutRequest.newBuilder().setKey(TEST_KEY).setValue(TEST_VAL).setHeader(ROUTING_HEADER)).build();
    when(rangeService.put(request)).thenReturn(FutureUtils.exception(new StatusRuntimeException(Status.NOT_FOUND)));
    TestResponseObserver<StorageContainerResponse> responseObserver = new TestResponseObserver<>();
    grpcService.put(request, responseObserver);
    responseObserver.verifyException(Status.NOT_FOUND);
    verify(rangeService, times(1)).put(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)

Example 8 with TestResponseObserver

use of org.apache.bookkeeper.stream.server.TestResponseObserver in project bookkeeper by apache.

the class TestGrpcTableService method testRangeActiveRangesFailure.

@Test
public void testRangeActiveRangesFailure() throws Exception {
    RangeStore rangeService = mock(RangeStore.class);
    GrpcTableService grpcService = new GrpcTableService(rangeService);
    StorageContainerRequest request = StorageContainerRequest.newBuilder().setKvRangeReq(RangeRequest.newBuilder().setKey(TEST_KEY).setHeader(ROUTING_HEADER)).build();
    StorageContainerResponse response = StorageContainerResponse.newBuilder().setCode(StatusCode.INTERNAL_SERVER_ERROR).build();
    when(rangeService.range(request)).thenReturn(FutureUtils.exception(CAUSE));
    TestResponseObserver<StorageContainerResponse> responseObserver = new TestResponseObserver<>();
    grpcService.range(request, responseObserver);
    responseObserver.verifySuccess(response);
    verify(rangeService, times(1)).range(request);
}
Also used : StorageContainerRequest(org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest) TestResponseObserver(org.apache.bookkeeper.stream.server.TestResponseObserver) RangeStore(org.apache.bookkeeper.stream.storage.api.RangeStore) StorageContainerResponse(org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse) Test(org.junit.Test)

Example 9 with TestResponseObserver

use of org.apache.bookkeeper.stream.server.TestResponseObserver 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 10 with TestResponseObserver

use of org.apache.bookkeeper.stream.server.TestResponseObserver 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)

Aggregations

StorageContainerRequest (org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest)12 StorageContainerResponse (org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse)12 TestResponseObserver (org.apache.bookkeeper.stream.server.TestResponseObserver)12 Test (org.junit.Test)12 RangeStore (org.apache.bookkeeper.stream.storage.api.RangeStore)9 StatusRuntimeException (io.grpc.StatusRuntimeException)4 RangeStoreImpl (org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl)3