Search in sources :

Example 1 with GetStorageContainerEndpointRequest

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

the class TestLocationClientImpl method testLocateStorageContainersSucceedAfterRetried.

@Test
public void testLocateStorageContainersSucceedAfterRetried() throws Exception {
    serviceRegistry.removeService(locationServiceDefinition);
    final AtomicInteger retries = new AtomicInteger(3);
    StatusRuntimeException statusException = new StatusRuntimeException(Status.INTERNAL);
    StorageContainerServiceImplBase locationServiceWithFailures = new StorageContainerServiceImplBase() {

        @Override
        public void getStorageContainerEndpoint(GetStorageContainerEndpointRequest request, StreamObserver<GetStorageContainerEndpointResponse> responseObserver) {
            if (retries.decrementAndGet() == 0) {
                locationService.getStorageContainerEndpoint(request, responseObserver);
                return;
            }
            responseObserver.onError(statusException);
        }
    };
    serviceRegistry.addService(locationServiceWithFailures.bindService());
    testLocateStorageContainersSuccess();
    assertEquals(0, retries.get());
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) StorageContainerServiceImplBase(org.apache.bookkeeper.stream.proto.storage.StorageContainerServiceGrpc.StorageContainerServiceImplBase) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StatusRuntimeException(io.grpc.StatusRuntimeException) GetStorageContainerEndpointRequest(org.apache.bookkeeper.stream.proto.storage.GetStorageContainerEndpointRequest) Test(org.junit.Test)

Example 2 with GetStorageContainerEndpointRequest

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

the class TestLocationClientImpl method testLocateStorageContainersFailureAfterRetried.

@Test
public void testLocateStorageContainersFailureAfterRetried() throws Exception {
    serviceRegistry.removeService(locationServiceDefinition);
    final AtomicInteger retries = new AtomicInteger(3);
    StatusRuntimeException statusException = new StatusRuntimeException(Status.INTERNAL);
    StorageContainerServiceImplBase locationServiceWithFailures = new StorageContainerServiceImplBase() {

        @Override
        public void getStorageContainerEndpoint(GetStorageContainerEndpointRequest request, StreamObserver<GetStorageContainerEndpointResponse> responseObserver) {
            if (retries.decrementAndGet() == 0) {
                responseObserver.onError(new StatusRuntimeException(Status.INVALID_ARGUMENT));
                return;
            }
            responseObserver.onError(statusException);
        }
    };
    serviceRegistry.addService(locationServiceWithFailures.bindService());
    CompletableFuture<List<OneStorageContainerEndpointResponse>> future = locationClient.locateStorageContainers(Lists.newArrayList(Revisioned.of(1L, IRevisioned.ANY_REVISION)));
    try {
        future.get();
        fail("should fail with exception");
    } catch (ExecutionException ee) {
        assertNotNull(ee.getCause());
        assertTrue(ee.getCause() instanceof StatusRuntimeException);
        assertEquals(Status.INVALID_ARGUMENT, ((StatusRuntimeException) ee.getCause()).getStatus());
    }
    assertEquals(0, retries.get());
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) StorageContainerServiceImplBase(org.apache.bookkeeper.stream.proto.storage.StorageContainerServiceGrpc.StorageContainerServiceImplBase) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StatusRuntimeException(io.grpc.StatusRuntimeException) List(java.util.List) ExecutionException(java.util.concurrent.ExecutionException) GetStorageContainerEndpointRequest(org.apache.bookkeeper.stream.proto.storage.GetStorageContainerEndpointRequest) Test(org.junit.Test)

Example 3 with GetStorageContainerEndpointRequest

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

the class TestProtocolInternalUtils method testCreateGetStorageContainerEndpointRequest.

// 
// Test Location Server Requests
// 
@Test
public void testCreateGetStorageContainerEndpointRequest() {
    List<Revisioned<Long>> scs = Lists.newArrayList(Revisioned.of(1000L, 1L), Revisioned.of(2000L, 2L), Revisioned.of(3000L, 3L));
    GetStorageContainerEndpointRequest request = createGetStorageContainerEndpointRequest(scs);
    assertEquals(3, request.getRequestsCount());
    int i = 1;
    for (OneStorageContainerEndpointRequest oneRequest : request.getRequestsList()) {
        assertEquals(1000L * i, oneRequest.getStorageContainer());
        assertEquals(1L * i, oneRequest.getRevision());
        ++i;
    }
}
Also used : Revisioned(org.apache.bookkeeper.common.util.Revisioned) GetStorageContainerEndpointRequest(org.apache.bookkeeper.stream.proto.storage.GetStorageContainerEndpointRequest) ProtoUtils.createGetStorageContainerEndpointRequest(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createGetStorageContainerEndpointRequest) OneStorageContainerEndpointRequest(org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointRequest) StorageContainerEndpoint(org.apache.bookkeeper.stream.proto.storage.StorageContainerEndpoint) Test(org.junit.Test)

Example 4 with GetStorageContainerEndpointRequest

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

the class GrpcClientTestBase method setUp.

