blob: 52dce8f28ef8212022418128db7e05c9400193ee [file] [log] [blame]
Craig Tillerfbac5f12015-05-15 14:20:44 -07001/*
2 *
3 * Copyright 2015, Google Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
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
15 * distribution.
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.
19 *
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.
31 *
32 */
33
34#include <iostream>
35#include <memory>
Craig Tiller7a317e52015-05-19 09:38:29 -070036#include <sstream>
Craig Tillerfbac5f12015-05-15 14:20:44 -070037#include <string>
38#include <gflags/gflags.h>
39
Craig Tiller7a317e52015-05-19 09:38:29 -070040#include <grpc++/channel_arguments.h>
yang-g8c2be9f2015-08-19 16:28:09 -070041#include <grpc++/channel.h>
Craig Tiller7a317e52015-05-19 09:38:29 -070042#include <grpc++/client_context.h>
43#include <grpc++/create_channel.h>
44#include <grpc++/credentials.h>
Craig Tillerfbac5f12015-05-15 14:20:44 -070045#include <grpc++/status.h>
46#include "test/cpp/util/echo.grpc.pb.h"
47
Craig Tiller7a317e52015-05-19 09:38:29 -070048DEFINE_string(address, "", "Address to connect to");
Craig Tillerfd7166d2015-05-19 10:23:03 -070049DEFINE_string(mode, "", "Test mode to use");
Craig Tillerfbac5f12015-05-15 14:20:44 -070050
51using grpc::cpp::test::util::EchoRequest;
52using grpc::cpp::test::util::EchoResponse;
53
54// In some distros, gflags is in the namespace google, and in some others,
55// in gflags. This hack is enabling us to find both.
56namespace google {}
57namespace gflags {}
58using namespace google;
59using namespace gflags;
60
Craig Tillerfbac5f12015-05-15 14:20:44 -070061int main(int argc, char** argv) {
62 ParseCommandLineFlags(&argc, &argv, true);
Craig Tillerd6c98df2015-08-18 09:33:44 -070063 auto stub = grpc::cpp::test::util::TestService::NewStub(grpc::CreateChannel(
64 FLAGS_address, grpc::InsecureCredentials(), grpc::ChannelArguments()));
Craig Tiller7a317e52015-05-19 09:38:29 -070065
66 EchoRequest request;
67 EchoResponse response;
68 grpc::ClientContext context;
69
Craig Tillerfd7166d2015-05-19 10:23:03 -070070 if (FLAGS_mode == "bidi") {
71 auto stream = stub->BidiStream(&context);
72 for (int i = 0;; i++) {
73 std::ostringstream msg;
74 msg << "Hello " << i;
75 request.set_message(msg.str());
76 GPR_ASSERT(stream->Write(request));
77 GPR_ASSERT(stream->Read(&response));
78 GPR_ASSERT(response.message() == request.message());
79 }
80 } else if (FLAGS_mode == "response") {
81 EchoRequest request;
82 request.set_message("Hello");
83 auto stream = stub->ResponseStream(&context, request);
84 for (;;) {
85 GPR_ASSERT(stream->Read(&response));
86 }
87 } else {
88 gpr_log(GPR_ERROR, "invalid test mode '%s'", FLAGS_mode.c_str());
89 return 1;
Craig Tiller7a317e52015-05-19 09:38:29 -070090 }
Craig Tillerfbac5f12015-05-15 14:20:44 -070091
92 return 0;
93}