Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: stop "testing" from depending on "core"'s test. #2652

Merged
merged 1 commit into from
Jan 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions core/src/test/java/io/grpc/internal/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -53,7 +51,7 @@
/**
* Common utility methods for tests.
*/
public final class TestUtils {
final class TestUtils {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea!


static class MockClientTransportInfo {
/**
Expand Down Expand Up @@ -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() {
}
}
4 changes: 0 additions & 4 deletions interop-testing/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
58 changes: 58 additions & 0 deletions testing/src/main/java/io/grpc/internal/TestingAccessor.java
Original file line number Diff line number Diff line change
@@ -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() {
}
}