Craig Tiller | fbac5f1 | 2015-05-15 14:20:44 -0700 | [diff] [blame] | 1 | /* |
| 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 Tiller | 7a317e5 | 2015-05-19 09:38:29 -0700 | [diff] [blame] | 36 | #include <sstream> |
Craig Tiller | fbac5f1 | 2015-05-15 14:20:44 -0700 | [diff] [blame] | 37 | #include <string> |
| 38 | #include <gflags/gflags.h> |
| 39 | |
Craig Tiller | 7a317e5 | 2015-05-19 09:38:29 -0700 | [diff] [blame] | 40 | #include <grpc++/channel_arguments.h> |
yang-g | 8c2be9f | 2015-08-19 16:28:09 -0700 | [diff] [blame^] | 41 | #include <grpc++/channel.h> |
Craig Tiller | 7a317e5 | 2015-05-19 09:38:29 -0700 | [diff] [blame] | 42 | #include <grpc++/client_context.h> |
| 43 | #include <grpc++/create_channel.h> |
| 44 | #include <grpc++/credentials.h> |
Craig Tiller | fbac5f1 | 2015-05-15 14:20:44 -0700 | [diff] [blame] | 45 | #include <grpc++/status.h> |
| 46 | #include "test/cpp/util/echo.grpc.pb.h" |
| 47 | |
Craig Tiller | 7a317e5 | 2015-05-19 09:38:29 -0700 | [diff] [blame] | 48 | DEFINE_string(address, "", "Address to connect to"); |
Craig Tiller | fd7166d | 2015-05-19 10:23:03 -0700 | [diff] [blame] | 49 | DEFINE_string(mode, "", "Test mode to use"); |
Craig Tiller | fbac5f1 | 2015-05-15 14:20:44 -0700 | [diff] [blame] | 50 | |
| 51 | using grpc::cpp::test::util::EchoRequest; |
| 52 | using 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. |
| 56 | namespace google {} |
| 57 | namespace gflags {} |
| 58 | using namespace google; |
| 59 | using namespace gflags; |
| 60 | |
Craig Tiller | fbac5f1 | 2015-05-15 14:20:44 -0700 | [diff] [blame] | 61 | int main(int argc, char** argv) { |
| 62 | ParseCommandLineFlags(&argc, &argv, true); |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 63 | auto stub = grpc::cpp::test::util::TestService::NewStub(grpc::CreateChannel( |
| 64 | FLAGS_address, grpc::InsecureCredentials(), grpc::ChannelArguments())); |
Craig Tiller | 7a317e5 | 2015-05-19 09:38:29 -0700 | [diff] [blame] | 65 | |
| 66 | EchoRequest request; |
| 67 | EchoResponse response; |
| 68 | grpc::ClientContext context; |
| 69 | |
Craig Tiller | fd7166d | 2015-05-19 10:23:03 -0700 | [diff] [blame] | 70 | 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 Tiller | 7a317e5 | 2015-05-19 09:38:29 -0700 | [diff] [blame] | 90 | } |
Craig Tiller | fbac5f1 | 2015-05-15 14:20:44 -0700 | [diff] [blame] | 91 | |
| 92 | return 0; |
| 93 | } |