Search in sources :

Example 11 with StorageContainerResponse

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

the class StorageContainerImplTest method testTxnWhenTableStoreNotCached.

@Test
public void testTxnWhenTableStoreNotCached() throws Exception {
    mockStorageContainer(SCID);
    StorageContainerResponse expectedResp = StorageContainerResponse.getDefaultInstance();
    when(trStore.txn(any(StorageContainerRequest.class))).thenReturn(FutureUtils.value(expectedResp));
    StorageContainerRequest request = newStorageContainerRequest(KV_TXN_REQ);
    StorageContainerResponse response = FutureUtils.result(container.txn(request));
    assertSame(expectedResp, response);
    assertSame(trStore, container.getTableStoreCache().getTableStore(RID));
}
Also used : StorageContainerRequest(org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest) StorageContainerResponse(org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse) Test(org.junit.Test)

Example 12 with StorageContainerResponse

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

the class StorageContainerImplTest method testRangeWhenTableStoreNotCached.

@Test
public void testRangeWhenTableStoreNotCached() throws Exception {
    mockStorageContainer(SCID);
    StorageContainerResponse expectedResp = StorageContainerResponse.getDefaultInstance();
    when(trStore.range(any(StorageContainerRequest.class))).thenReturn(FutureUtils.value(expectedResp));
    StorageContainerRequest request = newStorageContainerRequest(KV_RANGE_REQ);
    StorageContainerResponse response = FutureUtils.result(container.range(request));
    assertSame(expectedResp, response);
    assertSame(trStore, container.getTableStoreCache().getTableStore(RID));
}
Also used : StorageContainerRequest(org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest) StorageContainerResponse(org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse) Test(org.junit.Test)

Example 13 with StorageContainerResponse

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

the class StorageContainerImplTest method testDeleteWhenTableStoreNotCached.

@Test
public void testDeleteWhenTableStoreNotCached() throws Exception {
    mockStorageContainer(SCID);
    StorageContainerResponse expectedResp = StorageContainerResponse.getDefaultInstance();
    when(trStore.delete(any(StorageContainerRequest.class))).thenReturn(FutureUtils.value(expectedResp));
    StorageContainerRequest request = newStorageContainerRequest(KV_DELETE_REQ);
    StorageContainerResponse response = FutureUtils.result(container.delete(request));
    assertSame(expectedResp, response);
    assertSame(trStore, container.getTableStoreCache().getTableStore(RID));
}
Also used : StorageContainerRequest(org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest) StorageContainerResponse(org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse) Test(org.junit.Test)

Example 14 with StorageContainerResponse

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

the class TableRequestProcessorTest method testProcess.