@Before
public void setUp() throws Exception {
    fakeServer = InProcessServerBuilder.forName(serverName).fallbackHandlerRegistry(serviceRegistry).directExecutor().build().start();
    scheduler = OrderedScheduler.newSchedulerBuilder().name("scheduler-" + getClass()).numThreads(Runtime.getRuntime().availableProcessors()).build();
    settings = StorageClientSettings.newBuilder().managedChannelBuilder(InProcessChannelBuilder.forName(serverName).directExecutor()).usePlaintext(true).build();
    serverManager = new StorageServerClientManagerImpl(settings, resources.scheduler(), endpoint -> new StorageServerChannel(InProcessChannelBuilder.forName(serverName).directExecutor().build(), Optional.empty()));
    StorageContainerServiceImplBase scService = new StorageContainerServiceImplBase() {

        @Override
        public void getStorageContainerEndpoint(GetStorageContainerEndpointRequest request, StreamObserver<GetStorageContainerEndpointResponse> responseObserver) {
            GetStorageContainerEndpointResponse.Builder respBuilder = GetStorageContainerEndpointResponse.newBuilder();
            respBuilder.setStatusCode(StatusCode.SUCCESS);
            for (OneStorageContainerEndpointRequest oneReq : request.getRequestsList()) {
                OneStorageContainerEndpointResponse oneResp = OneStorageContainerEndpointResponse.newBuilder().setEndpoint(StorageContainerEndpoint.newBuilder().setStorageContainerId(oneReq.getStorageContainer()).setRevision(oneReq.getRevision() + 1).setRwEndpoint(ENDPOINT)).build();
                respBuilder.addResponses(oneResp);
            }
            responseObserver.onNext(respBuilder.build());
            responseObserver.onCompleted();
        }
    };
    serviceRegistry.addService(scService.bindService());
    doSetup();
}
Also used : GetStorageContainerEndpointRequest(org.apache.bookkeeper.stream.proto.storage.GetStorageContainerEndpointRequest) StorageServerChannel(org.apache.bookkeeper.clients.impl.channel.StorageServerChannel) OrderedScheduler(org.apache.bookkeeper.common.util.OrderedScheduler) OneStorageContainerEndpointResponse(org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse) StorageContainerServiceImplBase(org.apache.bookkeeper.stream.proto.storage.StorageContainerServiceGrpc.StorageContainerServiceImplBase) InProcessServerBuilder(io.grpc.inprocess.InProcessServerBuilder) MutableHandlerRegistry(io.grpc.util.MutableHandlerRegistry) ClientResources(org.apache.bookkeeper.clients.utils.ClientResources) OneStorageContainerEndpointRequest(org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointRequest) StreamObserver(io.grpc.stub.StreamObserver) StorageServerClientManagerImpl(org.apache.bookkeeper.clients.impl.internal.StorageServerClientManagerImpl) StorageClientSettings(org.apache.bookkeeper.clients.config.StorageClientSettings) Endpoint(org.apache.bookkeeper.stream.proto.common.Endpoint) StorageContainerEndpoint(org.apache.bookkeeper.stream.proto.storage.StorageContainerEndpoint) After(org.junit.After) Optional(java.util.Optional) Server(io.grpc.Server) InProcessChannelBuilder(io.grpc.inprocess.InProcessChannelBuilder) StatusCode(org.apache.bookkeeper.stream.proto.storage.StatusCode) GetStorageContainerEndpointResponse(org.apache.bookkeeper.stream.proto.storage.GetStorageContainerEndpointResponse) Before(org.junit.Before) StreamObserver(io.grpc.stub.StreamObserver) StorageContainerServiceImplBase(org.apache.bookkeeper.stream.proto.storage.StorageContainerServiceGrpc.StorageContainerServiceImplBase) StorageServerClientManagerImpl(org.apache.bookkeeper.clients.impl.internal.StorageServerClientManagerImpl) GetStorageContainerEndpointResponse(org.apache.bookkeeper.stream.proto.storage.GetStorageContainerEndpointResponse) OneStorageContainerEndpointResponse(org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse) StorageServerChannel(org.apache.bookkeeper.clients.impl.channel.StorageServerChannel) GetStorageContainerEndpointRequest(org.apache.bookkeeper.stream.proto.storage.GetStorageContainerEndpointRequest) OneStorageContainerEndpointRequest(org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointRequest) Before(org.junit.Before)

Aggregations

GetStorageContainerEndpointRequest (org.apache.bookkeeper.stream.proto.storage.GetStorageContainerEndpointRequest)4 StreamObserver (io.grpc.stub.StreamObserver)3 StorageContainerServiceImplBase (org.apache.bookkeeper.stream.proto.storage.StorageContainerServiceGrpc.StorageContainerServiceImplBase)3 Test (org.junit.Test)3 StatusRuntimeException (io.grpc.StatusRuntimeException)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 OneStorageContainerEndpointRequest (org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointRequest)2 StorageContainerEndpoint (org.apache.bookkeeper.stream.proto.storage.StorageContainerEndpoint)2 Server (io.grpc.Server)1 InProcessChannelBuilder (io.grpc.inprocess.InProcessChannelBuilder)1 InProcessServerBuilder (io.grpc.inprocess.InProcessServerBuilder)1 MutableHandlerRegistry (io.grpc.util.MutableHandlerRegistry)1 List (java.util.List)1 Optional (java.util.Optional)1 ExecutionException (java.util.concurrent.ExecutionException)1 StorageClientSettings (org.apache.bookkeeper.clients.config.StorageClientSettings)1 StorageServerChannel (org.apache.bookkeeper.clients.impl.channel.StorageServerChannel)1 StorageServerClientManagerImpl (org.apache.bookkeeper.clients.impl.internal.StorageServerClientManagerImpl)1 ClientResources (org.apache.bookkeeper.clients.utils.ClientResources)1 OrderedScheduler (org.apache.bookkeeper.common.util.OrderedScheduler)1