From 53724a689879f3e429853249bcde42b65a072a83 Mon Sep 17 00:00:00 2001 From: Kun Zhang Date: Tue, 24 Jan 2017 17:34:40 -0800 Subject: [PATCH] core: stop "testing" from depending on "core"'s test. Because "core"'s test source already depends on "testing", e.g., `core/src/test/java/io/grpc/internal/ServerCallImplTest.java` uses `testing/src/main/java/io/grpc/internal/testing/StatsTestUtils.java`, which forms a circular dependency. This change moves the StatsContext setter accessors from "core"'s test source to "testing". --- .../test/java/io/grpc/internal/TestUtils.java | 20 +------ interop-testing/build.gradle | 4 -- .../integration/AbstractInteropTest.java | 2 +- .../integration/AutoWindowSizingOnTest.java | 2 +- .../Http2NettyLocalChannelTest.java | 2 +- .../testing/integration/Http2NettyTest.java | 2 +- .../testing/integration/Http2OkHttpTest.java | 2 +- .../integration/TransportCompressionTest.java | 2 +- .../io/grpc/internal/TestingAccessor.java | 58 +++++++++++++++++++ 9 files changed, 65 insertions(+), 29 deletions(-) create mode 100644 testing/src/main/java/io/grpc/internal/TestingAccessor.java diff --git a/core/src/test/java/io/grpc/internal/TestUtils.java b/core/src/test/java/io/grpc/internal/TestUtils.java index 1ca06600206..14588352acf 100644 --- a/core/src/test/java/io/grpc/internal/TestUtils.java +++ b/core/src/test/java/io/grpc/internal/TestUtils.java @@ -36,8 +36,6 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import com.google.instrumentation.stats.StatsContextFactory; - import io.grpc.CallOptions; import io.grpc.Metadata; import io.grpc.MethodDescriptor; @@ -53,7 +51,7 @@ /** * Common utility methods for tests. */ -public final class TestUtils { +final class TestUtils { static class MockClientTransportInfo { /** @@ -113,22 +111,6 @@ public Runnable answer(InvocationOnMock invocation) throws Throwable { return captor; } - /** - * Sets a custom {@link StatsContextFactory} for tests. - */ - public static void setStatsContextFactory( - AbstractManagedChannelImplBuilder builder, StatsContextFactory factory) { - builder.statsContextFactory(factory); - } - - /** - * Sets a custom {@link StatsContextFactory} for tests. - */ - public static void setStatsContextFactory( - AbstractServerImplBuilder builder, StatsContextFactory factory) { - builder.statsContextFactory(factory); - } - private TestUtils() { } } diff --git a/interop-testing/build.gradle b/interop-testing/build.gradle index 5ba106f76b9..29e28355c42 100644 --- a/interop-testing/build.gradle +++ b/interop-testing/build.gradle @@ -16,10 +16,6 @@ dependencies { libraries.mockito, libraries.netty_tcnative, libraries.oauth_client - - // Tests depend on base class defined by core module. - compile project(':grpc-core').sourceSets.test.output - testCompile project(':grpc-core').sourceSets.test.output } test { 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 ab2261692b4..60c8b459910 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 @@ -152,7 +152,7 @@ protected static void startStaticServer( builder.addService(ServerInterceptors.intercept( new TestServiceImpl(testServiceExecutor), allInterceptors)); - io.grpc.internal.TestUtils.setStatsContextFactory(builder, serverStatsFactory); + io.grpc.internal.TestingAccessor.setStatsContextFactory(builder, serverStatsFactory); try { server = builder.build().start(); } catch (IOException ex) { 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 0247651e8ee..ba5e37c639f 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 @@ -64,7 +64,7 @@ protected ManagedChannel createChannel() { NettyChannelBuilder builder = NettyChannelBuilder.forAddress("localhost", getPort()) .negotiationType(NegotiationType.PLAINTEXT) .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE); - io.grpc.internal.TestUtils.setStatsContextFactory(builder, getClientStatsFactory()); + io.grpc.internal.TestingAccessor.setStatsContextFactory(builder, getClientStatsFactory()); return builder.build(); } } 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 423bd6d94bb..cfe93d9255a 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 @@ -75,7 +75,7 @@ protected ManagedChannel createChannel() { .channelType(LocalChannel.class) .flowControlWindow(65 * 1024) .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE); - io.grpc.internal.TestUtils.setStatsContextFactory(builder, getClientStatsFactory()); + io.grpc.internal.TestingAccessor.setStatsContextFactory(builder, getClientStatsFactory()); return builder.build(); } } 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 33df33b3fdd..f30dcf59dfc 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 @@ -92,7 +92,7 @@ protected ManagedChannel createChannel() { .ciphers(TestUtils.preferredTestCiphers(), SupportedCipherSuiteFilter.INSTANCE) .sslProvider(SslProvider.OPENSSL) .build()); - io.grpc.internal.TestUtils.setStatsContextFactory(builder, getClientStatsFactory()); + io.grpc.internal.TestingAccessor.setStatsContextFactory(builder, getClientStatsFactory()); return builder.build(); } 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 d5ed96ccaad..37128759ac6 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 @@ -110,7 +110,7 @@ protected ManagedChannel createChannel() { .build()) .overrideAuthority(GrpcUtil.authorityFromHostAndPort( TestUtils.TEST_SERVER_HOST, getPort())); - io.grpc.internal.TestUtils.setStatsContextFactory(builder, getClientStatsFactory()); + io.grpc.internal.TestingAccessor.setStatsContextFactory(builder, getClientStatsFactory()); try { builder.sslSocketFactory(TestUtils.newSslSocketFactoryForCa(Platform.get().getProvider(), TestUtils.loadCert("ca.pem"))); 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 cf62b67a3f5..8344e09e2b7 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 @@ -190,7 +190,7 @@ public void onHeaders(Metadata headers) { } }) .usePlaintext(true); - io.grpc.internal.TestUtils.setStatsContextFactory(builder, getClientStatsFactory()); + io.grpc.internal.TestingAccessor.setStatsContextFactory(builder, getClientStatsFactory()); return builder.build(); } diff --git a/testing/src/main/java/io/grpc/internal/TestingAccessor.java b/testing/src/main/java/io/grpc/internal/TestingAccessor.java new file mode 100644 index 00000000000..f1d3238d00d --- /dev/null +++ b/testing/src/main/java/io/grpc/internal/TestingAccessor.java @@ -0,0 +1,58 @@ +/* + * Copyright 2017, Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package io.grpc.internal; + +import com.google.instrumentation.stats.StatsContextFactory; + +/** + * Test helper that allows accessing package-private stuff. + */ +public final class TestingAccessor { + /** + * Sets a custom {@link StatsContextFactory} for tests. + */ + public static void setStatsContextFactory( + AbstractManagedChannelImplBuilder builder, StatsContextFactory factory) { + builder.statsContextFactory(factory); + } + + /** + * Sets a custom {@link StatsContextFactory} for tests. + */ + public static void setStatsContextFactory( + AbstractServerImplBuilder builder, StatsContextFactory factory) { + builder.statsContextFactory(factory); + } + + private TestingAccessor() { + } +}