aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/cpp/interop/interop_client.cc
diff options
context:
space:
mode:
Diffstat (limited to 'test/cpp/interop/interop_client.cc')
-rw-r--r--test/cpp/interop/interop_client.cc120
1 files changed, 114 insertions, 6 deletions
diff --git a/test/cpp/interop/interop_client.cc b/test/cpp/interop/interop_client.cc
index 8861bc1163..d1242627ef 100644
--- a/test/cpp/interop/interop_client.cc
+++ b/test/cpp/interop/interop_client.cc
@@ -40,6 +40,7 @@
#include <grpc++/client_context.h>
#include <grpc++/security/credentials.h>
#include <grpc/grpc.h>
+#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include <grpc/support/useful.h>
@@ -106,6 +107,11 @@ TestService::Stub* InteropClient::ServiceStub::Get() {
return stub_.get();
}
+UnimplementedService::Stub*
+InteropClient::ServiceStub::GetUnimplementedServiceStub() {
+ return UnimplementedService::NewStub(channel_).get();
+}
+
void InteropClient::ServiceStub::Reset(std::shared_ptr<Channel> channel) {
channel_ = channel;
@@ -161,8 +167,8 @@ bool InteropClient::AssertStatusCode(const Status& s,
bool InteropClient::DoEmpty() {
gpr_log(GPR_DEBUG, "Sending an empty rpc...");
- Empty request = Empty::default_instance();
- Empty response = Empty::default_instance();
+ Empty request;
+ Empty response;
ClientContext context;
Status s = serviceStub_.Get()->EmptyCall(&context, request, &response);
@@ -826,25 +832,90 @@ bool InteropClient::DoStatusWithMessage() {
gpr_log(GPR_DEBUG,
"Sending RPC with a request for status code 2 and message");
+ const grpc::StatusCode test_code = grpc::StatusCode::UNKNOWN;
+ const grpc::string test_msg = "This is a test message";
+
+ // Test UnaryCall.
ClientContext context;
SimpleRequest request;
SimpleResponse response;
EchoStatus* requested_status = request.mutable_response_status();
- requested_status->set_code(grpc::StatusCode::UNKNOWN);
- grpc::string test_msg = "This is a test message";
+ requested_status->set_code(test_code);
requested_status->set_message(test_msg);
-
Status s = serviceStub_.Get()->UnaryCall(&context, request, &response);
-
if (!AssertStatusCode(s, grpc::StatusCode::UNKNOWN)) {
return false;
}
+ GPR_ASSERT(s.error_message() == test_msg);
+ // Test FullDuplexCall.
+ ClientContext stream_context;
+ std::shared_ptr<ClientReaderWriter<StreamingOutputCallRequest,
+ StreamingOutputCallResponse>>
+ stream(serviceStub_.Get()->FullDuplexCall(&stream_context));
+ StreamingOutputCallRequest streaming_request;
+ requested_status = streaming_request.mutable_response_status();
+ requested_status->set_code(test_code);
+ requested_status->set_message(test_msg);
+ stream->Write(streaming_request);
+ stream->WritesDone();
+ StreamingOutputCallResponse streaming_response;
+ while (stream->Read(&streaming_response))
+ ;
+ s = stream->Finish();
+ if (!AssertStatusCode(s, grpc::StatusCode::UNKNOWN)) {
+ return false;
+ }
GPR_ASSERT(s.error_message() == test_msg);
+
gpr_log(GPR_DEBUG, "Done testing Status and Message");
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");
@@ -936,5 +1007,42 @@ bool InteropClient::DoCustomMetadata() {
return true;
}
+bool InteropClient::DoUnimplementedService() {
+ gpr_log(GPR_DEBUG, "Sending a request for an unimplemented service...");
+
+ Empty request;
+ Empty response;
+ ClientContext context;
+
+ UnimplementedService::Stub* stub = serviceStub_.GetUnimplementedServiceStub();
+
+ Status s = stub->UnimplementedCall(&context, request, &response);
+
+ if (!AssertStatusCode(s, StatusCode::UNIMPLEMENTED)) {
+ return false;
+ }
+
+ gpr_log(GPR_DEBUG, "unimplemented service done.");
+ return true;
+}
+
+bool InteropClient::DoUnimplementedMethod() {
+ gpr_log(GPR_DEBUG, "Sending a request for an unimplemented rpc...");
+
+ Empty request;
+ Empty response;
+ ClientContext context;
+
+ Status s =
+ serviceStub_.Get()->UnimplementedCall(&context, request, &response);
+
+ if (!AssertStatusCode(s, StatusCode::UNIMPLEMENTED)) {
+ return false;
+ }
+
+ gpr_log(GPR_DEBUG, "unimplemented rpc done.");
+ return true;
+}
+
} // namespace testing
} // namespace grpc