@@ -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 ();
0 commit comments