Search in sources :

Example 6 with StorageServerChannel

use of org.apache.bookkeeper.clients.impl.channel.StorageServerChannel in project bookkeeper by apache.

the class RootRangeClientImplTestBase method testChannelFailure.

@Test
public void testChannelFailure() throws Exception {
    CompletableFuture<StorageServerChannel> serviceFuture = FutureUtils.createFuture();
    rootRangeClient.getStorageContainerClient().setStorageServerChannelFuture(serviceFuture);
    IOException ioe = new IOException(testName.getMethodName());
    serviceFuture.completeExceptionally(ioe);
    verifyChannelFailure(ioe, rootRangeClient);
}
Also used : StorageServerChannel(org.apache.bookkeeper.clients.impl.channel.StorageServerChannel) IOException(java.io.IOException) Test(org.junit.Test)

Example 7 with StorageServerChannel

use of org.apache.bookkeeper.clients.impl.channel.StorageServerChannel in project bookkeeper by apache.

the class RootRangeClientImplTestBase method testRpcFailure.

@Test
public void testRpcFailure() throws Exception {
    CompletableFuture<StorageServerChannel> serviceFuture = FutureUtils.createFuture();
    rootRangeClient.getStorageContainerClient().setStorageServerChannelFuture(serviceFuture);
    RootRangeServiceImplBase rootRangeService = createRootRangeServiceForRpcFailure();
    serviceRegistry.addService(rootRangeService.bindService());
    StorageServerChannel rsChannel = new StorageServerChannel(InProcessChannelBuilder.forName(serverName).directExecutor().build(), Optional.empty());
    serviceFuture.complete(rsChannel);
    verifyRpcFailure(rootRangeClient);
}
Also used : StorageServerChannel(org.apache.bookkeeper.clients.impl.channel.StorageServerChannel) RootRangeServiceImplBase(org.apache.bookkeeper.stream.proto.storage.RootRangeServiceGrpc.RootRangeServiceImplBase) Test(org.junit.Test)

Example 8 with StorageServerChannel

use of org.apache.bookkeeper.clients.impl.channel.StorageServerChannel 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 9 with StorageServerChannel

use of org.apache.bookkeeper.clients.impl.channel.StorageServerChannel in project bookkeeper by apache.

the class TestMetaRangeClientImpl method testGetActiveStreamRangesFailure.

@Test
public void testGetActiveStreamRangesFailure() throws Exception {
    CompletableFuture<StorageServerChannel> serviceFuture = FutureUtils.createFuture();
    metaRangeClient.getStorageContainerClient().setStorageServerChannelFuture(serviceFuture);
    MetaRangeServiceImplBase metaRangeService = new MetaRangeServiceImplBase() {

        @Override
        public void getActiveRanges(StorageContainerRequest request, StreamObserver<StorageContainerResponse> responseObserver) {
            responseObserver.onError(new StatusRuntimeException(Status.INTERNAL));
        }
    };
    serviceRegistry.addService(metaRangeService.bindService());
    StorageServerChannel rsChannel = new StorageServerChannel(InProcessChannelBuilder.forName(serverName).directExecutor().build(), Optional.empty());
    serviceFuture.complete(rsChannel);
    CompletableFuture<HashStreamRanges> getFuture = metaRangeClient.getActiveDataRanges();
    try {
        getFuture.get();
        fail("should fail on rpc failure");
    } catch (ExecutionException ee) {
        assertNotNull(ee.getCause());
        assertTrue(ee.getCause() instanceof StatusRuntimeException);
        StatusRuntimeException se = (StatusRuntimeException) ee.getCause();
        assertEquals(Status.INTERNAL, se.getStatus());
    }
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) HashStreamRanges(org.apache.bookkeeper.clients.impl.internal.api.HashStreamRanges) StorageContainerRequest(org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest) StorageServerChannel(org.apache.bookkeeper.clients.impl.channel.StorageServerChannel) StatusRuntimeException(io.grpc.StatusRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) MetaRangeServiceImplBase(org.apache.bookkeeper.stream.proto.storage.MetaRangeServiceGrpc.MetaRangeServiceImplBase) Test(org.junit.Test)

Example 10 with StorageServerChannel

use of org.apache.bookkeeper.clients.impl.channel.StorageServerChannel in project bookkeeper by apache.

the class TestStorageContainerChannel method testGetRootRangeServiceFailureWhenClosingChannelManager.

