Skip to content

Commit

Permalink
address feedback wrt itrop tests. will be fixed up
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiitk committed Sep 3, 2020
1 parent c3793c0 commit 45702db
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 93 deletions.
Expand Up @@ -365,10 +365,10 @@ protected final ServerStreamTracer.Factory createCustomCensusTracerFactory() {
}

/**
* Return {@code true} when custom census module used.
* Override this when custom census module presence is different from {@link #metricsExpected()}
*/
protected boolean customCensusModulePresent() {
return false;
return metricsExpected();
}

/**
Expand Down

This file was deleted.

Expand Up @@ -18,19 +18,23 @@

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;
import org.junit.runner.RunWith;
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
Expand Down
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down
Expand Up @@ -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;
Expand All @@ -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";

Expand All @@ -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);
}
Expand Down
Expand Up @@ -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
Expand All @@ -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
Expand Down
Expand Up @@ -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;
Expand All @@ -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());
Expand All @@ -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 <ReqT, RespT> Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call,
Metadata headers, ServerCallHandler<ReqT, RespT> next) {
Listener<ReqT> 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 <ReqT, RespT> Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call,
Metadata headers, ServerCallHandler<ReqT, RespT> next) {
Listener<ReqT> 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
Expand Down
4 changes: 2 additions & 2 deletions okhttp/src/test/java/io/grpc/okhttp/OkHttpTransportTest.java
Expand Up @@ -53,7 +53,7 @@ public void releaseClientFactory() {
@Override
protected List<? extends InternalServer> newServer(
List<ServerStreamTracer.Factory> streamTracerFactories) {
final NettyServerBuilder builder = NettyServerBuilder
NettyServerBuilder builder = NettyServerBuilder
.forPort(0)
.flowControlWindow(AbstractTransportTest.TEST_FLOW_CONTROL_WINDOW);
InternalNettyServerBuilder.setTransportTracerFactory(builder, fakeClockTransportTracer);
Expand All @@ -63,7 +63,7 @@ protected List<? extends InternalServer> newServer(
@Override
protected List<? extends InternalServer> newServer(
int port, List<ServerStreamTracer.Factory> streamTracerFactories) {
final NettyServerBuilder builder = NettyServerBuilder
NettyServerBuilder builder = NettyServerBuilder
.forAddress(new InetSocketAddress(port))
.flowControlWindow(AbstractTransportTest.TEST_FLOW_CONTROL_WINDOW);
InternalNettyServerBuilder.setTransportTracerFactory(builder, fakeClockTransportTracer);
Expand Down

0 comments on commit 45702db

Please sign in to comment.