(low priority) core,netty,interop-testing: stabilize maxInboundMessageSize API (#4399)

On server side, `maxMessageSize` is deprecated for
`maxInboundMessageSize` to match the channel builder.

Update usages to use new setter.
This commit is contained in:
zpencer 2018-04-27 16:01:16 -07:00 committed by GitHub
parent 1d80febbc0
commit 9ada30b25d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 56 additions and 13 deletions

View File

@ -16,6 +16,7 @@
package io.grpc;
import com.google.common.base.Preconditions;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
@ -293,14 +294,14 @@ public abstract class ManagedChannelBuilder<T extends ManagedChannelBuilder<T>>
* <p>This method is advisory, and implementations may decide to not enforce this. Currently,
* the only known transport to not enforce this is {@code InProcessTransport}.
*
* @param max the maximum number of bytes a single message can be.
* @throws IllegalArgumentException if max is negative.
* @param bytes the maximum number of bytes a single message can be.
* @return this
* @throws IllegalArgumentException if bytes is negative.
* @since 1.1.0
*/
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/2307")
public T maxInboundMessageSize(int max) {
// intentional nop
public T maxInboundMessageSize(int bytes) {
// intentional noop rather than throw, this method is only advisory.
Preconditions.checkArgument(bytes >= 0, "bytes must be >= 0");
return thisT();
}

View File

@ -16,6 +16,7 @@
package io.grpc;
import com.google.common.base.Preconditions;
import java.io.File;
import java.io.InputStream;
import java.util.concurrent.Executor;
@ -203,6 +204,27 @@ public abstract class ServerBuilder<T extends ServerBuilder<T>> {
throw new UnsupportedOperationException();
}
/**
* Sets the maximum message size allowed to be received on the server. If not called,
* defaults to 4 MiB. The default provides protection to servers who haven't considered the
* possibility of receiving large messages while trying to be large enough to not be hit in normal
* usage.
*
* <p>This method is advisory, and implementations may decide to not enforce this. Currently,
* the only known transport to not enforce this is {@code InProcessServer}.
*
* @param bytes the maximum number of bytes a single message can be.
* @return this
* @throws IllegalArgumentException if bytes is negative.
* @throws UnsupportedOperationException if unsupported.
* @since 1.13.0
*/
public T maxInboundMessageSize(int bytes) {
// intentional noop rather than throw, this method is only advisory.
Preconditions.checkArgument(bytes >= 0, "bytes must be >= 0");
return thisT();
}
/**
* Builds a server using the given parameters.
*
@ -213,4 +235,13 @@ public abstract class ServerBuilder<T extends ServerBuilder<T>> {
* @since 1.0.0
*/
public abstract Server build();
/**
* Returns the correctly typed version of the builder.
*/
private T thisT() {
@SuppressWarnings("unchecked")
T thisT = (T) this;
return thisT;
}
}

View File

@ -147,7 +147,7 @@ public class TestServiceServer {
server =
NettyServerBuilder.forPort(port)
.sslContext(sslContext)
.maxMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE)
.maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE)
.addService(
ServerInterceptors.intercept(
new TestServiceImpl(executor), TestServiceImpl.interceptors()))

View File

@ -37,7 +37,8 @@ public class AutoWindowSizingOnTest extends AbstractInteropTest {
@Override
protected AbstractServerImplBuilder<?> getServerBuilder() {
return NettyServerBuilder.forPort(0).maxMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE);
return NettyServerBuilder.forPort(0)
.maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE);
}
@Override

View File

@ -38,7 +38,7 @@ public class Http2NettyLocalChannelTest extends AbstractInteropTest {
return NettyServerBuilder
.forAddress(new LocalAddress("in-process-1"))
.flowControlWindow(65 * 1024)
.maxMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE)
.maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE)
.channelType(LocalServerChannel.class);
}

View File

@ -46,7 +46,7 @@ public class Http2NettyTest extends AbstractInteropTest {
try {
return NettyServerBuilder.forPort(0)
.flowControlWindow(65 * 1024)
.maxMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE)
.maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE)
.sslContext(GrpcSslContexts
.forServer(TestUtils.loadCert("server1.pem"), TestUtils.loadCert("server1.key"))
.clientAuth(ClientAuth.REQUIRE)

View File

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

View File

@ -86,7 +86,7 @@ public class TransportCompressionTest extends AbstractInteropTest {
@Override
protected AbstractServerImplBuilder<?> getServerBuilder() {
return NettyServerBuilder.forPort(0)
.maxMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE)
.maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE)
.compressorRegistry(compressors)
.decompressorRegistry(decompressors)
.intercept(new ServerInterceptor() {

View File

@ -259,10 +259,20 @@ public final class NettyServerBuilder extends AbstractServerImplBuilder<NettySer
* defaults to 4 MiB. The default provides protection to services who haven't considered the
* possibility of receiving large messages while trying to be large enough to not be hit in normal
* usage.
*
* @deprecated Call {@link #maxInboundMessageSize} instead. This method will be removed in a
* future release.
*/
@Deprecated
public NettyServerBuilder maxMessageSize(int maxMessageSize) {
checkArgument(maxMessageSize >= 0, "maxMessageSize must be >= 0");
this.maxMessageSize = maxMessageSize;
return maxInboundMessageSize(maxMessageSize);
}
/** {@inheritDoc} */
@Override
public NettyServerBuilder maxInboundMessageSize(int bytes) {
checkArgument(bytes >= 0, "bytes must be >= 0");
this.maxMessageSize = bytes;
return this;
}