3
* Copyright 2015, Google Inc.
6
* Redistribution and use in source and binary forms, with or without
7
* modification, are permitted provided that the following conditions are
10
* * Redistributions of source code must retain the above copyright
11
* notice, this list of conditions and the following disclaimer.
12
* * Redistributions in binary form must reproduce the above
13
* copyright notice, this list of conditions and the following disclaimer
14
* in the documentation and/or other materials provided with the
16
* * Neither the name of Google Inc. nor the names of its
17
* contributors may be used to endorse or promote products derived from
18
* this software without specific prior written permission.
20
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38
#include <grpc/grpc.h>
39
#include <grpc/support/log.h>
40
#include <gflags/gflags.h>
41
#include <grpc++/channel_interface.h>
42
#include <grpc++/client_context.h>
43
#include <grpc++/status.h>
44
#include <grpc++/stream.h>
45
#include "test/cpp/interop/client_helper.h"
46
#include "test/cpp/interop/interop_client.h"
47
#include "test/cpp/util/test_config.h"
49
DEFINE_bool(enable_ssl, false, "Whether to use ssl/tls.");
50
DEFINE_bool(use_prod_roots, false, "True to use SSL roots for google");
51
DEFINE_int32(server_port, 0, "Server port.");
52
DEFINE_string(server_host, "127.0.0.1", "Server host to connect to");
53
DEFINE_string(server_host_override, "foo.test.google.fr",
54
"Override the server host which is sent in HTTP header");
55
DEFINE_string(test_case, "large_unary",
56
"Configure different test cases. Valid options are: "
57
"empty_unary : empty (zero bytes) request and response; "
58
"large_unary : single request and (large) response; "
59
"client_streaming : request streaming with single response; "
60
"server_streaming : single request with response streaming; "
61
"slow_consumer : single request with response; "
62
" streaming with slow client consumer; "
63
"half_duplex : half-duplex streaming; "
64
"ping_pong : full-duplex streaming; "
65
"cancel_after_begin : cancel stream after starting it; "
66
"cancel_after_first_response: cancel on first response; "
67
"service_account_creds : large_unary with service_account auth; "
68
"compute_engine_creds: large_unary with compute engine auth; "
69
"jwt_token_creds: large_unary with JWT token auth; "
70
"all : all of above.");
71
DEFINE_string(default_service_account, "",
72
"Email of GCE default service account");
73
DEFINE_string(service_account_key_file, "",
74
"Path to service account json key file.");
75
DEFINE_string(oauth_scope, "", "Scope for OAuth tokens.");
77
using grpc::testing::CreateChannelForTestCase;
78
using grpc::testing::GetServiceAccountJsonKey;
80
int main(int argc, char** argv) {
81
grpc::testing::InitTest(&argc, &argv, true);
84
grpc::testing::InteropClient client(
85
CreateChannelForTestCase(FLAGS_test_case));
86
if (FLAGS_test_case == "empty_unary") {
88
} else if (FLAGS_test_case == "large_unary") {
89
client.DoLargeUnary();
90
} else if (FLAGS_test_case == "client_streaming") {
91
client.DoRequestStreaming();
92
} else if (FLAGS_test_case == "server_streaming") {
93
client.DoResponseStreaming();
94
} else if (FLAGS_test_case == "slow_consumer") {
95
client.DoResponseStreamingWithSlowConsumer();
96
} else if (FLAGS_test_case == "half_duplex") {
97
client.DoHalfDuplex();
98
} else if (FLAGS_test_case == "ping_pong") {
100
} else if (FLAGS_test_case == "cancel_after_begin") {
101
client.DoCancelAfterBegin();
102
} else if (FLAGS_test_case == "cancel_after_first_response") {
103
client.DoCancelAfterFirstResponse();
104
} else if (FLAGS_test_case == "service_account_creds") {
105
grpc::string json_key = GetServiceAccountJsonKey();
106
client.DoServiceAccountCreds(json_key, FLAGS_oauth_scope);
107
} else if (FLAGS_test_case == "compute_engine_creds") {
108
client.DoComputeEngineCreds(FLAGS_default_service_account,
110
} else if (FLAGS_test_case == "jwt_token_creds") {
111
grpc::string json_key = GetServiceAccountJsonKey();
112
client.DoJwtTokenCreds(json_key);
113
} else if (FLAGS_test_case == "all") {
115
client.DoLargeUnary();
116
client.DoRequestStreaming();
117
client.DoResponseStreaming();
118
client.DoHalfDuplex();
120
client.DoCancelAfterBegin();
121
client.DoCancelAfterFirstResponse();
122
// service_account_creds and jwt_token_creds can only run with ssl.
123
if (FLAGS_enable_ssl) {
124
grpc::string json_key = GetServiceAccountJsonKey();
125
client.DoServiceAccountCreds(json_key, FLAGS_oauth_scope);
126
client.DoJwtTokenCreds(json_key);
128
// compute_engine_creds only runs in GCE.
132
"Unsupported test case %s. Valid options are all|empty_unary|"
133
"large_unary|client_streaming|server_streaming|half_duplex|ping_pong|"
134
"cancel_after_begin|cancel_after_first_response|"
135
"service_account_creds|compute_engine_creds|jwt_token_creds",
136
FLAGS_test_case.c_str());