aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/cpp')
-rw-r--r--test/cpp/client/channel_arguments_test.cc130
-rw-r--r--test/cpp/end2end/end2end_test.cc15
-rw-r--r--test/cpp/end2end/sync_client_async_server_test.cc4
-rw-r--r--test/cpp/interop/client.cc21
-rw-r--r--test/cpp/qps/client.cc20
-rw-r--r--test/cpp/util/create_test_channel.cc (renamed from test/cpp/util/test_ssl_channel.cc)38
-rw-r--r--test/cpp/util/create_test_channel.h (renamed from test/cpp/util/test_ssl_channel.h)22
7 files changed, 178 insertions, 72 deletions
diff --git a/test/cpp/client/channel_arguments_test.cc b/test/cpp/client/channel_arguments_test.cc
new file mode 100644
index 0000000000..b94d4788f7
--- /dev/null
+++ b/test/cpp/client/channel_arguments_test.cc
@@ -0,0 +1,130 @@
+/*
+ *
+ * Copyright 2014, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <grpc++/channel_arguments.h>
+
+#include <grpc/grpc.h>
+#include <gtest/gtest.h>
+
+namespace grpc {
+namespace testing {
+
+class ChannelArgumentsTest : public ::testing::Test {
+ protected:
+ void SetChannelArgs(const ChannelArguments& channel_args,
+ grpc_channel_args* args) {
+ channel_args.SetChannelArgs(args);
+ }
+};
+
+TEST_F(ChannelArgumentsTest, SetInt) {
+ grpc_channel_args args;
+ ChannelArguments channel_args;
+ // Empty arguments.
+ SetChannelArgs(channel_args, &args);
+ EXPECT_EQ(0, args.num_args);
+
+ grpc::string key("key0");
+ channel_args.SetInt(key, 0);
+ // Clear key early to make sure channel_args takes a copy
+ key = "";
+ SetChannelArgs(channel_args, &args);
+ EXPECT_EQ(1, args.num_args);
+ EXPECT_EQ(GRPC_ARG_INTEGER, args.args[0].type);
+ EXPECT_STREQ("key0", args.args[0].key);
+ EXPECT_EQ(0, args.args[0].value.integer);
+
+ key = "key1";
+ channel_args.SetInt(key, 1);
+ key = "";
+ SetChannelArgs(channel_args, &args);
+ EXPECT_EQ(2, args.num_args);
+ bool found[2] = {false, false};
+ // We do not enforce order on the arguments.
+ for (int i = 0; i < args.num_args; i++) {
+ EXPECT_EQ(GRPC_ARG_INTEGER, args.args[i].type);
+ if (grpc::string(args.args[i].key) == "key0") {
+ found[0] = true;
+ EXPECT_EQ(0, args.args[i].value.integer);
+ } else if (grpc::string(args.args[i].key) == "key1") {
+ found[1] = true;
+ EXPECT_EQ(1, args.args[i].value.integer);
+ }
+ }
+}
+
+TEST_F(ChannelArgumentsTest, SetString) {
+ grpc_channel_args args;
+ ChannelArguments channel_args;
+ // Empty arguments.
+ SetChannelArgs(channel_args, &args);
+ EXPECT_EQ(0, args.num_args);
+
+ grpc::string key("key0");
+ grpc::string val("val0");
+ channel_args.SetString(key, val);
+ // Clear key/val early to make sure channel_args takes a copy
+ key = "";
+ val = "";
+ SetChannelArgs(channel_args, &args);
+ EXPECT_EQ(1, args.num_args);
+ EXPECT_EQ(GRPC_ARG_STRING, args.args[0].type);
+ EXPECT_STREQ("key0", args.args[0].key);
+ EXPECT_STREQ("val0", args.args[0].value.string);
+
+ key = "key1";
+ val = "val1";
+ channel_args.SetString(key, val);
+ SetChannelArgs(channel_args, &args);
+ EXPECT_EQ(2, args.num_args);
+ bool found[2] = {false, false};
+ // We do not enforce order on the arguments.
+ for (int i = 0; i < args.num_args; i++) {
+ EXPECT_EQ(GRPC_ARG_STRING, args.args[i].type);
+ if (grpc::string(args.args[i].key) == "key0") {
+ found[0] = true;
+ EXPECT_STREQ("val0", args.args[i].value.string);
+ } else if (grpc::string(args.args[i].key) == "key1") {
+ found[1] = true;
+ EXPECT_STREQ("val1", args.args[i].value.string);
+ }
+ }
+}
+
+} // namespace testing
+} // namespace grpc
+
+int main(int argc, char** argv) {
+
+ return RUN_ALL_TESTS();
+}
diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc
index f32f99e048..4b5a9a8e6a 100644
--- a/test/cpp/end2end/end2end_test.cc
+++ b/test/cpp/end2end/end2end_test.cc
@@ -35,6 +35,7 @@
#include "src/cpp/server/rpc_service_method.h"
#include "test/cpp/util/echo.pb.h"
#include "net/util/netutil.h"
+#include <grpc++/channel_arguments.h>
#include <grpc++/channel_interface.h>
#include <grpc++/client_context.h>
#include <grpc++/create_channel.h>
@@ -126,7 +127,7 @@ class End2endTest : public ::testing::Test {
static void SendRpc(const grpc::string& server_address, int num_rpcs) {
std::shared_ptr<ChannelInterface> channel =
- CreateChannel(server_address);
+ CreateChannel(server_address, ChannelArguments());
TestService::Stub* stub = TestService::NewStub(channel);
EchoRequest request;
EchoResponse response;
@@ -160,7 +161,7 @@ TEST_F(End2endTest, MultipleRpcs) {
// Set a 10us deadline and make sure proper error is returned.
TEST_F(End2endTest, RpcDeadlineExpires) {
std::shared_ptr<ChannelInterface> channel =
- CreateChannel(server_address_.str());
+ CreateChannel(server_address_.str(), ChannelArguments());
TestService::Stub* stub = TestService::NewStub(channel);
EchoRequest request;
EchoResponse response;
@@ -180,7 +181,7 @@ TEST_F(End2endTest, RpcDeadlineExpires) {
TEST_F(End2endTest, UnimplementedRpc) {
std::shared_ptr<ChannelInterface> channel =
- CreateChannel(server_address_.str());
+ CreateChannel(server_address_.str(), ChannelArguments());
TestService::Stub* stub = TestService::NewStub(channel);
EchoRequest request;
EchoResponse response;
@@ -198,7 +199,7 @@ TEST_F(End2endTest, UnimplementedRpc) {
TEST_F(End2endTest, RequestStreamOneRequest) {
std::shared_ptr<ChannelInterface> channel =
- CreateChannel(server_address_.str());
+ CreateChannel(server_address_.str(), ChannelArguments());
TestService::Stub* stub = TestService::NewStub(channel);
EchoRequest request;
EchoResponse response;
@@ -218,7 +219,7 @@ TEST_F(End2endTest, RequestStreamOneRequest) {
TEST_F(End2endTest, RequestStreamTwoRequests) {
std::shared_ptr<ChannelInterface> channel =
- CreateChannel(server_address_.str());
+ CreateChannel(server_address_.str(), ChannelArguments());
TestService::Stub* stub = TestService::NewStub(channel);
EchoRequest request;
EchoResponse response;
@@ -239,7 +240,7 @@ TEST_F(End2endTest, RequestStreamTwoRequests) {
TEST_F(End2endTest, ResponseStream) {
std::shared_ptr<ChannelInterface> channel =
- CreateChannel(server_address_.str());
+ CreateChannel(server_address_.str(), ChannelArguments());
TestService::Stub* stub = TestService::NewStub(channel);
EchoRequest request;
EchoResponse response;
@@ -264,7 +265,7 @@ TEST_F(End2endTest, ResponseStream) {
TEST_F(End2endTest, BidiStream) {
std::shared_ptr<ChannelInterface> channel =
- CreateChannel(server_address_.str());
+ CreateChannel(server_address_.str(), ChannelArguments());
TestService::Stub* stub = TestService::NewStub(channel);
EchoRequest request;
EchoResponse response;
diff --git a/test/cpp/end2end/sync_client_async_server_test.cc b/test/cpp/end2end/sync_client_async_server_test.cc
index f9ac6f2ea5..839f89cdb1 100644
--- a/test/cpp/end2end/sync_client_async_server_test.cc
+++ b/test/cpp/end2end/sync_client_async_server_test.cc
@@ -43,6 +43,7 @@
#include "src/cpp/rpc_method.h"
#include "test/cpp/util/echo.pb.h"
#include "net/util/netutil.h"
+#include <grpc++/channel_arguments.h>
#include <grpc++/channel_interface.h>
#include <grpc++/client_context.h>
#include <grpc++/create_channel.h>
@@ -86,7 +87,8 @@ class End2endTest : public ::testing::Test {
// Setup client
oss.str("");
oss << "127.0.0.1:" << port;
- std::shared_ptr<ChannelInterface> channel = CreateChannel(oss.str());
+ std::shared_ptr<ChannelInterface> channel =
+ CreateChannel(oss.str(), ChannelArguments());
stub_.set_channel(channel);
}
diff --git a/test/cpp/interop/client.cc b/test/cpp/interop/client.cc
index a2a0f582f9..8ea52b5d51 100644
--- a/test/cpp/interop/client.cc
+++ b/test/cpp/interop/client.cc
@@ -40,12 +40,13 @@
#include <grpc/grpc.h>
#include <grpc/support/log.h>
#include <google/gflags.h>
+#include <grpc++/channel_arguments.h>
#include <grpc++/channel_interface.h>
#include <grpc++/client_context.h>
#include <grpc++/create_channel.h>
#include <grpc++/status.h>
#include <grpc++/stream.h>
-#include "test/cpp/util/test_ssl_channel.h"
+#include "test/cpp/util/create_test_channel.h"
#include "test/cpp/interop/test.pb.h"
#include "test/cpp/interop/empty.pb.h"
#include "test/cpp/interop/messages.pb.h"
@@ -67,8 +68,7 @@ DEFINE_string(test_case, "large_unary",
using grpc::ChannelInterface;
using grpc::ClientContext;
-using grpc::CreateChannel;
-using grpc::TestSslChannel;
+using grpc::CreateTestChannel;
using grpc::testing::ResponseParameters;
using grpc::testing::SimpleRequest;
using grpc::testing::SimpleResponse;
@@ -87,17 +87,6 @@ const int kResponseMessageSize = 1030;
const int kReceiveDelayMilliSeconds = 20;
} // namespace
-std::shared_ptr<ChannelInterface> CreateTestChannel(
- const grpc::string& server) {
- std::shared_ptr<ChannelInterface> channel;
- if (FLAGS_enable_ssl) {
- channel.reset(new TestSslChannel(server));
- } else {
- channel = CreateChannel(server);
- }
- return channel;
-}
-
void DoEmpty(std::shared_ptr<ChannelInterface> channel) {
gpr_log(GPR_INFO, "Sending an empty rpc...");
std::unique_ptr<TestService::Stub> stub(TestService::NewStub(channel));
@@ -146,9 +135,9 @@ int main(int argc, char** argv) {
FLAGS_server_port);
if (FLAGS_test_case == "empty_unary") {
- DoEmpty(CreateTestChannel(host_port));
+ DoEmpty(CreateTestChannel(host_port, FLAGS_enable_ssl));
} else if (FLAGS_test_case == "large_unary") {
- DoLargeUnary(CreateTestChannel(host_port));
+ DoLargeUnary(CreateTestChannel(host_port, FLAGS_enable_ssl));
} else {
gpr_log(
GPR_ERROR,
diff --git a/test/cpp/qps/client.cc b/test/cpp/qps/client.cc
index e0f13a8ca2..287cef8192 100644
--- a/test/cpp/qps/client.cc
+++ b/test/cpp/qps/client.cc
@@ -43,11 +43,9 @@
#include <grpc/support/histogram.h>
#include <grpc/support/log.h>
#include <google/gflags.h>
-#include <grpc++/channel_interface.h>
#include <grpc++/client_context.h>
-#include <grpc++/create_channel.h>
#include <grpc++/status.h>
-#include "test/cpp/util/test_ssl_channel.h"
+#include "test/cpp/util/create_test_channel.h"
#include "test/cpp/interop/test.pb.h"
DEFINE_bool(enable_ssl, false, "Whether to use ssl/tls.");
@@ -75,23 +73,11 @@ DEFINE_int32(payload_size, 1, "Payload size in bytes");
DEFINE_string(workload, "", "Workload parameters");
using grpc::ChannelInterface;
-using grpc::CreateChannel;
-using grpc::TestSslChannel;
+using grpc::CreateTestChannel;
using grpc::testing::SimpleRequest;
using grpc::testing::SimpleResponse;
using grpc::testing::TestService;
-std::shared_ptr<ChannelInterface> CreateTestChannel(
- const grpc::string& server) {
- std::shared_ptr<ChannelInterface> channel;
- if (FLAGS_enable_ssl) {
- channel.reset(new TestSslChannel(server));
- } else {
- channel = CreateChannel(server);
- }
- return channel;
-}
-
static double now() {
gpr_timespec tv = gpr_now();
return 1e9 * tv.tv_sec + tv.tv_nsec;
@@ -116,7 +102,7 @@ void RunTest(const int client_threads, const int client_channels,
class ClientChannelInfo {
public:
explicit ClientChannelInfo(const grpc::string &server)
- : channel_(CreateTestChannel(server)),
+ : channel_(CreateTestChannel(server, FLAGS_enable_ssl)),
stub_(TestService::NewStub(channel_)) {}
ChannelInterface *get_channel() { return channel_.get(); }
TestService::Stub *get_stub() { return stub_.get(); }
diff --git a/test/cpp/util/test_ssl_channel.cc b/test/cpp/util/create_test_channel.cc
index ca2c563c7b..afac38abd3 100644
--- a/test/cpp/util/test_ssl_channel.cc
+++ b/test/cpp/util/create_test_channel.cc
@@ -31,28 +31,32 @@
*
*/
-#include "test/cpp/util/test_ssl_channel.h"
-
-#include <grpc/support/log.h>
-
-#include <grpc/grpc_security.h>
+#include "test/cpp/util/create_test_channel.h"
#include "test/core/end2end/data/ssl_test_data.h"
+#include <grpc++/channel_arguments.h>
+#include <grpc++/create_channel.h>
+#include <grpc++/credentials.h>
namespace grpc {
-TestSslChannel::TestSslChannel(const grpc::string& target) {
- grpc_credentials* ssl_creds = grpc_ssl_credentials_create(
- test_ca_cert, test_ca_cert_size, NULL, 0, NULL, 0);
- grpc_arg ssl_name_override = {
- GRPC_ARG_STRING,
- const_cast<char*>(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG),
- {const_cast<char*>("foo.test.google.com")}};
- grpc_channel_args client_args = {1, &ssl_name_override};
- set_c_channel(
- grpc_secure_channel_create(ssl_creds, target.c_str(), &client_args));
- grpc_credentials_release(ssl_creds);
+std::shared_ptr<ChannelInterface> CreateTestChannel(const grpc::string& server,
+ bool enable_ssl) {
+ ChannelArguments channel_args;
+ if (enable_ssl) {
+ SslCredentialsOptions ssl_opts = {
+ {reinterpret_cast<const char*>(test_ca_cert), test_ca_cert_size},
+ "",
+ ""};
+
+ std::unique_ptr<Credentials> creds =
+ CredentialsFactory::SslCredentials(ssl_opts);
+
+ channel_args.SetSslTargetNameOverride("foo.test.google.com");
+ return CreateChannel(server, creds, channel_args);
+ } else {
+ return CreateChannel(server, channel_args);
+ }
}
} // namespace grpc
-
diff --git a/test/cpp/util/test_ssl_channel.h b/test/cpp/util/create_test_channel.h
index 28905dc3ab..c705e59ddf 100644
--- a/test/cpp/util/test_ssl_channel.h
+++ b/test/cpp/util/create_test_channel.h
@@ -31,25 +31,19 @@
*
*/
-#ifndef __GRPCPP_TEST_UTIL_TEST_SSL_CHANNEL_H__
-#define __GRPCPP_TEST_UTIL_TEST_SSL_CHANNEL_H__
+#ifndef __GRPCPP_TEST_UTIL_CREATE_TEST_CHANNEL_H_
+#define __GRPCPP_TEST_UTIL_CREATE_TEST_CHANNEL_H_
-#include <string>
+#include <memory>
-#include "src/cpp/client/channel.h"
-
-struct grpc_channel;
+#include <grpc++/config.h>
namespace grpc {
-class StreamContextInterface;
+class ChannelInterface;
-// The channel is used to test against test gfe or interop binaries with ssl
-// support.
-class TestSslChannel : public Channel {
- public:
- explicit TestSslChannel(const grpc::string& target);
-};
+std::shared_ptr<ChannelInterface> CreateTestChannel(const grpc::string& server,
+ bool enable_ssl);
} // namespace grpc
-#endif // __GRPCPP_TEST_UTIL_TEST_SSL_CHANNEL_H__
+#endif // __GRPCPP_TEST_UTIL_CREATE_TEST_CHANNEL_H_