@Override protected ManagedChannel createChannel() { try { final int port = server.getPort(); return OkHttpChannelBuilder .forAddress("localhost", port) .negotiationType(NegotiationType.TLS) .maxInboundMessageSize(16 * 1024 * 1024) .connectionSpec(ConnectionSpec.MODERN_TLS) .overrideAuthority("example.com:" + port) .sslSocketFactory(TestUtils.newSslSocketFactoryForCa( Platform.get().getProvider(), ssc.certificate())) .build(); } catch (Exception ex) { throw new RuntimeException(ex); } }
@Override protected ManagedChannel createChannel() { assertEquals( "jdk7 required", "1.7", System.getProperty("java.specification.version")); assertEquals( "Can not run in dev servers because they lack org.conscrypt.OpenSSLProvider support", "Production", System.getProperty("com.google.appengine.runtime.environment")); ManagedChannelBuilder<?> builder = ManagedChannelBuilder.forTarget(INTEROP_TEST_ADDRESS) .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE); assertTrue(builder instanceof OkHttpChannelBuilder); return builder.build(); }
public static ManagedChannel build(String host, int port, @Nullable String serverHostOverride, boolean useTls, @Nullable InputStream testCa, @Nullable String androidSocketFactoryTls) { ManagedChannelBuilder<?> channelBuilder = ManagedChannelBuilder.forAddress(host, port) .maxInboundMessageSize(16 * 1024 * 1024); if (serverHostOverride != null) { // Force the hostname to match the cert the server uses. channelBuilder.overrideAuthority(serverHostOverride); } if (useTls) { try { SSLSocketFactory factory; if (androidSocketFactoryTls != null) { factory = getSslCertificateSocketFactory(testCa, androidSocketFactoryTls); } else { factory = getSslSocketFactory(testCa); } ((OkHttpChannelBuilder) channelBuilder).negotiationType(NegotiationType.TLS); ((OkHttpChannelBuilder) channelBuilder).sslSocketFactory(factory); } catch (Exception e) { throw new RuntimeException(e); } } else { channelBuilder.usePlaintext(true); } return channelBuilder.build(); }
private OkHttpChannelBuilder createChannelBuilder() { OkHttpChannelBuilder builder = OkHttpChannelBuilder.forAddress("localhost", getPort()) .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE) .connectionSpec(new ConnectionSpec.Builder(OkHttpChannelBuilder.DEFAULT_CONNECTION_SPEC) .cipherSuites(TestUtils.preferredTestCiphers().toArray(new String[0])) .tlsVersions(ConnectionSpec.MODERN_TLS.tlsVersions().toArray(new TlsVersion[0])) .build()) .overrideAuthority(GrpcUtil.authorityFromHostAndPort( TestUtils.TEST_SERVER_HOST, getPort())); io.grpc.internal.TestingAccessor.setStatsImplementation( builder, createClientCensusStatsModule()); try { builder.sslSocketFactory(TestUtils.newSslSocketFactoryForCa(Platform.get().getProvider(), TestUtils.loadCert("ca.pem"))); } catch (Exception e) { throw new RuntimeException(e); } return builder; }
static ManagedChannel getChannel(String host, int port) { OkHttpChannelBuilder channelBuilder; if (DISABLE_TLS) { channelBuilder = OkHttpChannelBuilder .forAddress(host, port) .usePlaintext(true); } else { channelBuilder = OkHttpChannelBuilder .forAddress(host, port); } return channelBuilder.build(); }
@Setup public void start() throws Exception { setUp(); okhttpChannel = OkHttpChannelBuilder.forAddress("127.0.0.1", port()) .usePlaintext(true) .directExecutor() .build(); githubApiOkhttpClient = GithubServiceGrpc.newBlockingStub(okhttpChannel); githubApiOkhttpFutureClient = GithubServiceGrpc.newFutureStub(okhttpChannel); }
private void runTest() throws Exception { try { controlChannel = NettyChannelBuilder.forAddress("127.0.0.1", serverControlPort) .negotiationType(NegotiationType.PLAINTEXT).build(); controlStub = ReconnectServiceGrpc.newBlockingStub(controlChannel); if (useOkhttp) { retryChannel = OkHttpChannelBuilder.forAddress("127.0.0.1", serverRetryPort) .negotiationType(io.grpc.okhttp.NegotiationType.TLS).build(); } else { retryChannel = NettyChannelBuilder.forAddress("127.0.0.1", serverRetryPort) .negotiationType(NegotiationType.TLS).build(); } retryStub = ReconnectServiceGrpc.newBlockingStub(retryChannel); controlStub.start(Empty.getDefaultInstance()); long startTimeStamp = System.currentTimeMillis(); while ((System.currentTimeMillis() - startTimeStamp) < TEST_TIME_MS) { try { retryStub.start(Empty.getDefaultInstance()); } catch (StatusRuntimeException expected) { // Make CheckStyle happy. } Thread.sleep(50); } ReconnectInfo info = controlStub.stop(Empty.getDefaultInstance()); assertTrue(info.getPassed()); } finally { controlChannel.shutdownNow(); retryChannel.shutdownNow(); } }
private static OkHttpChannelBuilder newOkhttpClientChannel( SocketAddress address, boolean tls, boolean testca, @Nullable String authorityOverride) { InetSocketAddress addr = (InetSocketAddress) address; OkHttpChannelBuilder builder = OkHttpChannelBuilder.forAddress(addr.getHostName(), addr.getPort()); if (tls) { builder.negotiationType(io.grpc.okhttp.NegotiationType.TLS); SSLSocketFactory factory; if (testca) { builder.overrideAuthority( GrpcUtil.authorityFromHostAndPort(authorityOverride, addr.getPort())); try { factory = TestUtils.newSslSocketFactoryForCa( Platform.get().getProvider(), TestUtils.loadCert("ca.pem")); } catch (Exception e) { throw new RuntimeException(e); } } else { factory = (SSLSocketFactory) SSLSocketFactory.getDefault(); } builder.sslSocketFactory(factory); } else { builder.negotiationType(io.grpc.okhttp.NegotiationType.PLAINTEXT); } return builder; }
@Override protected ManagedChannel createChannel() { AbstractManagedChannelImplBuilder<?> builder; if (!useOkHttp) { SslContext sslContext = null; if (useTestCa) { try { sslContext = GrpcSslContexts.forClient().trustManager( TestUtils.loadCert("ca.pem")).build(); } catch (Exception ex) { throw new RuntimeException(ex); } } NettyChannelBuilder nettyBuilder = NettyChannelBuilder.forAddress(serverHost, serverPort) .flowControlWindow(65 * 1024) .negotiationType(useTls ? NegotiationType.TLS : NegotiationType.PLAINTEXT) .sslContext(sslContext); if (serverHostOverride != null) { nettyBuilder.overrideAuthority(serverHostOverride); } if (fullStreamDecompression) { nettyBuilder.enableFullStreamDecompression(); } builder = nettyBuilder; } else { OkHttpChannelBuilder okBuilder = OkHttpChannelBuilder.forAddress(serverHost, serverPort); if (serverHostOverride != null) { // Force the hostname to match the cert the server uses. okBuilder.overrideAuthority( GrpcUtil.authorityFromHostAndPort(serverHostOverride, serverPort)); } if (useTls) { try { SSLSocketFactory factory = useTestCa ? TestUtils.newSslSocketFactoryForCa(Platform.get().getProvider(), TestUtils.loadCert("ca.pem")) : (SSLSocketFactory) SSLSocketFactory.getDefault(); okBuilder.sslSocketFactory(factory); } catch (Exception e) { throw new RuntimeException(e); } } else { okBuilder.usePlaintext(true); } if (fullStreamDecompression) { okBuilder.enableFullStreamDecompression(); } builder = okBuilder; } io.grpc.internal.TestingAccessor.setStatsImplementation( builder, createClientCensusStatsModule()); return builder.build(); }