Debian Codegraph @

test/cpp/end2end/server_crash_test_client.cc

raw
1 /*
2 *
3 * Copyright 2015 gRPC authors.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18
19 #include <iostream>
20 #include <memory>
21 #include <sstream>
22 #include <string>
23
24 #include "absl/flags/flag.h"
25
26 #include <grpc/support/log.h>
27 #include <grpcpp/channel.h>
28 #include <grpcpp/client_context.h>
29 #include <grpcpp/create_channel.h>
30
31 #include "src/proto/grpc/testing/echo.grpc.pb.h"
32 #include "test/cpp/util/test_config.h"
33
34 ABSL_FLAG(std::string, address, "", "Address to connect to");
35 ABSL_FLAG(std::string, mode, "", "Test mode to use");
36
37 using grpc::testing::EchoRequest;
38 using grpc::testing::EchoResponse;
39
40 int main(int argc, char** argv) {
41 grpc::testing::InitTest(&argc, &argv, true);
42 auto stub = grpc::testing::EchoTestService::NewStub(grpc::CreateChannel(
43 absl::GetFlag(FLAGS_address), grpc::InsecureChannelCredentials()));
44
45 EchoRequest request;
46 EchoResponse response;
47 grpc::ClientContext context;
48 context.set_wait_for_ready(true);
49
50 if (absl::GetFlag(FLAGS_mode) == "bidi") {
51 auto stream = stub->BidiStream(&context);
52 for (int i = 0;; i++) {
53 std::ostringstream msg;
54 msg << "Hello " << i;
55 request.set_message(msg.str());
56 GPR_ASSERT(stream->Write(request));
57 GPR_ASSERT(stream->Read(&response));
58 GPR_ASSERT(response.message() == request.message());
59 }
60 } else if (absl::GetFlag(FLAGS_mode) == "response") {
61 EchoRequest request;
62 request.set_message("Hello");
63 auto stream = stub->ResponseStream(&context, request);
64 for (;;) {
65 GPR_ASSERT(stream->Read(&response));
66 }
67 } else {
68 gpr_log(GPR_ERROR, "invalid test mode '%s'",
69 absl::GetFlag(FLAGS_mode).c_str());
70 return 1;
71 }
72 }