mirror of https://github.com/grpc/grpc-java.git
core: stop "testing" from depending on "core"'s test. (#2652)
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". Resolves #2651
This commit is contained in:
parent
7d85e73b23
commit
f088b81fc8
|
|
@ -36,8 +36,6 @@ import static org.mockito.Mockito.doAnswer;
|
|||
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 @@ import javax.annotation.Nullable;
|
|||
/**
|
||||
* Common utility methods for tests.
|
||||
*/
|
||||
public final class TestUtils {
|
||||
final class TestUtils {
|
||||
|
||||
static class MockClientTransportInfo {
|
||||
/**
|
||||
|
|
@ -113,22 +111,6 @@ public final class TestUtils {
|
|||
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() {
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ public abstract class AbstractInteropTest {
|
|||
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) {
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ public class AutoWindowSizingOnTest extends AbstractInteropTest {
|
|||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ public class Http2NettyLocalChannelTest extends AbstractInteropTest {
|
|||
.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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ public class Http2NettyTest extends AbstractInteropTest {
|
|||
.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);
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ public class Http2OkHttpTest extends AbstractInteropTest {
|
|||
.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")));
|
||||
|
|
|
|||
|
|
@ -190,7 +190,7 @@ public class TransportCompressionTest extends AbstractInteropTest {
|
|||
}
|
||||
})
|
||||
.usePlaintext(true);
|
||||
io.grpc.internal.TestUtils.setStatsContextFactory(builder, getClientStatsFactory());
|
||||
io.grpc.internal.TestingAccessor.setStatsContextFactory(builder, getClientStatsFactory());
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue