Explain test value for flow control window

This commit is contained in:
Sergii Tkachenko 2020-09-02 14:11:34 -04:00 committed by Sergii Tkachenko
parent e335cb3618
commit c29ad76dae
9 changed files with 25 additions and 12 deletions

View File

@ -89,6 +89,12 @@ import org.mockito.InOrder;
/** Standard unit tests for {@link ClientTransport}s and {@link ServerTransport}s. */ /** Standard unit tests for {@link ClientTransport}s and {@link ServerTransport}s. */
@RunWith(JUnit4.class) @RunWith(JUnit4.class)
public abstract class AbstractTransportTest { public abstract class AbstractTransportTest {
/**
* Use a small flow control to help detect flow control bugs. Don't use 64KiB to test
* SETTINGS/WINDOW_UPDATE exchange.
*/
public static final int TEST_FLOW_CONTROL_WINDOW = 65 * 1024;
private static final int TIMEOUT_MS = 5000; private static final int TIMEOUT_MS = 5000;
private static final Attributes.Key<String> ADDITIONAL_TRANSPORT_ATTR_KEY = private static final Attributes.Key<String> ADDITIONAL_TRANSPORT_ATTR_KEY =

View File

@ -134,7 +134,8 @@ public final class NettyClientInteropServlet extends HttpServlet {
ManagedChannelBuilder.forTarget(INTEROP_TEST_ADDRESS) ManagedChannelBuilder.forTarget(INTEROP_TEST_ADDRESS)
.maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE); .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE);
assertTrue(builder instanceof NettyChannelBuilder); assertTrue(builder instanceof NettyChannelBuilder);
((NettyChannelBuilder) builder).flowControlWindow(65 * 1024); ((NettyChannelBuilder) builder)
.flowControlWindow(AbstractInteropTest.TEST_FLOW_CONTROL_WINDOW);
return builder; return builder;
} }

View File

@ -148,6 +148,12 @@ public abstract class AbstractInteropTest {
/** Must be at least {@link #unaryPayloadLength()}, plus some to account for encoding overhead. */ /** Must be at least {@link #unaryPayloadLength()}, plus some to account for encoding overhead. */
public static final int MAX_MESSAGE_SIZE = 16 * 1024 * 1024; public static final int MAX_MESSAGE_SIZE = 16 * 1024 * 1024;
/**
* Use a small flow control to help detect flow control bugs. Don't use 64KiB to test
* SETTINGS/WINDOW_UPDATE exchange.
*/
public static final int TEST_FLOW_CONTROL_WINDOW = 65 * 1024;
private static final FakeTagger tagger = new FakeTagger(); private static final FakeTagger tagger = new FakeTagger();
private static final FakeTagContextBinarySerializer tagContextBinarySerializer = private static final FakeTagContextBinarySerializer tagContextBinarySerializer =
new FakeTagContextBinarySerializer(); new FakeTagContextBinarySerializer();

View File

@ -416,7 +416,7 @@ public class TestServiceClient {
} }
NettyChannelBuilder nettyBuilder = NettyChannelBuilder nettyBuilder =
NettyChannelBuilder.forAddress(serverHost, serverPort) NettyChannelBuilder.forAddress(serverHost, serverPort)
.flowControlWindow(65 * 1024) .flowControlWindow(AbstractInteropTest.TEST_FLOW_CONTROL_WINDOW)
.negotiationType(useTls ? NegotiationType.TLS : .negotiationType(useTls ? NegotiationType.TLS :
(useH2cUpgrade ? NegotiationType.PLAINTEXT_UPGRADE : NegotiationType.PLAINTEXT)) (useH2cUpgrade ? NegotiationType.PLAINTEXT_UPGRADE : NegotiationType.PLAINTEXT))
.sslContext(sslContext); .sslContext(sslContext);

View File

@ -41,7 +41,7 @@ public class Http2NettyLocalChannelTest extends AbstractInteropTest {
protected AbstractServerImplBuilder<?> getServerBuilder() { protected AbstractServerImplBuilder<?> getServerBuilder() {
return NettyServerBuilder return NettyServerBuilder
.forAddress(new LocalAddress("in-process-1")) .forAddress(new LocalAddress("in-process-1"))
.flowControlWindow(65 * 1024) .flowControlWindow(AbstractInteropTest.TEST_FLOW_CONTROL_WINDOW)
.maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE) .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE)
.channelType(LocalServerChannel.class) .channelType(LocalServerChannel.class)
.workerEventLoopGroup(eventLoopGroup) .workerEventLoopGroup(eventLoopGroup)
@ -55,7 +55,7 @@ public class Http2NettyLocalChannelTest extends AbstractInteropTest {
.negotiationType(NegotiationType.PLAINTEXT) .negotiationType(NegotiationType.PLAINTEXT)
.channelType(LocalChannel.class) .channelType(LocalChannel.class)
.eventLoopGroup(eventLoopGroup) .eventLoopGroup(eventLoopGroup)
.flowControlWindow(65 * 1024) .flowControlWindow(AbstractInteropTest.TEST_FLOW_CONTROL_WINDOW)
.maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE); .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE);
// Disable the default census stats interceptor, use testing interceptor instead. // Disable the default census stats interceptor, use testing interceptor instead.
InternalNettyChannelBuilder.setStatsEnabled(builder, false); InternalNettyChannelBuilder.setStatsEnabled(builder, false);

View File

@ -45,7 +45,7 @@ public class Http2NettyTest extends AbstractInteropTest {
// Starts the server with HTTPS. // Starts the server with HTTPS.
try { try {
return NettyServerBuilder.forPort(0) return NettyServerBuilder.forPort(0)
.flowControlWindow(65 * 1024) .flowControlWindow(AbstractInteropTest.TEST_FLOW_CONTROL_WINDOW)
.maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE) .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE)
.sslContext(GrpcSslContexts .sslContext(GrpcSslContexts
.forServer(TestUtils.loadCert("server1.pem"), TestUtils.loadCert("server1.key")) .forServer(TestUtils.loadCert("server1.pem"), TestUtils.loadCert("server1.key"))
@ -63,7 +63,7 @@ public class Http2NettyTest extends AbstractInteropTest {
try { try {
NettyChannelBuilder builder = NettyChannelBuilder NettyChannelBuilder builder = NettyChannelBuilder
.forAddress(TestUtils.testServerAddress((InetSocketAddress) getListenAddress())) .forAddress(TestUtils.testServerAddress((InetSocketAddress) getListenAddress()))
.flowControlWindow(65 * 1024) .flowControlWindow(AbstractInteropTest.TEST_FLOW_CONTROL_WINDOW)
.maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE) .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE)
.sslContext(GrpcSslContexts .sslContext(GrpcSslContexts
.forClient() .forClient()

View File

@ -78,7 +78,7 @@ public class Http2OkHttpTest extends AbstractInteropTest {
GrpcSslContexts.configure(contextBuilder, sslProvider); GrpcSslContexts.configure(contextBuilder, sslProvider);
contextBuilder.ciphers(TestUtils.preferredTestCiphers(), SupportedCipherSuiteFilter.INSTANCE); contextBuilder.ciphers(TestUtils.preferredTestCiphers(), SupportedCipherSuiteFilter.INSTANCE);
return NettyServerBuilder.forPort(0) return NettyServerBuilder.forPort(0)
.flowControlWindow(65 * 1024) .flowControlWindow(AbstractInteropTest.TEST_FLOW_CONTROL_WINDOW)
.maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE) .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE)
.sslContext(contextBuilder.build()); .sslContext(contextBuilder.build());
} catch (IOException ex) { } catch (IOException ex) {

View File

@ -47,7 +47,7 @@ public class NettyTransportTest extends AbstractTransportTest {
private final ClientTransportFactory clientFactory = NettyChannelBuilder private final ClientTransportFactory clientFactory = NettyChannelBuilder
// Although specified here, address is ignored because we never call build. // Although specified here, address is ignored because we never call build.
.forAddress("localhost", 0) .forAddress("localhost", 0)
.flowControlWindow(65 * 1024) .flowControlWindow(AbstractTransportTest.TEST_FLOW_CONTROL_WINDOW)
.negotiationType(NegotiationType.PLAINTEXT) .negotiationType(NegotiationType.PLAINTEXT)
.setTransportTracerFactory(fakeClockTransportTracer) .setTransportTracerFactory(fakeClockTransportTracer)
.buildTransportFactory(); .buildTransportFactory();
@ -67,7 +67,7 @@ public class NettyTransportTest extends AbstractTransportTest {
List<ServerStreamTracer.Factory> streamTracerFactories) { List<ServerStreamTracer.Factory> streamTracerFactories) {
return NettyServerBuilder return NettyServerBuilder
.forAddress(new InetSocketAddress("localhost", 0)) .forAddress(new InetSocketAddress("localhost", 0))
.flowControlWindow(65 * 1024) .flowControlWindow(AbstractTransportTest.TEST_FLOW_CONTROL_WINDOW)
.setTransportTracerFactory(fakeClockTransportTracer) .setTransportTracerFactory(fakeClockTransportTracer)
.buildTransportServers(streamTracerFactories); .buildTransportServers(streamTracerFactories);
} }
@ -77,7 +77,7 @@ public class NettyTransportTest extends AbstractTransportTest {
int port, List<ServerStreamTracer.Factory> streamTracerFactories) { int port, List<ServerStreamTracer.Factory> streamTracerFactories) {
return NettyServerBuilder return NettyServerBuilder
.forAddress(new InetSocketAddress("localhost", port)) .forAddress(new InetSocketAddress("localhost", port))
.flowControlWindow(65 * 1024) .flowControlWindow(AbstractTransportTest.TEST_FLOW_CONTROL_WINDOW)
.setTransportTracerFactory(fakeClockTransportTracer) .setTransportTracerFactory(fakeClockTransportTracer)
.buildTransportServers(streamTracerFactories); .buildTransportServers(streamTracerFactories);
} }

View File

@ -56,7 +56,7 @@ public class OkHttpTransportTest extends AbstractTransportTest {
return AccessProtectedHack.serverBuilderBuildTransportServer( return AccessProtectedHack.serverBuilderBuildTransportServer(
NettyServerBuilder NettyServerBuilder
.forPort(0) .forPort(0)
.flowControlWindow(65 * 1024), .flowControlWindow(AbstractTransportTest.TEST_FLOW_CONTROL_WINDOW),
streamTracerFactories, streamTracerFactories,
fakeClockTransportTracer); fakeClockTransportTracer);
} }
@ -67,7 +67,7 @@ public class OkHttpTransportTest extends AbstractTransportTest {
return AccessProtectedHack.serverBuilderBuildTransportServer( return AccessProtectedHack.serverBuilderBuildTransportServer(
NettyServerBuilder NettyServerBuilder
.forAddress(new InetSocketAddress(port)) .forAddress(new InetSocketAddress(port))
.flowControlWindow(65 * 1024), .flowControlWindow(AbstractTransportTest.TEST_FLOW_CONTROL_WINDOW),
streamTracerFactories, streamTracerFactories,
fakeClockTransportTracer); fakeClockTransportTracer);
} }