Search in sources :

Example 1 with ManagedChannel

use of io.grpc.ManagedChannel in project beam by apache.

the class ManagedChannelFactoryTest method testEpollHostPortChannel.

@Test
public void testEpollHostPortChannel() {
    assumeTrue(io.netty.channel.epoll.Epoll.isAvailable());
    ApiServiceDescriptor apiServiceDescriptor = ApiServiceDescriptor.newBuilder().setUrl("localhost:123").build();
    ManagedChannel channel = ManagedChannelFactory.from(PipelineOptionsFactory.fromArgs(new String[] { "--experiments=beam_fn_api_epoll" }).create()).forDescriptor(apiServiceDescriptor);
    assertEquals("localhost:123", channel.authority());
    channel.shutdownNow();
}
Also used : ApiServiceDescriptor(org.apache.beam.fn.v1.BeamFnApi.ApiServiceDescriptor) ManagedChannel(io.grpc.ManagedChannel) Test(org.junit.Test)

Example 2 with ManagedChannel

use of io.grpc.ManagedChannel in project grpc-java by grpc.

the class TransportCompressionTest method createChannel.

@Override
protected ManagedChannel createChannel() {
    NettyChannelBuilder builder = NettyChannelBuilder.forAddress("localhost", getPort()).maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE).decompressorRegistry(decompressors).compressorRegistry(compressors).intercept(new ClientInterceptor() {

        @Override
        public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
            final ClientCall<ReqT, RespT> call = next.newCall(method, callOptions);
            return new ForwardingClientCall<ReqT, RespT>() {

                @Override
                protected ClientCall<ReqT, RespT> delegate() {
                    return call;
                }

                @Override
                public void start(final ClientCall.Listener<RespT> responseListener, Metadata headers) {
                    ClientCall.Listener<RespT> listener = new ForwardingClientCallListener<RespT>() {

                        @Override
                        protected io.grpc.ClientCall.Listener<RespT> delegate() {
                            return responseListener;
                        }

                        @Override
                        public void onHeaders(Metadata headers) {
                            super.onHeaders(headers);
                            if (expectFzip) {
                                String encoding = headers.get(GrpcUtil.MESSAGE_ENCODING_KEY);
                                assertEquals(encoding, FZIPPER.getMessageEncoding());
                            }
                        }
                    };
                    super.start(listener, headers);
                    setMessageCompression(true);
                }
            };
        }
    }).usePlaintext(true);
    io.grpc.internal.TestingAccessor.setStatsContextFactory(builder, getClientStatsFactory());
    return builder.build();
}
Also used : ForwardingClientCallListener(io.grpc.ForwardingClientCallListener) Listener(io.grpc.ServerCall.Listener) ManagedChannel(io.grpc.ManagedChannel) Channel(io.grpc.Channel) ForwardingClientCall(io.grpc.ForwardingClientCall) Metadata(io.grpc.Metadata) CallOptions(io.grpc.CallOptions) ByteString(com.google.protobuf.ByteString) MethodDescriptor(io.grpc.MethodDescriptor) ClientCall(io.grpc.ClientCall) ForwardingClientCall(io.grpc.ForwardingClientCall) ClientInterceptor(io.grpc.ClientInterceptor) NettyChannelBuilder(io.grpc.netty.NettyChannelBuilder) ForwardingClientCallListener(io.grpc.ForwardingClientCallListener)

Example 3 with ManagedChannel

use of io.grpc.ManagedChannel in project sonarlint-core by SonarSource.

the class ConnectedDaemonTest method testNormal.

