Search in sources :

Example 76 with ManagedChannel

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel in project grpc-java by grpc.

the class StressTestClient method runStressTest.

@VisibleForTesting
void runStressTest() throws Exception {
    Preconditions.checkState(!shutdown, "client was shutdown.");
    if (testCaseWeightPairs.isEmpty()) {
        return;
    }
    int numChannels = addresses.size() * channelsPerServer;
    int numThreads = numChannels * stubsPerChannel;
    threadpool = MoreExecutors.listeningDecorator(newFixedThreadPool(numThreads));
    int serverIdx = -1;
    for (InetSocketAddress address : addresses) {
        serverIdx++;
        for (int i = 0; i < channelsPerServer; i++) {
            ManagedChannel channel = createChannel(address);
            channels.add(channel);
            for (int j = 0; j < stubsPerChannel; j++) {
                String gaugeName = String.format("/stress_test/server_%d/channel_%d/stub_%d/qps", serverIdx, i, j);
                Worker worker = new Worker(channel, testCaseWeightPairs, durationSecs, gaugeName);
                workerFutures.add(threadpool.submit(worker));
            }
        }
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ManagedChannel(io.grpc.ManagedChannel) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 77 with ManagedChannel

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel in project grpc-java by grpc.

the class StressTestClient method shutdown.

@VisibleForTesting
void shutdown() {
    if (shutdown) {
        return;
    }
    shutdown = true;
    for (ManagedChannel ch : channels) {
        try {
            ch.shutdownNow();
            ch.awaitTermination(1, SECONDS);
        } catch (Throwable t) {
            log.log(Level.WARNING, "Error shutting down channel!", t);
        }
    }
    try {
        metricsServer.shutdownNow();
    } catch (Throwable t) {
        log.log(Level.WARNING, "Error shutting down metrics service!", t);
    }
    try {
        if (threadpool != null) {
            threadpool.shutdownNow();
        }
    } catch (Throwable t) {
        log.log(Level.WARNING, "Error shutting down threadpool.", t);
    }
}
Also used : ManagedChannel(io.grpc.ManagedChannel) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 78 with ManagedChannel

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel in project grpc-java by grpc.

the class HealthCheckingLoadBalancerFactoryTest method setup.

@Before
@SuppressWarnings("unchecked")
public void setup() throws Exception {
    MockitoAnnotations.initMocks(this);
    for (int i = 0; i < NUM_SUBCHANNELS; i++) {
        HealthImpl healthImpl = new HealthImpl();
        healthImpls[i] = healthImpl;
        Server server = InProcessServerBuilder.forName("health-check-test-" + i).addService(healthImpl).directExecutor().build().start();
        servers[i] = server;
        ManagedChannel channel = InProcessChannelBuilder.forName("health-check-test-" + i).directExecutor().build();
        channels[i] = channel;
        EquivalentAddressGroup eag = new EquivalentAddressGroup(new FakeSocketAddress("address-" + i));
        eags[i] = eag;
        List<EquivalentAddressGroup> eagList = Arrays.asList(eag);
        eagLists[i] = eagList;
        mockStateListeners[i] = mock(SubchannelStateListener.class);
    }
    resolvedAddressList = Arrays.asList(eags);
    when(backoffPolicyProvider.get()).thenReturn(backoffPolicy1, backoffPolicy2);
    when(backoffPolicy1.nextBackoffNanos()).thenReturn(11L, 21L, 31L);
    when(backoffPolicy2.nextBackoffNanos()).thenReturn(12L, 22L, 32L);
    hcLbFactory = new HealthCheckingLoadBalancerFactory(origLbFactory, backoffPolicyProvider, clock.getStopwatchSupplier());
    hcLb = hcLbFactory.newLoadBalancer(origHelper);
    // Make sure all calls into the hcLb is from the syncContext
    hcLbEventDelivery = new LoadBalancer() {

        // Per LoadBalancer API, no more callbacks will be called after shutdown() is called.
        boolean shutdown;

        @Override
        public void handleResolvedAddresses(final ResolvedAddresses resolvedAddresses) {
            syncContext.execute(new Runnable() {

                @Override
                public void run() {
                    if (!shutdown) {
                        hcLb.handleResolvedAddresses(resolvedAddresses);
                    }
                }
            });
        }

        @Override
        public void handleNameResolutionError(Status error) {
            throw new AssertionError("Not supposed to be called");
        }

        @Override
        public void shutdown() {
            syncContext.execute(new Runnable() {

                @Override
                public void run() {
                    if (!shutdown) {
                        shutdown = true;
                        hcLb.shutdown();
                    }
                }
            });
        }
    };
    verify(origLbFactory).newLoadBalancer(any(Helper.class));
}
Also used : Status(io.grpc.Status) ServingStatus(io.grpc.health.v1.HealthCheckResponse.ServingStatus) SubchannelStateListener(io.grpc.LoadBalancer.SubchannelStateListener) Server(io.grpc.Server) LoadBalancer(io.grpc.LoadBalancer) Helper(io.grpc.LoadBalancer.Helper) EquivalentAddressGroup(io.grpc.EquivalentAddressGroup) ManagedChannel(io.grpc.ManagedChannel) ResolvedAddresses(io.grpc.LoadBalancer.ResolvedAddresses) Before(org.junit.Before)

Example 79 with ManagedChannel

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel in project grpc-java by grpc.

the class ProtoReflectionServiceTest method sharedServiceBetweenServers.

@Test
public void sharedServiceBetweenServers() throws IOException, ExecutionException, InterruptedException {
    Server anotherServer = InProcessServerBuilder.forName("proto-reflection-test-2").directExecutor().addService(reflectionService).addService(new AnotherReflectableServiceGrpc.AnotherReflectableServiceImplBase() {
    }).build().start();
    grpcCleanupRule.register(anotherServer);
    ManagedChannel anotherChannel = grpcCleanupRule.register(InProcessChannelBuilder.forName("proto-reflection-test-2").directExecutor().build());
    ServerReflectionGrpc.ServerReflectionStub stub2 = ServerReflectionGrpc.newStub(anotherChannel);
    ServerReflectionRequest request = ServerReflectionRequest.newBuilder().setHost(TEST_HOST).setListServices("services").build();
    StreamRecorder<ServerReflectionResponse> responseObserver = StreamRecorder.create();
    StreamObserver<ServerReflectionRequest> requestObserver = stub2.serverReflectionInfo(responseObserver);
    requestObserver.onNext(request);
    requestObserver.onCompleted();
    List<ServiceResponse> response = responseObserver.firstValue().get().getListServicesResponse().getServiceList();
    assertEquals(new HashSet<>(Arrays.asList(ServiceResponse.newBuilder().setName("grpc.reflection.v1alpha.ServerReflection").build(), ServiceResponse.newBuilder().setName("grpc.reflection.testing.AnotherReflectableService").build())), new HashSet<>(response));
}
Also used : Server(io.grpc.Server) ServerReflectionRequest(io.grpc.reflection.v1alpha.ServerReflectionRequest) ServiceResponse(io.grpc.reflection.v1alpha.ServiceResponse) AnotherReflectableServiceGrpc(io.grpc.reflection.testing.AnotherReflectableServiceGrpc) ManagedChannel(io.grpc.ManagedChannel) ServerReflectionGrpc(io.grpc.reflection.v1alpha.ServerReflectionGrpc) ServerReflectionResponse(io.grpc.reflection.v1alpha.ServerReflectionResponse) Test(org.junit.Test)

Example 80 with ManagedChannel

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel in project grpc-java by grpc.

the class ManagedChannelImplTest method oobChannelsWhenChannelShutdownNow.

@Test
public void oobChannelsWhenChannelShutdownNow() {
    createChannel();
    ManagedChannel oob1 = helper.createOobChannel(Collections.singletonList(addressGroup), "oob1Authority");
    ManagedChannel oob2 = helper.createOobChannel(Collections.singletonList(addressGroup), "oob2Authority");
    oob1.newCall(method, CallOptions.DEFAULT).start(mockCallListener, new Metadata());
    oob2.newCall(method, CallOptions.DEFAULT).start(mockCallListener2, new Metadata());
    assertThat(transports).hasSize(2);
    MockClientTransportInfo ti1 = transports.poll();
    MockClientTransportInfo ti2 = transports.poll();
    ti1.listener.transportReady();
    ti2.listener.transportReady();
    channel.shutdownNow();
    verify(ti1.transport).shutdownNow(any(Status.class));
    verify(ti2.transport).shutdownNow(any(Status.class));
    ti1.listener.transportShutdown(Status.UNAVAILABLE.withDescription("shutdown now"));
    ti2.listener.transportShutdown(Status.UNAVAILABLE.withDescription("shutdown now"));
    ti1.listener.transportTerminated();
    assertFalse(channel.isTerminated());
    ti2.listener.transportTerminated();
    assertTrue(channel.isTerminated());
}
Also used : Status(io.grpc.Status) Metadata(io.grpc.Metadata) ManagedChannel(io.grpc.ManagedChannel) MockClientTransportInfo(io.grpc.internal.TestUtils.MockClientTransportInfo) Test(org.junit.Test)

Aggregations

ManagedChannel (io.grpc.ManagedChannel)163 Test (org.junit.Test)92 CountDownLatch (java.util.concurrent.CountDownLatch)26 ManagedChannel (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel)26 ArrayList (java.util.ArrayList)20 Metadata (io.grpc.Metadata)18 EquivalentAddressGroup (io.grpc.EquivalentAddressGroup)15 ExecutorService (java.util.concurrent.ExecutorService)13 ByteString (com.google.protobuf.ByteString)12 Status (io.grpc.Status)12 StreamObserver (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver)11 StreamObserver (io.grpc.stub.StreamObserver)10 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)10 BeamFnApi (org.apache.beam.model.fnexecution.v1.BeamFnApi)10 CallOptions (io.grpc.CallOptions)9 Subchannel (io.grpc.LoadBalancer.Subchannel)9 SubchannelPicker (io.grpc.LoadBalancer.SubchannelPicker)9 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)9 Endpoints (org.apache.beam.model.pipeline.v1.Endpoints)9