@Test
public void testGetRootRangeServiceFailureWhenClosingChannelManager() throws Exception {
    CompletableFuture<List<OneStorageContainerEndpointResponse>> locateResponses = FutureUtils.createFuture();
    when(locationClient.locateStorageContainers(anyList())).thenReturn(locateResponses);
    // the future is not set before #getRootRangeService
    assertNull(scClient.getStorageServerChannelFuture());
    assertNull(scClient.getStorageContainerInfo());
    // call #getRootRangeService
    CompletableFuture<StorageServerChannel> rsChannelFuture = scClient.getStorageContainerChannelFuture();
    // the future is set and the locationClient#locateStorageContainers is called
    assertNotNull(scClient.getStorageServerChannelFuture());
    assertNull(scClient.getStorageContainerInfo());
    verify(locationClient, times(1)).locateStorageContainers(anyList());
    // if the request is outstanding, a second call will not call locationClient#locateStorageContainers
    CompletableFuture<StorageServerChannel> rsChannelFuture1 = scClient.getStorageContainerChannelFuture();
    assertTrue(rsChannelFuture == rsChannelFuture1);
    assertNull(scClient.getStorageContainerInfo());
    verify(locationClient, times(1)).locateStorageContainers(anyList());
    // closing the channel manager
    channelManager.close();
    // prepare the result and complete the request
    OneStorageContainerEndpointResponse oneResp = OneStorageContainerEndpointResponse.newBuilder().setStatusCode(StatusCode.SUCCESS).setEndpoint(StorageContainerEndpoint.newBuilder().setStorageContainerId(ROOT_STORAGE_CONTAINER_ID).setRevision(1000L).setRwEndpoint(endpoint).addRoEndpoint(endpoint).build()).build();
    locateResponses.complete(Lists.newArrayList(oneResp));
    // verify the result
    try {
        rsChannelFuture.get();
        fail("Should fail get root range service if channel manager is shutting down.");
    } catch (ExecutionException ee) {
        assertNotNull(ee.getCause());
        assertTrue(ee.getCause() instanceof ObjectClosedException);
    }
    // verify storage container info
    StorageContainerInfo scInfo = scClient.getStorageContainerInfo();
    assertEquals(ROOT_STORAGE_CONTAINER_ID, scInfo.getGroupId());
    assertEquals(1000L, scInfo.getRevision());
    assertEquals(endpoint, scInfo.getWriteEndpoint());
    assertEquals(Lists.newArrayList(endpoint, endpoint), scInfo.getReadEndpoints());
    // verify channel
    assertNull(channelManager.getChannel(endpoint));
    verify(locationClient, times(1)).locateStorageContainers(anyList());
}
Also used : OneStorageContainerEndpointResponse(org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse) ObjectClosedException(org.apache.bookkeeper.common.exceptions.ObjectClosedException) StorageServerChannel(org.apache.bookkeeper.clients.impl.channel.StorageServerChannel) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) List(java.util.List) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Aggregations

StorageServerChannel (org.apache.bookkeeper.clients.impl.channel.StorageServerChannel)14 Test (org.junit.Test)11 OneStorageContainerEndpointResponse (org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse)7 List (java.util.List)5 ArgumentMatchers.anyList (org.mockito.ArgumentMatchers.anyList)5 StreamObserver (io.grpc.stub.StreamObserver)4 RootRangeServiceImplBase (org.apache.bookkeeper.stream.proto.storage.RootRangeServiceGrpc.RootRangeServiceImplBase)3 StorageContainerRequest (org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest)3 ExecutionException (java.util.concurrent.ExecutionException)2 HashStreamRanges (org.apache.bookkeeper.clients.impl.internal.api.HashStreamRanges)2 ObjectClosedException (org.apache.bookkeeper.common.exceptions.ObjectClosedException)2 Endpoint (org.apache.bookkeeper.stream.proto.common.Endpoint)2 MetaRangeServiceImplBase (org.apache.bookkeeper.stream.proto.storage.MetaRangeServiceGrpc.MetaRangeServiceImplBase)2 StorageContainerEndpoint (org.apache.bookkeeper.stream.proto.storage.StorageContainerEndpoint)2 StorageContainerResponse (org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse)2 Server (io.grpc.Server)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 InProcessChannelBuilder (io.grpc.inprocess.InProcessChannelBuilder)1 InProcessServerBuilder (io.grpc.inprocess.InProcessServerBuilder)1 MutableHandlerRegistry (io.grpc.util.MutableHandlerRegistry)1