diff options
author | makdharma <makdharma@users.noreply.github.com> | 2016-10-12 10:53:56 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-12 10:53:56 -0700 |
commit | 5ef0c0041fa09d9db030fea16a9d4b4794a2521f (patch) | |
tree | 347e6099991f7e6d2d38483586cb05a23556c683 /test/cpp/interop/interop_client.cc | |
parent | fad04cc4adb9607ff6e0e14fa863e581c5574124 (diff) | |
parent | 82d7677ec9104e6e3bf57097591ef322758e6cfb (diff) |
Merge pull request #8101 from makdharma/cacheable_unary
Add interop test for Cacheable Unary Calls
Diffstat (limited to 'test/cpp/interop/interop_client.cc')
-rw-r--r-- | test/cpp/interop/interop_client.cc | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/test/cpp/interop/interop_client.cc b/test/cpp/interop/interop_client.cc index 6117878a33..e9a804ccae 100644 --- a/test/cpp/interop/interop_client.cc +++ b/test/cpp/interop/interop_client.cc @@ -846,6 +846,50 @@ bool InteropClient::DoStatusWithMessage() { return true; } +bool InteropClient::DoCacheableUnary() { + gpr_log(GPR_DEBUG, "Sending RPC with cacheable response"); + + // Create request with current timestamp + gpr_timespec ts = gpr_now(GPR_CLOCK_PRECISE); + std::string timestamp = std::to_string((long long unsigned)ts.tv_nsec); + SimpleRequest request; + request.mutable_payload()->set_body(timestamp.c_str(), timestamp.size()); + + // 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 2 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"); |