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 060629b52b06..7b8f8d51e82e 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 @@ -365,10 +365,10 @@ protected final ServerStreamTracer.Factory createCustomCensusTracerFactory() { } /** - * Return {@code true} when custom census module used. + * Override this when census module presence is different from {@link #metricsExpected()} */ protected boolean customCensusModulePresent() { - return false; + return metricsExpected(); } /** diff --git a/interop-testing/src/main/java/io/grpc/testing/integration/AbstractNettyInteropTest.java b/interop-testing/src/main/java/io/grpc/testing/integration/AbstractNettyInteropTest.java deleted file mode 100644 index c8b176a0cec0..000000000000 --- a/interop-testing/src/main/java/io/grpc/testing/integration/AbstractNettyInteropTest.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2020 The gRPC Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.grpc.testing.integration; - -import io.grpc.netty.InternalNettyServerBuilder; -import io.grpc.netty.NettyServerBuilder; - -public abstract class AbstractNettyInteropTest extends AbstractInteropTest { - protected NettyServerBuilder withCustomCensusModule(NettyServerBuilder builder) { - InternalNettyServerBuilder.setStatsEnabled(builder, false); - builder.addStreamTracerFactory(createCustomCensusTracerFactory()); - return builder; - } - - @Override - protected boolean customCensusModulePresent() { - return true; - } -} 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 126cbfc2ef81..05fd970e3e0f 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 @@ -18,6 +18,7 @@ import io.grpc.ServerBuilder; import io.grpc.netty.InternalNettyChannelBuilder; +import io.grpc.netty.InternalNettyServerBuilder; import io.grpc.netty.NegotiationType; import io.grpc.netty.NettyChannelBuilder; import io.grpc.netty.NettyServerBuilder; @@ -25,12 +26,15 @@ import org.junit.runners.JUnit4; @RunWith(JUnit4.class) -public class AutoWindowSizingOnTest extends AbstractNettyInteropTest { +public class AutoWindowSizingOnTest extends AbstractInteropTest { @Override protected ServerBuilder getServerBuilder() { - return withCustomCensusModule( - NettyServerBuilder.forPort(0).maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE)); + NettyServerBuilder builder = NettyServerBuilder.forPort(0) + .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE); + // Disable the default census stats tracer, use testing tracer instead. + InternalNettyServerBuilder.setStatsEnabled(builder, false); + return builder.addStreamTracerFactory(createCustomCensusTracerFactory()); } @Override 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 2bbdcecab6ef..778e8bdf97cd 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 @@ -18,6 +18,7 @@ import io.grpc.ServerBuilder; import io.grpc.netty.InternalNettyChannelBuilder; +import io.grpc.netty.InternalNettyServerBuilder; import io.grpc.netty.NegotiationType; import io.grpc.netty.NettyChannelBuilder; import io.grpc.netty.NettyServerBuilder; @@ -33,20 +34,22 @@ * Run transport tests over the Netty in-process channel. */ @RunWith(JUnit4.class) -public class Http2NettyLocalChannelTest extends AbstractNettyInteropTest { +public class Http2NettyLocalChannelTest extends AbstractInteropTest { private DefaultEventLoopGroup eventLoopGroup = new DefaultEventLoopGroup(); @Override protected ServerBuilder getServerBuilder() { - return withCustomCensusModule( - NettyServerBuilder - .forAddress(new LocalAddress("in-process-1")) - .flowControlWindow(AbstractInteropTest.TEST_FLOW_CONTROL_WINDOW) - .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE) - .channelType(LocalServerChannel.class) - .workerEventLoopGroup(eventLoopGroup) - .bossEventLoopGroup(eventLoopGroup)); + NettyServerBuilder builder = NettyServerBuilder + .forAddress(new LocalAddress("in-process-1")) + .flowControlWindow(AbstractInteropTest.TEST_FLOW_CONTROL_WINDOW) + .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE) + .channelType(LocalServerChannel.class) + .workerEventLoopGroup(eventLoopGroup) + .bossEventLoopGroup(eventLoopGroup); + // Disable the default census stats tracer, use testing tracer instead. + InternalNettyServerBuilder.setStatsEnabled(builder, false); + return builder.addStreamTracerFactory(createCustomCensusTracerFactory()); } @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 4334a616f0a9..0d3910391050 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 @@ -23,6 +23,7 @@ import io.grpc.internal.testing.TestUtils; import io.grpc.netty.GrpcSslContexts; import io.grpc.netty.InternalNettyChannelBuilder; +import io.grpc.netty.InternalNettyServerBuilder; import io.grpc.netty.NettyChannelBuilder; import io.grpc.netty.NettyServerBuilder; import io.netty.handler.ssl.ClientAuth; @@ -38,22 +39,24 @@ * Integration tests for GRPC over HTTP2 using the Netty framework. */ @RunWith(JUnit4.class) -public class Http2NettyTest extends AbstractNettyInteropTest { +public class Http2NettyTest extends AbstractInteropTest { @Override protected ServerBuilder getServerBuilder() { // Starts the server with HTTPS. try { - return withCustomCensusModule( - NettyServerBuilder.forPort(0) - .flowControlWindow(AbstractInteropTest.TEST_FLOW_CONTROL_WINDOW) - .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE) - .sslContext(GrpcSslContexts - .forServer(TestUtils.loadCert("server1.pem"), TestUtils.loadCert("server1.key")) - .clientAuth(ClientAuth.REQUIRE) - .trustManager(TestUtils.loadCert("ca.pem")) - .ciphers(TestUtils.preferredTestCiphers(), SupportedCipherSuiteFilter.INSTANCE) - .build())); + NettyServerBuilder builder = NettyServerBuilder.forPort(0) + .flowControlWindow(AbstractInteropTest.TEST_FLOW_CONTROL_WINDOW) + .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE) + .sslContext(GrpcSslContexts + .forServer(TestUtils.loadCert("server1.pem"), TestUtils.loadCert("server1.key")) + .clientAuth(ClientAuth.REQUIRE) + .trustManager(TestUtils.loadCert("ca.pem")) + .ciphers(TestUtils.preferredTestCiphers(), SupportedCipherSuiteFilter.INSTANCE) + .build()); + // Disable the default census stats tracer, use testing tracer instead. + InternalNettyServerBuilder.setStatsEnabled(builder, false); + return builder.addStreamTracerFactory(createCustomCensusTracerFactory()); } catch (IOException 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 069c7071dd65..612774c7564b 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 @@ -28,6 +28,7 @@ import io.grpc.internal.testing.StreamRecorder; import io.grpc.internal.testing.TestUtils; import io.grpc.netty.GrpcSslContexts; +import io.grpc.netty.InternalNettyServerBuilder; import io.grpc.netty.NettyServerBuilder; import io.grpc.okhttp.InternalOkHttpChannelBuilder; import io.grpc.okhttp.OkHttpChannelBuilder; @@ -52,7 +53,7 @@ * Integration tests for GRPC over Http2 using the OkHttp framework. */ @RunWith(JUnit4.class) -public class Http2OkHttpTest extends AbstractNettyInteropTest { +public class Http2OkHttpTest extends AbstractInteropTest { private static final String BAD_HOSTNAME = "I.am.a.bad.hostname"; @@ -77,11 +78,13 @@ protected ServerBuilder getServerBuilder() { .forServer(TestUtils.loadCert("server1.pem"), TestUtils.loadCert("server1.key")); GrpcSslContexts.configure(contextBuilder, sslProvider); contextBuilder.ciphers(TestUtils.preferredTestCiphers(), SupportedCipherSuiteFilter.INSTANCE); - return withCustomCensusModule( - NettyServerBuilder.forPort(0) - .flowControlWindow(AbstractInteropTest.TEST_FLOW_CONTROL_WINDOW) - .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE) - .sslContext(contextBuilder.build())); + NettyServerBuilder builder = NettyServerBuilder.forPort(0) + .flowControlWindow(AbstractInteropTest.TEST_FLOW_CONTROL_WINDOW) + .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE) + .sslContext(contextBuilder.build()); + // Disable the default census stats tracer, use testing tracer instead. + InternalNettyServerBuilder.setStatsEnabled(builder, false); + return builder.addStreamTracerFactory(createCustomCensusTracerFactory()); } catch (IOException ex) { throw new RuntimeException(ex); } 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 54865b2708e8..1ad63ae85d85 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 @@ -33,18 +33,10 @@ public class InProcessTest extends AbstractInteropTest { @Override protected ServerBuilder getServerBuilder() { // Starts the in-process server. - return withCustomCensusModule(InProcessServerBuilder.forName(SERVER_NAME)); - } - - private InProcessServerBuilder withCustomCensusModule(InProcessServerBuilder builder) { + InProcessServerBuilder builder = InProcessServerBuilder.forName(SERVER_NAME); + // Disable the default census stats tracer, use testing tracer instead. InternalInProcessServerBuilder.setStatsEnabled(builder, false); - builder.addStreamTracerFactory(createCustomCensusTracerFactory()); - return builder; - } - - @Override - protected boolean customCensusModulePresent() { - return true; + return builder.addStreamTracerFactory(createCustomCensusTracerFactory()); } @Override @@ -55,6 +47,12 @@ protected InProcessChannelBuilder createChannelBuilder() { return builder.intercept(createCensusStatsClientInterceptor()); } + @Override + protected boolean customCensusModulePresent() { + // Metrics values are not expected, but custom census module is still used. + return true; + } + @Override protected boolean metricsExpected() { // TODO(zhangkun83): InProcessTransport by-passes framer and deframer, thus message sizes are 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 9e948364a2a2..8d184dd44283 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 @@ -38,6 +38,7 @@ import io.grpc.ServerInterceptor; import io.grpc.internal.GrpcUtil; import io.grpc.netty.InternalNettyChannelBuilder; +import io.grpc.netty.InternalNettyServerBuilder; import io.grpc.netty.NettyChannelBuilder; import io.grpc.netty.NettyServerBuilder; import io.grpc.testing.integration.Messages.BoolValue; @@ -59,7 +60,7 @@ * Tests that compression is turned on. */ @RunWith(JUnit4.class) -public class TransportCompressionTest extends AbstractNettyInteropTest { +public class TransportCompressionTest extends AbstractInteropTest { // Masquerade as identity. private static final Fzip FZIPPER = new Fzip("gzip", new Codec.Gzip()); @@ -84,21 +85,23 @@ public static void registerCompressors() { @Override protected ServerBuilder getServerBuilder() { - return withCustomCensusModule( - NettyServerBuilder.forPort(0) - .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE) - .compressorRegistry(compressors) - .decompressorRegistry(decompressors) - .intercept(new ServerInterceptor() { - @Override - public Listener interceptCall(ServerCall call, - Metadata headers, ServerCallHandler next) { - Listener listener = next.startCall(call, headers); - // TODO(carl-mastrangelo): check that encoding was set. - call.setMessageCompression(true); - return listener; - } - })); + NettyServerBuilder builder = NettyServerBuilder.forPort(0) + .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE) + .compressorRegistry(compressors) + .decompressorRegistry(decompressors) + .intercept(new ServerInterceptor() { + @Override + public Listener interceptCall(ServerCall call, + Metadata headers, ServerCallHandler next) { + Listener listener = next.startCall(call, headers); + // TODO(carl-mastrangelo): check that encoding was set. + call.setMessageCompression(true); + return listener; + } + }); + // Disable the default census stats tracer, use testing tracer instead. + InternalNettyServerBuilder.setStatsEnabled(builder, false); + return builder.addStreamTracerFactory(createCustomCensusTracerFactory()); } @Test diff --git a/okhttp/src/test/java/io/grpc/okhttp/OkHttpTransportTest.java b/okhttp/src/test/java/io/grpc/okhttp/OkHttpTransportTest.java index 7f33fa3100c5..1f812fe06444 100644 --- a/okhttp/src/test/java/io/grpc/okhttp/OkHttpTransportTest.java +++ b/okhttp/src/test/java/io/grpc/okhttp/OkHttpTransportTest.java @@ -53,7 +53,7 @@ public void releaseClientFactory() { @Override protected List newServer( List streamTracerFactories) { - final NettyServerBuilder builder = NettyServerBuilder + NettyServerBuilder builder = NettyServerBuilder .forPort(0) .flowControlWindow(AbstractTransportTest.TEST_FLOW_CONTROL_WINDOW); InternalNettyServerBuilder.setTransportTracerFactory(builder, fakeClockTransportTracer); @@ -63,7 +63,7 @@ protected List newServer( @Override protected List newServer( int port, List streamTracerFactories) { - final NettyServerBuilder builder = NettyServerBuilder + NettyServerBuilder builder = NettyServerBuilder .forAddress(new InetSocketAddress(port)) .flowControlWindow(AbstractTransportTest.TEST_FLOW_CONTROL_WINDOW); InternalNettyServerBuilder.setTransportTracerFactory(builder, fakeClockTransportTracer);