private void testProcess(RequestCase type) throws Exception {
    @Cleanup("shutdown") ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
    StorageContainerChannel scChannel = mock(StorageContainerChannel.class);
    CompletableFuture<StorageServerChannel> serverChannelFuture = FutureUtils.createFuture();
    when(scChannel.getStorageContainerChannelFuture()).thenReturn(serverChannelFuture);
    StorageContainerResponse.Builder respBuilder = StorageContainerResponse.newBuilder().setCode(StatusCode.SUCCESS);
    switch(type) {
        case KV_PUT_REQ:
            respBuilder.setKvPutResp(PutResponse.newBuilder().build());
            break;
        case KV_DELETE_REQ:
            respBuilder.setKvDeleteResp(DeleteRangeResponse.newBuilder().build());
            break;
        case KV_RANGE_REQ:
            respBuilder.setKvRangeResp(RangeResponse.newBuilder().build());
            break;
        case KV_INCR_REQ:
            respBuilder.setKvIncrResp(IncrementResponse.newBuilder().build());
            break;
        case KV_TXN_REQ:
            respBuilder.setKvTxnResp(TxnResponse.newBuilder().build());
            break;
        default:
            break;
    }
    StorageContainerResponse response = respBuilder.build();
    AtomicReference<StorageContainerRequest> receivedRequest = new AtomicReference<>(null);
    AtomicReference<RequestCase> receivedRequestType = new AtomicReference<>(null);
    TableServiceImplBase tableService = new TableServiceImplBase() {

        @Override
        public void range(StorageContainerRequest request, StreamObserver<StorageContainerResponse> responseObserver) {
            receivedRequest.set(request);
            receivedRequestType.set(KV_RANGE_REQ);
            complete(responseObserver);
        }

        @Override
        public void put(StorageContainerRequest request, StreamObserver<StorageContainerResponse> responseObserver) {
            receivedRequest.set(request);
            receivedRequestType.set(KV_PUT_REQ);
            complete(responseObserver);
        }

        @Override
        public void delete(StorageContainerRequest request, StreamObserver<StorageContainerResponse> responseObserver) {
            receivedRequest.set(request);
            receivedRequestType.set(KV_DELETE_REQ);
            complete(responseObserver);
        }

        @Override
        public void txn(StorageContainerRequest request, StreamObserver<StorageContainerResponse> responseObserver) {
            receivedRequest.set(request);
            receivedRequestType.set(KV_TXN_REQ);
            complete(responseObserver);
        }

        @Override
        public void increment(StorageContainerRequest request, StreamObserver<StorageContainerResponse> responseObserver) {
            receivedRequest.set(request);
            receivedRequestType.set(KV_INCR_REQ);
            complete(responseObserver);
        }

        private void complete(StreamObserver<StorageContainerResponse> responseStreamObserver) {
            responseStreamObserver.onNext(response);
            responseStreamObserver.onCompleted();
        }
    };
    serviceRegistry.addService(tableService.bindService());
    StorageServerChannel ssChannel = new StorageServerChannel(InProcessChannelBuilder.forName(serverName).directExecutor().build(), Optional.empty());
    serverChannelFuture.complete(ssChannel);
    StorageContainerRequest.Builder requestBuilder = StorageContainerRequest.newBuilder();
    switch(type) {
        case KV_PUT_REQ:
            requestBuilder.setKvPutReq(PutRequest.newBuilder().build());
            break;
        case KV_DELETE_REQ:
            requestBuilder.setKvDeleteReq(DeleteRangeRequest.newBuilder().build());
            break;
        case KV_RANGE_REQ:
            requestBuilder.setKvRangeReq(RangeRequest.newBuilder().build());
            break;
        case KV_INCR_REQ:
            requestBuilder.setKvIncrReq(IncrementRequest.newBuilder().build());
            break;
        case KV_TXN_REQ:
            requestBuilder.setKvTxnReq(TxnRequest.newBuilder().build());
            break;
        default:
            break;
    }
    StorageContainerRequest request = requestBuilder.build();
    TableRequestProcessor<String> processor = TableRequestProcessor.of(request, resp -> "test", scChannel, scheduler);
    assertEquals("test", FutureUtils.result(processor.process()));
    assertSame(request, receivedRequest.get());
    assertEquals(type, receivedRequestType.get());
}
Also used : TableServiceImplBase(org.apache.bookkeeper.stream.proto.storage.TableServiceGrpc.TableServiceImplBase) StreamObserver(io.grpc.stub.StreamObserver) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) StorageContainerRequest(org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest) StorageServerChannel(org.apache.bookkeeper.clients.impl.channel.StorageServerChannel) AtomicReference(java.util.concurrent.atomic.AtomicReference) Cleanup(lombok.Cleanup) StorageContainerResponse(org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse) RequestCase(org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest.RequestCase) StorageContainerChannel(org.apache.bookkeeper.clients.impl.container.StorageContainerChannel)

Example 15 with StorageContainerResponse

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

the class TableRequestProcessor method sendRPC.

@Override
protected ListenableFuture<StorageContainerResponse> sendRPC(StorageServerChannel rsChannel, StorageContainerRequest request) {
    switch(request.getRequestCase()) {
        case KV_RANGE_REQ:
            return rsChannel.getTableService().range(request);
        case KV_PUT_REQ:
            return rsChannel.getTableService().put(request);
        case KV_DELETE_REQ:
            return rsChannel.getTableService().delete(request);
        case KV_INCR_REQ:
            return rsChannel.getTableService().increment(request);
        case KV_TXN_REQ:
            return rsChannel.getTableService().txn(request);
        default:
            SettableFuture<StorageContainerResponse> respFuture = SettableFuture.create();
            respFuture.setException(new Exception("Unknown request " + request));
            return respFuture;
    }
}
Also used : InternalServerException(org.apache.bookkeeper.clients.exceptions.InternalServerException) StorageContainerResponse(org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse)

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