Skip to content

Commit d898a4d

Browse files
committed
Allow client compressed tests without probing (#4240)
1 parent 14003c1 commit d898a4d

File tree

4 files changed

+64
-16
lines changed

4 files changed

+64
-16
lines changed

interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,18 @@ public void largeUnary() throws Exception {
391391
* a message's compression level, so this is primarily intended to run against a gRPC C++ server.
392392
*/
393393
public void clientCompressedUnary() throws Exception {
394+
clientCompressedUnary(true);
395+
}
396+
397+
/**
398+
* Tests client per-message compression for unary calls. The Java API does not support inspecting
399+
* a message's compression level, so this is primarily intended to run against a gRPC C++ server.
400+
*/
401+
public void clientCompressedUnaryNoProbe() throws Exception {
402+
clientCompressedUnary(false);
403+
}
404+
405+
private void clientCompressedUnary(boolean probe) throws Exception {
394406
assumeEnoughMemory();
395407
final SimpleRequest expectCompressedRequest =
396408
SimpleRequest.newBuilder()
@@ -409,15 +421,17 @@ public void clientCompressedUnary() throws Exception {
409421
.setPayload(Payload.newBuilder().setBody(ByteString.copyFrom(new byte[314159])))
410422
.build();
411423

412-
// Send a non-compressed message with expectCompress=true. Servers supporting this test case
413-
// should return INVALID_ARGUMENT.
414-
try {
415-
blockingStub.unaryCall(expectCompressedRequest);
416-
fail("expected INVALID_ARGUMENT");
417-
} catch (StatusRuntimeException e) {
418-
assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatus().getCode());
424+
if (probe) {
425+
// Send a non-compressed message with expectCompress=true. Servers supporting this test case
426+
// should return INVALID_ARGUMENT.
427+
try {
428+
blockingStub.unaryCall(expectCompressedRequest);
429+
fail("expected INVALID_ARGUMENT");
430+
} catch (StatusRuntimeException e) {
431+
assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatus().getCode());
432+
}
433+
assertStatsTrace("grpc.testing.TestService/UnaryCall", Status.Code.INVALID_ARGUMENT);
419434
}
420-
assertStatsTrace("grpc.testing.TestService/UnaryCall", Status.Code.INVALID_ARGUMENT);
421435

422436
assertEquals(
423437
goldenResponse, blockingStub.withCompression("gzip").unaryCall(expectCompressedRequest));
@@ -558,6 +572,19 @@ public void clientStreaming() throws Exception {
558572
* C++ server.
559573
*/
560574
public void clientCompressedStreaming() throws Exception {
575+
clientCompressedStreaming(true);
576+
}
577+
578+
/**
579+
* Tests client per-message compression for streaming calls. The Java API does not support
580+
* inspecting a message's compression level, so this is primarily intended to run against a gRPC
581+
* C++ server.
582+
*/
583+
public void clientCompressedStreamingNoProbe() throws Exception {
584+
clientCompressedStreaming(false);
585+
}
586+
587+
private void clientCompressedStreaming(boolean probe) throws Exception {
561588
final StreamingInputCallRequest expectCompressedRequest =
562589
StreamingInputCallRequest.newBuilder()
563590
.setExpectCompressed(BoolValue.newBuilder().setValue(true))
@@ -575,13 +602,15 @@ public void clientCompressedStreaming() throws Exception {
575602
StreamObserver<StreamingInputCallRequest> requestObserver =
576603
asyncStub.streamingInputCall(responseObserver);
577604

578-
// Send a non-compressed message with expectCompress=true. Servers supporting this test case
579-
// should return INVALID_ARGUMENT.
580-
requestObserver.onNext(expectCompressedRequest);
581-
responseObserver.awaitCompletion(operationTimeoutMillis(), TimeUnit.MILLISECONDS);
582-
Throwable e = responseObserver.getError();
583-
assertNotNull("expected INVALID_ARGUMENT", e);
584-
assertEquals(Status.INVALID_ARGUMENT.getCode(), Status.fromThrowable(e).getCode());
605+
if (probe) {
606+
// Send a non-compressed message with expectCompress=true. Servers supporting this test case
607+
// should return INVALID_ARGUMENT.
608+
requestObserver.onNext(expectCompressedRequest);
609+
responseObserver.awaitCompletion(operationTimeoutMillis(), TimeUnit.MILLISECONDS);
610+
Throwable e = responseObserver.getError();
611+
assertNotNull("expected INVALID_ARGUMENT", e);
612+
assertEquals(Status.INVALID_ARGUMENT.getCode(), Status.fromThrowable(e).getCode());
613+
}
585614

586615
// Start a new stream
587616
responseObserver = StreamRecorder.create();

interop-testing/src/main/java/io/grpc/testing/integration/TestCases.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ public enum TestCases {
2626
CACHEABLE_UNARY("cacheable unary rpc sent using GET"),
2727
LARGE_UNARY("single request and (large) response"),
2828
CLIENT_COMPRESSED_UNARY("client compressed unary request"),
29+
CLIENT_COMPRESSED_UNARY_NOPROBE("client compressed unary request (skip initial feature-probing request)"),
2930
SERVER_COMPRESSED_UNARY("server compressed unary response"),
3031
CLIENT_STREAMING("request streaming with single response"),
3132
CLIENT_COMPRESSED_STREAMING("client per-message compression on stream"),
33+
CLIENT_COMPRESSED_STREAMING_NOPROBE("client per-message compression on stream (skip initial feature-probing request)"),
3234
SERVER_STREAMING("single request with response streaming"),
3335
SERVER_COMPRESSED_STREAMING("server per-message compression on stream"),
3436
PING_PONG("full-duplex ping-pong streaming"),

interop-testing/src/main/java/io/grpc/testing/integration/TestServiceClient.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,10 @@ private void runTest(TestCases testCase) throws Exception {
224224
tester.clientCompressedUnary();
225225
break;
226226

227+
case CLIENT_COMPRESSED_UNARY_NOPROBE:
228+
tester.clientCompressedUnaryNoProbe();
229+
break;
230+
227231
case SERVER_COMPRESSED_UNARY:
228232
tester.serverCompressedUnary();
229233
break;
@@ -236,6 +240,10 @@ private void runTest(TestCases testCase) throws Exception {
236240
tester.clientCompressedStreaming();
237241
break;
238242

243+
case CLIENT_COMPRESSED_STREAMING_NOPROBE:
244+
tester.clientCompressedStreamingNoProbe();
245+
break;
246+
239247
case SERVER_STREAMING:
240248
tester.serverStreaming();
241249
break;

interop-testing/src/test/java/io/grpc/testing/integration/TestCasesTest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,21 @@ public void testCaseNamesShouldMapToEnums() {
6565
"timeout_on_sleeping_server"
6666
};
6767

68-
assertEquals(testCases.length, TestCases.values().length);
68+
// additional test cases
69+
String[] additionalTestCases = {
70+
"client_compressed_unary_noprobe",
71+
"client_compressed_streaming_noprobe"
72+
};
73+
74+
assertEquals(testCases.length + additionalTestCases.length, TestCases.values().length);
6975

7076
Set<TestCases> testCaseSet = new HashSet<TestCases>(testCases.length);
7177
for (String testCase : testCases) {
7278
testCaseSet.add(TestCases.fromString(testCase));
7379
}
80+
for (String testCase : additionalTestCases) {
81+
testCaseSet.add(TestCases.fromString(testCase));
82+
}
7483

7584
assertEquals(TestCases.values().length, testCaseSet.size());
7685
}

0 commit comments

Comments
 (0)