|
17 | 17 | package io.grpc.testing.integration; |
18 | 18 |
|
19 | 19 | import static org.junit.Assert.assertEquals; |
| 20 | +import static org.junit.Assert.assertThrows; |
20 | 21 | import static org.junit.Assert.assertTrue; |
21 | 22 |
|
22 | 23 | import com.google.protobuf.ByteString; |
|
37 | 38 | import io.grpc.ServerCall.Listener; |
38 | 39 | import io.grpc.ServerCallHandler; |
39 | 40 | import io.grpc.ServerInterceptor; |
| 41 | +import io.grpc.Status.Code; |
| 42 | +import io.grpc.StatusRuntimeException; |
40 | 43 | import io.grpc.internal.GrpcUtil; |
41 | 44 | import io.grpc.netty.InternalNettyChannelBuilder; |
42 | 45 | import io.grpc.netty.InternalNettyServerBuilder; |
|
53 | 56 | import java.io.OutputStream; |
54 | 57 | import org.junit.Before; |
55 | 58 | import org.junit.BeforeClass; |
| 59 | +import org.junit.Ignore; |
| 60 | +import org.junit.Rule; |
56 | 61 | import org.junit.Test; |
| 62 | +import org.junit.rules.TestName; |
57 | 63 | import org.junit.runner.RunWith; |
58 | 64 | import org.junit.runners.JUnit4; |
59 | 65 |
|
@@ -84,10 +90,16 @@ public static void registerCompressors() { |
84 | 90 | compressors.register(Codec.Identity.NONE); |
85 | 91 | } |
86 | 92 |
|
| 93 | + @Rule |
| 94 | + public final TestName currentTest = new TestName(); |
| 95 | + |
87 | 96 | @Override |
88 | 97 | protected ServerBuilder<?> getServerBuilder() { |
89 | 98 | NettyServerBuilder builder = NettyServerBuilder.forPort(0, InsecureServerCredentials.create()) |
90 | | - .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE) |
| 99 | + .maxInboundMessageSize( |
| 100 | + DECOMPRESSED_MESSAGE_TOO_LONG_METHOD_NAME.equals(currentTest.getMethodName()) |
| 101 | + ? 1000 |
| 102 | + : AbstractInteropTest.MAX_MESSAGE_SIZE) |
91 | 103 | .compressorRegistry(compressors) |
92 | 104 | .decompressorRegistry(decompressors) |
93 | 105 | .intercept(new ServerInterceptor() { |
@@ -126,6 +138,22 @@ public void compresses() { |
126 | 138 | assertTrue(FZIPPER.anyWritten); |
127 | 139 | } |
128 | 140 |
|
| 141 | + private static final String DECOMPRESSED_MESSAGE_TOO_LONG_METHOD_NAME = "decompressedMessageTooLong"; |
| 142 | + |
| 143 | + @Test |
| 144 | + @Ignore("for PR #12360") |
| 145 | + public void decompressedMessageTooLong() { |
| 146 | + assertEquals(DECOMPRESSED_MESSAGE_TOO_LONG_METHOD_NAME, currentTest.getMethodName()); |
| 147 | + final SimpleRequest bigRequest = SimpleRequest.newBuilder() |
| 148 | + .setPayload(Payload.newBuilder().setBody(ByteString.copyFrom(new byte[10_000]))) |
| 149 | + .build(); |
| 150 | + StatusRuntimeException e = assertThrows(StatusRuntimeException.class, |
| 151 | + () -> blockingStub.withCompression("gzip").unaryCall(bigRequest)); |
| 152 | + assertCodeEquals(Code.RESOURCE_EXHAUSTED, e.getStatus()); |
| 153 | + assertEquals("Decompressed gRPC message exceeds maximum size 1000", |
| 154 | + e.getStatus().getDescription()); |
| 155 | + } |
| 156 | + |
129 | 157 | @Override |
130 | 158 | protected NettyChannelBuilder createChannelBuilder() { |
131 | 159 | NettyChannelBuilder builder = NettyChannelBuilder.forAddress(getListenAddress()) |
|
0 commit comments