Search in sources :

Example 21 with StorageContainerResponse

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

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

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

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

the class TestStorageContainerResponseHandler method testStatusException.

@SuppressWarnings("unchecked")
@Test
public void testStatusException() {
    StreamObserver<StorageContainerResponse> observer = mock(StreamObserver.class);
    StorageContainerResponseHandler handler = StorageContainerResponseHandler.of(observer);
    StatusException exception = new StatusException(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 : StatusException(io.grpc.StatusException) StorageContainerResponse(org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse) Test(org.junit.Test)

Example 25 with StorageContainerResponse

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

the class TestStorageContainerResponseHandler method testInternalError.

@SuppressWarnings("unchecked")
@Test
public void testInternalError() throws Exception {
    StreamObserver<StorageContainerResponse> observer = mock(StreamObserver.class);
    AtomicReference<StorageContainerResponse> responseHolder = new AtomicReference<>(null);
    CountDownLatch latch = new CountDownLatch(1);
    doAnswer((Answer<Void>) invocation -> {
        StorageContainerResponse resp = invocation.getArgument(0);
        responseHolder.set(resp);
        latch.countDown();
        return null;
    }).when(observer).onNext(any(StorageContainerResponse.class));
    StorageContainerResponseHandler handler = StorageContainerResponseHandler.of(observer);
    StorageException exception = new StorageException("test-exception");
    handler.accept(null, exception);
    verify(observer, times(1)).onNext(any());
    verify(observer, times(1)).onCompleted();
    verify(observer, times(0)).onError(any());
    latch.await();
    assertNotNull(responseHolder.get());
    assertEquals(StatusCode.INTERNAL_SERVER_ERROR, responseHolder.get().getCode());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Assert.assertNotNull(org.junit.Assert.assertNotNull) StatusException(io.grpc.StatusException) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) AtomicReference(java.util.concurrent.atomic.AtomicReference) Mockito.verify(org.mockito.Mockito.verify) StatusRuntimeException(io.grpc.StatusRuntimeException) CountDownLatch(java.util.concurrent.CountDownLatch) StorageContainerResponse(org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse) Answer(org.mockito.stubbing.Answer) StreamObserver(io.grpc.stub.StreamObserver) StorageException(org.apache.bookkeeper.stream.storage.exceptions.StorageException) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Status(io.grpc.Status) Assert.assertEquals(org.junit.Assert.assertEquals) StatusCode(org.apache.bookkeeper.stream.proto.storage.StatusCode) Mockito.mock(org.mockito.Mockito.mock) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) StorageException(org.apache.bookkeeper.stream.storage.exceptions.StorageException) 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