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.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import com.google.instrumentation.stats.StatsContextFactory;
|
|
||||||
|
|
||||||
import io.grpc.CallOptions;
|
import io.grpc.CallOptions;
|
||||||
import io.grpc.Metadata;
|
import io.grpc.Metadata;
|
||||||
import io.grpc.MethodDescriptor;
|
import io.grpc.MethodDescriptor;
|
||||||
|
|
@ -53,7 +51,7 @@ import javax.annotation.Nullable;
|
||||||
/**
|
/**
|
||||||
* Common utility methods for tests.
|
* Common utility methods for tests.
|
||||||
*/
|
*/
|
||||||
public final class TestUtils {
|
final class TestUtils {
|
||||||
|
|
||||||
static class MockClientTransportInfo {
|
static class MockClientTransportInfo {
|
||||||
/**
|
/**
|
||||||
|
|
@ -113,22 +111,6 @@ public final class TestUtils {
|
||||||
return captor;
|
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() {
|
private TestUtils() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,10 +16,6 @@ dependencies {
|
||||||
libraries.mockito,
|
libraries.mockito,
|
||||||
libraries.netty_tcnative,
|
libraries.netty_tcnative,
|
||||||
libraries.oauth_client
|
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 {
|
test {
|
||||||
|
|
|
||||||
|
|
@ -152,7 +152,7 @@ public abstract class AbstractInteropTest {
|
||||||
builder.addService(ServerInterceptors.intercept(
|
builder.addService(ServerInterceptors.intercept(
|
||||||
new TestServiceImpl(testServiceExecutor),
|
new TestServiceImpl(testServiceExecutor),
|
||||||
allInterceptors));
|
allInterceptors));
|
||||||
io.grpc.internal.TestUtils.setStatsContextFactory(builder, serverStatsFactory);
|
io.grpc.internal.TestingAccessor.setStatsContextFactory(builder, serverStatsFactory);
|
||||||
try {
|
try {
|
||||||
server = builder.build().start();
|
server = builder.build().start();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ public class AutoWindowSizingOnTest extends AbstractInteropTest {
|
||||||
NettyChannelBuilder builder = NettyChannelBuilder.forAddress("localhost", getPort())
|
NettyChannelBuilder builder = NettyChannelBuilder.forAddress("localhost", getPort())
|
||||||
.negotiationType(NegotiationType.PLAINTEXT)
|
.negotiationType(NegotiationType.PLAINTEXT)
|
||||||
.maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE);
|
.maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE);
|
||||||
io.grpc.internal.TestUtils.setStatsContextFactory(builder, getClientStatsFactory());
|
io.grpc.internal.TestingAccessor.setStatsContextFactory(builder, getClientStatsFactory());
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ public class Http2NettyLocalChannelTest extends AbstractInteropTest {
|
||||||
.channelType(LocalChannel.class)
|
.channelType(LocalChannel.class)
|
||||||
.flowControlWindow(65 * 1024)
|
.flowControlWindow(65 * 1024)
|
||||||
.maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE);
|
.maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE);
|
||||||
io.grpc.internal.TestUtils.setStatsContextFactory(builder, getClientStatsFactory());
|
io.grpc.internal.TestingAccessor.setStatsContextFactory(builder, getClientStatsFactory());
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ public class Http2NettyTest extends AbstractInteropTest {
|
||||||
.ciphers(TestUtils.preferredTestCiphers(), SupportedCipherSuiteFilter.INSTANCE)
|
.ciphers(TestUtils.preferredTestCiphers(), SupportedCipherSuiteFilter.INSTANCE)
|
||||||
.sslProvider(SslProvider.OPENSSL)
|
.sslProvider(SslProvider.OPENSSL)
|
||||||
.build());
|
.build());
|
||||||
io.grpc.internal.TestUtils.setStatsContextFactory(builder, getClientStatsFactory());
|
io.grpc.internal.TestingAccessor.setStatsContextFactory(builder, getClientStatsFactory());
|
||||||
return builder.build();
|
return builder.build();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
throw new RuntimeException(ex);
|
throw new RuntimeException(ex);
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,7 @@ public class Http2OkHttpTest extends AbstractInteropTest {
|
||||||
.build())
|
.build())
|
||||||
.overrideAuthority(GrpcUtil.authorityFromHostAndPort(
|
.overrideAuthority(GrpcUtil.authorityFromHostAndPort(
|
||||||
TestUtils.TEST_SERVER_HOST, getPort()));
|
TestUtils.TEST_SERVER_HOST, getPort()));
|
||||||
io.grpc.internal.TestUtils.setStatsContextFactory(builder, getClientStatsFactory());
|
io.grpc.internal.TestingAccessor.setStatsContextFactory(builder, getClientStatsFactory());
|
||||||
try {
|
try {
|
||||||
builder.sslSocketFactory(TestUtils.newSslSocketFactoryForCa(Platform.get().getProvider(),
|
builder.sslSocketFactory(TestUtils.newSslSocketFactoryForCa(Platform.get().getProvider(),
|
||||||
TestUtils.loadCert("ca.pem")));
|
TestUtils.loadCert("ca.pem")));
|
||||||
|
|
|
||||||
|
|
@ -190,7 +190,7 @@ public class TransportCompressionTest extends AbstractInteropTest {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.usePlaintext(true);
|
.usePlaintext(true);
|
||||||
io.grpc.internal.TestUtils.setStatsContextFactory(builder, getClientStatsFactory());
|
io.grpc.internal.TestingAccessor.setStatsContextFactory(builder, getClientStatsFactory());
|
||||||
return builder.build();
|
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