@Test
public void testNormal() throws InterruptedException, IOException {
    daemon.run();
    daemon.waitReady();
    ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 8050).usePlaintext(true).build();
    LogCollector logs = new LogCollector();
    ConnectedSonarLintBlockingStub sonarlint = ConnectedSonarLintGrpc.newBlockingStub(channel);
    // REGISTER
    sonarlint.start(createConnectedConfig());
    // STATE
    assertThat(sonarlint.getState(Void.newBuilder().build()).getState()).isEqualTo(StorageState.State.NEVER_UPDATED);
    // UPDATE GLOBAL
    ServerConfig serverConfig = ServerConfig.newBuilder().setHostUrl(ORCHESTRATOR.getServer().getUrl()).setCredentials(Credentials.newBuilder().setLogin(SONARLINT_USER).setPassword(SONARLINT_PWD).build()).build();
    sonarlint.update(serverConfig);
    // STATE
    assertThat(sonarlint.getState(Void.newBuilder().build()).getState()).isEqualTo(StorageState.State.UPDATED);
    // UPDATE MODULE
    ModuleUpdateReq moduleUpdate = ModuleUpdateReq.newBuilder().setModuleKey(PROJECT_KEY_JAVA).setServerConfig(serverConfig).build();
    sonarlint.updateModule(moduleUpdate);
    // ANALYSIS
    ClientCall<Void, LogEvent> call = getLogs(logs, channel);
    Iterator<Issue> issues = sonarlint.analyze(createAnalysisConfig(PROJECT_KEY_JAVA));
    assertThat(issues).hasSize(3);
    // assertThat(logs.getLogsAndClear()).contains("2 files indexed");
    call.cancel(null, null);
    channel.shutdownNow();
    channel.awaitTermination(2, TimeUnit.SECONDS);
}
Also used : ServerConfig(org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.ServerConfig) ConnectedSonarLintBlockingStub(org.sonarsource.sonarlint.daemon.proto.ConnectedSonarLintGrpc.ConnectedSonarLintBlockingStub) Issue(org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.Issue) LogEvent(org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.LogEvent) ModuleUpdateReq(org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.ModuleUpdateReq) ManagedChannel(io.grpc.ManagedChannel) Void(org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.Void) Test(org.junit.Test)

Example 4 with ManagedChannel

use of io.grpc.ManagedChannel in project sonarlint-core by SonarSource.

the class ConnectedDaemonTest method testError.

@Test
public void testError() throws IOException {
    daemon.run();
    daemon.waitReady();
    ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 8050).usePlaintext(true).build();
    ConnectedSonarLintBlockingStub sonarlint = ConnectedSonarLintGrpc.newBlockingStub(channel);
    sonarlint.start(createConnectedConfig());
    // Analyze without update -> error
    Iterator<Issue> analyze = sonarlint.analyze(createAnalysisConfig(PROJECT_KEY_JAVA));
    exception.expectMessage("Please update server 'storage'");
    exception.expect(StatusRuntimeException.class);
    analyze.hasNext();
    sonarlint.shutdown(null);
}
Also used : ConnectedSonarLintBlockingStub(org.sonarsource.sonarlint.daemon.proto.ConnectedSonarLintGrpc.ConnectedSonarLintBlockingStub) Issue(org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.Issue) ManagedChannel(io.grpc.ManagedChannel) Test(org.junit.Test)

Example 5 with ManagedChannel

use of io.grpc.ManagedChannel in project sonarlint-core by SonarSource.

the class ConnectedDaemonTest method testPort.

@Test
public void testPort() throws IOException {
    daemon.run("--port", "8051");
    daemon.waitReady();
    ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 8051).usePlaintext(true).build();
    ConnectedSonarLintBlockingStub sonarlint = ConnectedSonarLintGrpc.newBlockingStub(channel);
    sonarlint.start(createConnectedConfig());
}
Also used : ConnectedSonarLintBlockingStub(org.sonarsource.sonarlint.daemon.proto.ConnectedSonarLintGrpc.ConnectedSonarLintBlockingStub) ManagedChannel(io.grpc.ManagedChannel) Test(org.junit.Test)

Aggregations

ManagedChannel (io.grpc.ManagedChannel)159 Test (org.junit.Test)91 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