From c1ef4264025669ed45119d7bf6e34e02b95d6ee7 Mon Sep 17 00:00:00 2001 From: Arnout Engelen Date: Wed, 28 Mar 2018 16:18:39 +0200 Subject: [PATCH 1/3] interop-testing: client compressed tests without probing (#4240) --- .../integration/AbstractInteropTest.java | 59 ++++++++++++++----- .../grpc/testing/integration/TestCases.java | 2 + .../integration/TestServiceClient.java | 8 +++ .../testing/integration/TestCasesTest.java | 11 +++- 4 files changed, 64 insertions(+), 16 deletions(-) diff --git a/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java b/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java index e54b3cc9821..15cb9f8e51d 100644 --- a/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java +++ b/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java @@ -391,6 +391,18 @@ public void largeUnary() throws Exception { * a message's compression level, so this is primarily intended to run against a gRPC C++ server. */ public void clientCompressedUnary() throws Exception { + clientCompressedUnary(true); + } + + /** + * Tests client per-message compression for unary calls. The Java API does not support inspecting + * a message's compression level, so this is primarily intended to run against a gRPC C++ server. + */ + public void clientCompressedUnaryNoProbe() throws Exception { + clientCompressedUnary(false); + } + + private void clientCompressedUnary(boolean probe) throws Exception { assumeEnoughMemory(); final SimpleRequest expectCompressedRequest = SimpleRequest.newBuilder() @@ -409,15 +421,17 @@ public void clientCompressedUnary() throws Exception { .setPayload(Payload.newBuilder().setBody(ByteString.copyFrom(new byte[314159]))) .build(); - // Send a non-compressed message with expectCompress=true. Servers supporting this test case - // should return INVALID_ARGUMENT. - try { - blockingStub.unaryCall(expectCompressedRequest); - fail("expected INVALID_ARGUMENT"); - } catch (StatusRuntimeException e) { - assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatus().getCode()); + if (probe) { + // Send a non-compressed message with expectCompress=true. Servers supporting this test case + // should return INVALID_ARGUMENT. + try { + blockingStub.unaryCall(expectCompressedRequest); + fail("expected INVALID_ARGUMENT"); + } catch (StatusRuntimeException e) { + assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatus().getCode()); + } + assertStatsTrace("grpc.testing.TestService/UnaryCall", Status.Code.INVALID_ARGUMENT); } - assertStatsTrace("grpc.testing.TestService/UnaryCall", Status.Code.INVALID_ARGUMENT); assertEquals( goldenResponse, blockingStub.withCompression("gzip").unaryCall(expectCompressedRequest)); @@ -558,6 +572,19 @@ public void clientStreaming() throws Exception { * C++ server. */ public void clientCompressedStreaming() throws Exception { + clientCompressedStreaming(true); + } + + /** + * Tests client per-message compression for streaming calls. The Java API does not support + * inspecting a message's compression level, so this is primarily intended to run against a gRPC + * C++ server. + */ + public void clientCompressedStreamingNoProbe() throws Exception { + clientCompressedStreaming(false); + } + + private void clientCompressedStreaming(boolean probe) throws Exception { final StreamingInputCallRequest expectCompressedRequest = StreamingInputCallRequest.newBuilder() .setExpectCompressed(BoolValue.newBuilder().setValue(true)) @@ -575,13 +602,15 @@ public void clientCompressedStreaming() throws Exception { StreamObserver requestObserver = asyncStub.streamingInputCall(responseObserver); - // Send a non-compressed message with expectCompress=true. Servers supporting this test case - // should return INVALID_ARGUMENT. - requestObserver.onNext(expectCompressedRequest); - responseObserver.awaitCompletion(operationTimeoutMillis(), TimeUnit.MILLISECONDS); - Throwable e = responseObserver.getError(); - assertNotNull("expected INVALID_ARGUMENT", e); - assertEquals(Status.INVALID_ARGUMENT.getCode(), Status.fromThrowable(e).getCode()); + if (probe) { + // Send a non-compressed message with expectCompress=true. Servers supporting this test case + // should return INVALID_ARGUMENT. + requestObserver.onNext(expectCompressedRequest); + responseObserver.awaitCompletion(operationTimeoutMillis(), TimeUnit.MILLISECONDS); + Throwable e = responseObserver.getError(); + assertNotNull("expected INVALID_ARGUMENT", e); + assertEquals(Status.INVALID_ARGUMENT.getCode(), Status.fromThrowable(e).getCode()); + } // Start a new stream responseObserver = StreamRecorder.create(); diff --git a/interop-testing/src/main/java/io/grpc/testing/integration/TestCases.java b/interop-testing/src/main/java/io/grpc/testing/integration/TestCases.java index 2efbd31062d..f298f3524bf 100644 --- a/interop-testing/src/main/java/io/grpc/testing/integration/TestCases.java +++ b/interop-testing/src/main/java/io/grpc/testing/integration/TestCases.java @@ -26,9 +26,11 @@ public enum TestCases { CACHEABLE_UNARY("cacheable unary rpc sent using GET"), LARGE_UNARY("single request and (large) response"), CLIENT_COMPRESSED_UNARY("client compressed unary request"), + CLIENT_COMPRESSED_UNARY_NOPROBE("client compressed unary request (skip initial feature-probing request)"), SERVER_COMPRESSED_UNARY("server compressed unary response"), CLIENT_STREAMING("request streaming with single response"), CLIENT_COMPRESSED_STREAMING("client per-message compression on stream"), + CLIENT_COMPRESSED_STREAMING_NOPROBE("client per-message compression on stream (skip initial feature-probing request)"), SERVER_STREAMING("single request with response streaming"), SERVER_COMPRESSED_STREAMING("server per-message compression on stream"), PING_PONG("full-duplex ping-pong streaming"), diff --git a/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceClient.java b/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceClient.java index bdf7eb1366e..dbaa2defcf3 100644 --- a/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceClient.java +++ b/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceClient.java @@ -224,6 +224,10 @@ private void runTest(TestCases testCase) throws Exception { tester.clientCompressedUnary(); break; + case CLIENT_COMPRESSED_UNARY_NOPROBE: + tester.clientCompressedUnaryNoProbe(); + break; + case SERVER_COMPRESSED_UNARY: tester.serverCompressedUnary(); break; @@ -236,6 +240,10 @@ private void runTest(TestCases testCase) throws Exception { tester.clientCompressedStreaming(); break; + case CLIENT_COMPRESSED_STREAMING_NOPROBE: + tester.clientCompressedStreamingNoProbe(); + break; + case SERVER_STREAMING: tester.serverStreaming(); break; diff --git a/interop-testing/src/test/java/io/grpc/testing/integration/TestCasesTest.java b/interop-testing/src/test/java/io/grpc/testing/integration/TestCasesTest.java index aac5cbc670b..6e54f5c2101 100644 --- a/interop-testing/src/test/java/io/grpc/testing/integration/TestCasesTest.java +++ b/interop-testing/src/test/java/io/grpc/testing/integration/TestCasesTest.java @@ -65,12 +65,21 @@ public void testCaseNamesShouldMapToEnums() { "timeout_on_sleeping_server" }; - assertEquals(testCases.length, TestCases.values().length); + // additional test cases + String[] additionalTestCases = { + "client_compressed_unary_noprobe", + "client_compressed_streaming_noprobe" + }; + + assertEquals(testCases.length + additionalTestCases.length, TestCases.values().length); Set testCaseSet = new HashSet(testCases.length); for (String testCase : testCases) { testCaseSet.add(TestCases.fromString(testCase)); } + for (String testCase : additionalTestCases) { + testCaseSet.add(TestCases.fromString(testCase)); + } assertEquals(TestCases.values().length, testCaseSet.size()); } From 91eb9ada9669d9ad678eee6fa3fa0b09bb669a97 Mon Sep 17 00:00:00 2001 From: Arnout Engelen Date: Wed, 28 Mar 2018 21:53:23 +0200 Subject: [PATCH 2/3] Avoid lines longer than 100 characters --- .../main/java/io/grpc/testing/integration/TestCases.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/interop-testing/src/main/java/io/grpc/testing/integration/TestCases.java b/interop-testing/src/main/java/io/grpc/testing/integration/TestCases.java index f298f3524bf..7056d384820 100644 --- a/interop-testing/src/main/java/io/grpc/testing/integration/TestCases.java +++ b/interop-testing/src/main/java/io/grpc/testing/integration/TestCases.java @@ -26,11 +26,13 @@ public enum TestCases { CACHEABLE_UNARY("cacheable unary rpc sent using GET"), LARGE_UNARY("single request and (large) response"), CLIENT_COMPRESSED_UNARY("client compressed unary request"), - CLIENT_COMPRESSED_UNARY_NOPROBE("client compressed unary request (skip initial feature-probing request)"), + CLIENT_COMPRESSED_UNARY_NOPROBE( + "client compressed unary request (skip initial feature-probing request)"), SERVER_COMPRESSED_UNARY("server compressed unary response"), CLIENT_STREAMING("request streaming with single response"), CLIENT_COMPRESSED_STREAMING("client per-message compression on stream"), - CLIENT_COMPRESSED_STREAMING_NOPROBE("client per-message compression on stream (skip initial feature-probing request)"), + CLIENT_COMPRESSED_STREAMING_NOPROBE( + "client per-message compression on stream (skip initial feature-probing request)"), SERVER_STREAMING("single request with response streaming"), SERVER_COMPRESSED_STREAMING("server per-message compression on stream"), PING_PONG("full-duplex ping-pong streaming"), From 6b6558342e75942c8392ef5f2db4f7dc02ef13a0 Mon Sep 17 00:00:00 2001 From: Arnout Engelen Date: Wed, 28 Mar 2018 22:28:51 +0200 Subject: [PATCH 3/3] More direct method calls, make checkstyle happy --- .../integration/AbstractInteropTest.java | 29 ++----------------- .../integration/TestServiceClient.java | 8 ++--- 2 files changed, 6 insertions(+), 31 deletions(-) diff --git a/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java b/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java index 15cb9f8e51d..6fa78124680 100644 --- a/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java +++ b/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java @@ -390,19 +390,7 @@ public void largeUnary() throws Exception { * Tests client per-message compression for unary calls. The Java API does not support inspecting * a message's compression level, so this is primarily intended to run against a gRPC C++ server. */ - public void clientCompressedUnary() throws Exception { - clientCompressedUnary(true); - } - - /** - * Tests client per-message compression for unary calls. The Java API does not support inspecting - * a message's compression level, so this is primarily intended to run against a gRPC C++ server. - */ - public void clientCompressedUnaryNoProbe() throws Exception { - clientCompressedUnary(false); - } - - private void clientCompressedUnary(boolean probe) throws Exception { + public void clientCompressedUnary(boolean probe) throws Exception { assumeEnoughMemory(); final SimpleRequest expectCompressedRequest = SimpleRequest.newBuilder() @@ -571,20 +559,7 @@ public void clientStreaming() throws Exception { * inspecting a message's compression level, so this is primarily intended to run against a gRPC * C++ server. */ - public void clientCompressedStreaming() throws Exception { - clientCompressedStreaming(true); - } - - /** - * Tests client per-message compression for streaming calls. The Java API does not support - * inspecting a message's compression level, so this is primarily intended to run against a gRPC - * C++ server. - */ - public void clientCompressedStreamingNoProbe() throws Exception { - clientCompressedStreaming(false); - } - - private void clientCompressedStreaming(boolean probe) throws Exception { + public void clientCompressedStreaming(boolean probe) throws Exception { final StreamingInputCallRequest expectCompressedRequest = StreamingInputCallRequest.newBuilder() .setExpectCompressed(BoolValue.newBuilder().setValue(true)) diff --git a/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceClient.java b/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceClient.java index dbaa2defcf3..4d891c93246 100644 --- a/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceClient.java +++ b/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceClient.java @@ -221,11 +221,11 @@ private void runTest(TestCases testCase) throws Exception { break; case CLIENT_COMPRESSED_UNARY: - tester.clientCompressedUnary(); + tester.clientCompressedUnary(true); break; case CLIENT_COMPRESSED_UNARY_NOPROBE: - tester.clientCompressedUnaryNoProbe(); + tester.clientCompressedUnary(false); break; case SERVER_COMPRESSED_UNARY: @@ -237,11 +237,11 @@ private void runTest(TestCases testCase) throws Exception { break; case CLIENT_COMPRESSED_STREAMING: - tester.clientCompressedStreaming(); + tester.clientCompressedStreaming(true); break; case CLIENT_COMPRESSED_STREAMING_NOPROBE: - tester.clientCompressedStreamingNoProbe(); + tester.clientCompressedStreaming(false); break; case SERVER_STREAMING: