From cb5ceaaaa02774f57579394b486de72921271d6d Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Thu, 9 Jul 2020 09:09:51 -0700 Subject: [PATCH] interop-testing: Add integration test for RetriableStream --- .../grpc/android/integrationtest/InteropTask.java | 6 ++++++ .../integration/NettyClientInteropServlet.java | 5 ++--- .../testing/integration/AbstractInteropTest.java | 14 +++++++++++++- .../grpc/testing/integration/StressTestClient.java | 6 ++++++ .../testing/integration/TestServiceClient.java | 11 ++++++----- .../integration/AutoWindowSizingOnTest.java | 5 ++--- .../integration/Http2NettyLocalChannelTest.java | 5 ++--- .../grpc/testing/integration/Http2NettyTest.java | 5 ++--- .../grpc/testing/integration/Http2OkHttpTest.java | 6 +----- .../io/grpc/testing/integration/InProcessTest.java | 5 ++--- .../integration/TransportCompressionTest.java | 5 ++--- 11 files changed, 44 insertions(+), 29 deletions(-) diff --git a/android-interop-testing/src/main/java/io/grpc/android/integrationtest/InteropTask.java b/android-interop-testing/src/main/java/io/grpc/android/integrationtest/InteropTask.java index a2dae13b59..8beaea3ec9 100644 --- a/android-interop-testing/src/main/java/io/grpc/android/integrationtest/InteropTask.java +++ b/android-interop-testing/src/main/java/io/grpc/android/integrationtest/InteropTask.java @@ -19,6 +19,7 @@ package io.grpc.android.integrationtest; import android.os.AsyncTask; import android.util.Log; import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; import io.grpc.testing.integration.AbstractInteropTest; import java.io.PrintWriter; import java.io.StringWriter; @@ -156,6 +157,11 @@ final class InteropTask extends AsyncTask { return channel; } + @Override + protected ManagedChannelBuilder createChannelBuilder() { + throw new UnsupportedOperationException(); + } + @Override protected boolean metricsExpected() { return false; diff --git a/gae-interop-testing/gae-jdk8/src/main/java/io/grpc/testing/integration/NettyClientInteropServlet.java b/gae-interop-testing/gae-jdk8/src/main/java/io/grpc/testing/integration/NettyClientInteropServlet.java index a6845dc068..b42f9aef31 100644 --- a/gae-interop-testing/gae-jdk8/src/main/java/io/grpc/testing/integration/NettyClientInteropServlet.java +++ b/gae-interop-testing/gae-jdk8/src/main/java/io/grpc/testing/integration/NettyClientInteropServlet.java @@ -19,7 +19,6 @@ package io.grpc.testing.integration; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import io.grpc.netty.NettyChannelBuilder; import java.io.IOException; @@ -126,7 +125,7 @@ public final class NettyClientInteropServlet extends HttpServlet { public static final class Tester extends AbstractInteropTest { @Override - protected ManagedChannel createChannel() { + protected ManagedChannelBuilder createChannelBuilder() { assertEquals( "jdk8 required", "1.8", @@ -136,7 +135,7 @@ public final class NettyClientInteropServlet extends HttpServlet { .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE); assertTrue(builder instanceof NettyChannelBuilder); ((NettyChannelBuilder) builder).flowControlWindow(65 * 1024); - return builder.build(); + return builder; } @Override diff --git a/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java b/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java index b0d656f7de..35cd30583a 100644 --- a/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java +++ b/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java @@ -49,6 +49,7 @@ import io.grpc.ClientStreamTracer; import io.grpc.Context; import io.grpc.Grpc; import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; import io.grpc.Metadata; import io.grpc.MethodDescriptor; import io.grpc.Server; @@ -337,7 +338,11 @@ public abstract class AbstractInteropTest { stopServer(); } - protected abstract ManagedChannel createChannel(); + protected ManagedChannel createChannel() { + return createChannelBuilder().build(); + } + + protected abstract ManagedChannelBuilder createChannelBuilder(); @Nullable protected ClientInterceptor[] getAdditionalInterceptors() { @@ -374,6 +379,13 @@ public abstract class AbstractInteropTest { assertEquals(EMPTY, blockingStub.emptyCall(EMPTY)); } + @Test + public void emptyUnaryWithRetriableStream() throws Exception { + channel.shutdown(); + channel = createChannelBuilder().enableRetry().build(); + assertEquals(EMPTY, TestServiceGrpc.newBlockingStub(channel).emptyCall(EMPTY)); + } + /** Sends a cacheable unary rpc using GET. Requires that the server is behind a caching proxy. */ public void cacheableUnary() { // THIS TEST IS BROKEN. Enabling safe just on the MethodDescriptor does nothing by itself. This diff --git a/interop-testing/src/main/java/io/grpc/testing/integration/StressTestClient.java b/interop-testing/src/main/java/io/grpc/testing/integration/StressTestClient.java index fba45d1e0b..6669d2700d 100644 --- a/interop-testing/src/main/java/io/grpc/testing/integration/StressTestClient.java +++ b/interop-testing/src/main/java/io/grpc/testing/integration/StressTestClient.java @@ -33,6 +33,7 @@ import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; import io.grpc.Server; import io.grpc.ServerBuilder; import io.grpc.Status; @@ -515,6 +516,11 @@ public class StressTestClient { return Worker.this.channel; } + @Override + protected ManagedChannelBuilder createChannelBuilder() { + throw new UnsupportedOperationException(); + } + @Override protected int operationTimeoutMillis() { // Don't enforce a timeout when using the interop tests for the stress test client. diff --git a/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceClient.java b/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceClient.java index 714306f92b..fa7010d19a 100644 --- a/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceClient.java +++ b/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceClient.java @@ -19,6 +19,7 @@ package io.grpc.testing.integration; import com.google.common.annotations.VisibleForTesting; import com.google.common.io.Files; import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; import io.grpc.alts.AltsChannelBuilder; import io.grpc.alts.ComputeEngineChannelBuilder; import io.grpc.alts.GoogleDefaultChannelBuilder; @@ -389,17 +390,17 @@ public class TestServiceClient { private class Tester extends AbstractInteropTest { @Override - protected ManagedChannel createChannel() { + protected ManagedChannelBuilder createChannelBuilder() { if (customCredentialsType != null && customCredentialsType.equals("google_default_credentials")) { - return GoogleDefaultChannelBuilder.forAddress(serverHost, serverPort).build(); + return GoogleDefaultChannelBuilder.forAddress(serverHost, serverPort); } if (customCredentialsType != null && customCredentialsType.equals("compute_engine_channel_creds")) { - return ComputeEngineChannelBuilder.forAddress(serverHost, serverPort).build(); + return ComputeEngineChannelBuilder.forAddress(serverHost, serverPort); } if (useAlts) { - return AltsChannelBuilder.forAddress(serverHost, serverPort).build(); + return AltsChannelBuilder.forAddress(serverHost, serverPort); } AbstractManagedChannelImplBuilder builder; if (!useOkHttp) { @@ -452,7 +453,7 @@ public class TestServiceClient { } // Disable the default census stats interceptor, use testing interceptor instead. io.grpc.internal.TestingAccessor.setStatsEnabled(builder, false); - return builder.intercept(createCensusStatsClientInterceptor()).build(); + return builder.intercept(createCensusStatsClientInterceptor()); } @Override diff --git a/interop-testing/src/test/java/io/grpc/testing/integration/AutoWindowSizingOnTest.java b/interop-testing/src/test/java/io/grpc/testing/integration/AutoWindowSizingOnTest.java index dc19d28688..a68181be83 100644 --- a/interop-testing/src/test/java/io/grpc/testing/integration/AutoWindowSizingOnTest.java +++ b/interop-testing/src/test/java/io/grpc/testing/integration/AutoWindowSizingOnTest.java @@ -16,7 +16,6 @@ package io.grpc.testing.integration; -import io.grpc.ManagedChannel; import io.grpc.internal.AbstractServerImplBuilder; import io.grpc.netty.NegotiationType; import io.grpc.netty.NettyChannelBuilder; @@ -34,13 +33,13 @@ public class AutoWindowSizingOnTest extends AbstractInteropTest { } @Override - protected ManagedChannel createChannel() { + protected NettyChannelBuilder createChannelBuilder() { NettyChannelBuilder builder = NettyChannelBuilder.forAddress(getListenAddress()) .negotiationType(NegotiationType.PLAINTEXT) .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE) .initialFlowControlWindow(NettyChannelBuilder.DEFAULT_FLOW_CONTROL_WINDOW); // Disable the default census stats interceptor, use testing interceptor instead. io.grpc.internal.TestingAccessor.setStatsEnabled(builder, false); - return builder.intercept(createCensusStatsClientInterceptor()).build(); + return builder.intercept(createCensusStatsClientInterceptor()); } } diff --git a/interop-testing/src/test/java/io/grpc/testing/integration/Http2NettyLocalChannelTest.java b/interop-testing/src/test/java/io/grpc/testing/integration/Http2NettyLocalChannelTest.java index d934621f74..5592801755 100644 --- a/interop-testing/src/test/java/io/grpc/testing/integration/Http2NettyLocalChannelTest.java +++ b/interop-testing/src/test/java/io/grpc/testing/integration/Http2NettyLocalChannelTest.java @@ -16,7 +16,6 @@ package io.grpc.testing.integration; -import io.grpc.ManagedChannel; import io.grpc.internal.AbstractServerImplBuilder; import io.grpc.netty.NegotiationType; import io.grpc.netty.NettyChannelBuilder; @@ -49,7 +48,7 @@ public class Http2NettyLocalChannelTest extends AbstractInteropTest { } @Override - protected ManagedChannel createChannel() { + protected NettyChannelBuilder createChannelBuilder() { NettyChannelBuilder builder = NettyChannelBuilder .forAddress(new LocalAddress("in-process-1")) .negotiationType(NegotiationType.PLAINTEXT) @@ -59,7 +58,7 @@ public class Http2NettyLocalChannelTest extends AbstractInteropTest { .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE); // Disable the default census stats interceptor, use testing interceptor instead. io.grpc.internal.TestingAccessor.setStatsEnabled(builder, false); - return builder.intercept(createCensusStatsClientInterceptor()).build(); + return builder.intercept(createCensusStatsClientInterceptor()); } @Override diff --git a/interop-testing/src/test/java/io/grpc/testing/integration/Http2NettyTest.java b/interop-testing/src/test/java/io/grpc/testing/integration/Http2NettyTest.java index 76726d1802..1819b9f300 100644 --- a/interop-testing/src/test/java/io/grpc/testing/integration/Http2NettyTest.java +++ b/interop-testing/src/test/java/io/grpc/testing/integration/Http2NettyTest.java @@ -19,7 +19,6 @@ package io.grpc.testing.integration; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; -import io.grpc.ManagedChannel; import io.grpc.internal.AbstractServerImplBuilder; import io.grpc.internal.testing.TestUtils; import io.grpc.netty.GrpcSslContexts; @@ -59,7 +58,7 @@ public class Http2NettyTest extends AbstractInteropTest { } @Override - protected ManagedChannel createChannel() { + protected NettyChannelBuilder createChannelBuilder() { try { NettyChannelBuilder builder = NettyChannelBuilder .forAddress(TestUtils.testServerAddress((InetSocketAddress) getListenAddress())) @@ -73,7 +72,7 @@ public class Http2NettyTest extends AbstractInteropTest { .build()); // Disable the default census stats interceptor, use testing interceptor instead. io.grpc.internal.TestingAccessor.setStatsEnabled(builder, false); - return builder.intercept(createCensusStatsClientInterceptor()).build(); + return builder.intercept(createCensusStatsClientInterceptor()); } catch (Exception ex) { throw new RuntimeException(ex); } diff --git a/interop-testing/src/test/java/io/grpc/testing/integration/Http2OkHttpTest.java b/interop-testing/src/test/java/io/grpc/testing/integration/Http2OkHttpTest.java index bdb1594b53..041c7cafaa 100644 --- a/interop-testing/src/test/java/io/grpc/testing/integration/Http2OkHttpTest.java +++ b/interop-testing/src/test/java/io/grpc/testing/integration/Http2OkHttpTest.java @@ -86,11 +86,7 @@ public class Http2OkHttpTest extends AbstractInteropTest { } @Override - protected ManagedChannel createChannel() { - return createChannelBuilder().build(); - } - - private OkHttpChannelBuilder createChannelBuilder() { + protected OkHttpChannelBuilder createChannelBuilder() { int port = ((InetSocketAddress) getListenAddress()).getPort(); OkHttpChannelBuilder builder = OkHttpChannelBuilder.forAddress("localhost", port) .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE) diff --git a/interop-testing/src/test/java/io/grpc/testing/integration/InProcessTest.java b/interop-testing/src/test/java/io/grpc/testing/integration/InProcessTest.java index 3592f4b96b..fd403affcf 100644 --- a/interop-testing/src/test/java/io/grpc/testing/integration/InProcessTest.java +++ b/interop-testing/src/test/java/io/grpc/testing/integration/InProcessTest.java @@ -16,7 +16,6 @@ package io.grpc.testing.integration; -import io.grpc.ManagedChannel; import io.grpc.inprocess.InProcessChannelBuilder; import io.grpc.inprocess.InProcessServerBuilder; import io.grpc.internal.AbstractServerImplBuilder; @@ -36,11 +35,11 @@ public class InProcessTest extends AbstractInteropTest { } @Override - protected ManagedChannel createChannel() { + protected InProcessChannelBuilder createChannelBuilder() { InProcessChannelBuilder builder = InProcessChannelBuilder.forName(SERVER_NAME); // Disable the default census stats interceptor, use testing interceptor instead. io.grpc.internal.TestingAccessor.setStatsEnabled(builder, false); - return builder.intercept(createCensusStatsClientInterceptor()).build(); + return builder.intercept(createCensusStatsClientInterceptor()); } @Override diff --git a/interop-testing/src/test/java/io/grpc/testing/integration/TransportCompressionTest.java b/interop-testing/src/test/java/io/grpc/testing/integration/TransportCompressionTest.java index a776a83121..8bc0494b79 100644 --- a/interop-testing/src/test/java/io/grpc/testing/integration/TransportCompressionTest.java +++ b/interop-testing/src/test/java/io/grpc/testing/integration/TransportCompressionTest.java @@ -29,7 +29,6 @@ import io.grpc.CompressorRegistry; import io.grpc.DecompressorRegistry; import io.grpc.ForwardingClientCall; import io.grpc.ForwardingClientCallListener; -import io.grpc.ManagedChannel; import io.grpc.Metadata; import io.grpc.MethodDescriptor; import io.grpc.ServerCall; @@ -122,7 +121,7 @@ public class TransportCompressionTest extends AbstractInteropTest { } @Override - protected ManagedChannel createChannel() { + protected NettyChannelBuilder createChannelBuilder() { NettyChannelBuilder builder = NettyChannelBuilder.forAddress(getListenAddress()) .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE) .decompressorRegistry(decompressors) @@ -167,7 +166,7 @@ public class TransportCompressionTest extends AbstractInteropTest { .usePlaintext(); // Disable the default census stats interceptor, use testing interceptor instead. io.grpc.internal.TestingAccessor.setStatsEnabled(builder, false); - return builder.intercept(createCensusStatsClientInterceptor()).build(); + return builder.intercept(createCensusStatsClientInterceptor()); } /**