diff options
author | Makarand Dharmapurikar <makarandd@google.com> | 2016-09-14 15:01:16 -0700 |
---|---|---|
committer | Makarand Dharmapurikar <makarandd@google.com> | 2016-09-14 15:01:16 -0700 |
commit | 1ed0b8e3d72abcc4788e89cab4caa4e8c0083985 (patch) | |
tree | 304e0cefda1020d57d878208b5614f0cc6d0670d /test/cpp/interop/interop_client.cc | |
parent | 83374d51662899adc08966ccca0d8d407f626df2 (diff) |
Add interop test for Cacheable Unary Calls
modified interop test spec doc
added CacheableUnaryCall to test.proto
modified server and client implmenentations to support new method
Diffstat (limited to 'test/cpp/interop/interop_client.cc')
-rw-r--r-- | test/cpp/interop/interop_client.cc | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/cpp/interop/interop_client.cc b/test/cpp/interop/interop_client.cc index 8861bc1163..f2290adfc3 100644 --- a/test/cpp/interop/interop_client.cc +++ b/test/cpp/interop/interop_client.cc @@ -845,6 +845,49 @@ bool InteropClient::DoStatusWithMessage() { return true; } +bool InteropClient::DoCacheableUnary() { + gpr_log(GPR_DEBUG, "Sending RPC with cacheable response"); + + SimpleRequest request; + request.set_response_size(16); + grpc::string payload(16, '\0'); + request.mutable_payload()->set_body(payload.c_str(), 16); + + // Request 1 + ClientContext context1; + SimpleResponse response1; + context1.set_cacheable(true); + // Add fake user IP since some proxy's (GFE) won't cache requests from + // localhost. + context1.AddMetadata("x-user-ip", "1.2.3.4"); + Status s1 = + serviceStub_.Get()->CacheableUnaryCall(&context1, request, &response1); + if (!AssertStatusOk(s1)) { + return false; + } + gpr_log(GPR_DEBUG, "response 1 payload: %s", + response1.payload().body().c_str()); + + // Request 2 + ClientContext context2; + SimpleResponse response2; + context2.set_cacheable(true); + context2.AddMetadata("x-user-ip", "1.2.3.4"); + Status s2 = + serviceStub_.Get()->CacheableUnaryCall(&context2, request, &response2); + if (!AssertStatusOk(s2)) { + return false; + } + gpr_log(GPR_DEBUG, "response 1 payload: %s", + response2.payload().body().c_str()); + + // Check that the body is same for both requests. It will be the same if the + // second response is a cached copy of the first response + GPR_ASSERT(response2.payload().body() == response1.payload().body()); + + return true; +} + bool InteropClient::DoCustomMetadata() { const grpc::string kEchoInitialMetadataKey("x-grpc-test-echo-initial"); const grpc::string kInitialMetadataValue("test_initial_metadata_value"); |