Merge pull request #3104 from yang-g/create_channel

Create channel API change
pull/3111/head^2
Craig Tiller 10 years ago
commit 89d56103eb
  1. 6
      include/grpc++/create_channel.h
  2. 2
      include/grpc++/credentials.h
  3. 6
      src/cpp/client/create_channel.cc
  4. 8
      test/cpp/end2end/async_end2end_test.cc
  5. 2
      test/cpp/end2end/client_crash_test.cc
  6. 9
      test/cpp/end2end/end2end_test.cc
  7. 4
      test/cpp/end2end/generic_end2end_test.cc
  8. 4
      test/cpp/end2end/mock_test.cc
  9. 4
      test/cpp/end2end/server_crash_test_client.cc
  10. 2
      test/cpp/end2end/shutdown_test.cc
  11. 4
      test/cpp/end2end/thread_stress_test.cc
  12. 2
      test/cpp/end2end/zookeeper_test.cc
  13. 8
      test/cpp/qps/driver.cc
  14. 4
      test/cpp/qps/report.h
  15. 3
      test/cpp/util/cli_call_test.cc
  16. 4
      test/cpp/util/create_test_channel.cc
  17. 2
      test/cpp/util/grpc_cli.cc

@ -44,6 +44,12 @@ namespace grpc {
// If creds does not hold an object or is invalid, a lame channel is returned. // If creds does not hold an object or is invalid, a lame channel is returned.
std::shared_ptr<Channel> CreateChannel( std::shared_ptr<Channel> CreateChannel(
const grpc::string& target, const std::shared_ptr<Credentials>& creds);
// For advanced use and testing ONLY. Override default channel arguments only
// if necessary.
// If creds does not hold an object or is invalid, a lame channel is returned.
std::shared_ptr<Channel> CreateCustomChannel(
const grpc::string& target, const std::shared_ptr<Credentials>& creds, const grpc::string& target, const std::shared_ptr<Credentials>& creds,
const ChannelArguments& args); const ChannelArguments& args);

@ -57,7 +57,7 @@ class Credentials : public GrpcLibrary {
virtual SecureCredentials* AsSecureCredentials() = 0; virtual SecureCredentials* AsSecureCredentials() = 0;
private: private:
friend std::shared_ptr<Channel> CreateChannel( friend std::shared_ptr<Channel> CreateCustomChannel(
const grpc::string& target, const std::shared_ptr<Credentials>& creds, const grpc::string& target, const std::shared_ptr<Credentials>& creds,
const ChannelArguments& args); const ChannelArguments& args);

@ -44,6 +44,11 @@ namespace grpc {
class ChannelArguments; class ChannelArguments;
std::shared_ptr<Channel> CreateChannel( std::shared_ptr<Channel> CreateChannel(
const grpc::string& target, const std::shared_ptr<Credentials>& creds) {
return CreateCustomChannel(target, creds, ChannelArguments());
}
std::shared_ptr<Channel> CreateCustomChannel(
const grpc::string& target, const std::shared_ptr<Credentials>& creds, const grpc::string& target, const std::shared_ptr<Credentials>& creds,
const ChannelArguments& args) { const ChannelArguments& args) {
ChannelArguments cp_args = args; ChannelArguments cp_args = args;
@ -57,4 +62,5 @@ std::shared_ptr<Channel> CreateChannel(
NULL, GRPC_STATUS_INVALID_ARGUMENT, NULL, GRPC_STATUS_INVALID_ARGUMENT,
"Invalid credentials.")); "Invalid credentials."));
} }
} // namespace grpc } // namespace grpc

@ -200,8 +200,8 @@ class AsyncEnd2endTest : public ::testing::TestWithParam<bool> {
} }
void ResetStub() { void ResetStub() {
std::shared_ptr<Channel> channel = CreateChannel( std::shared_ptr<Channel> channel =
server_address_.str(), InsecureCredentials(), ChannelArguments()); CreateChannel(server_address_.str(), InsecureCredentials());
stub_ = std::move(grpc::cpp::test::util::TestService::NewStub(channel)); stub_ = std::move(grpc::cpp::test::util::TestService::NewStub(channel));
} }
@ -750,8 +750,8 @@ TEST_P(AsyncEnd2endTest, ServerCheckDone) {
} }
TEST_P(AsyncEnd2endTest, UnimplementedRpc) { TEST_P(AsyncEnd2endTest, UnimplementedRpc) {
std::shared_ptr<Channel> channel = CreateChannel( std::shared_ptr<Channel> channel =
server_address_.str(), InsecureCredentials(), ChannelArguments()); CreateChannel(server_address_.str(), InsecureCredentials());
std::unique_ptr<grpc::cpp::test::util::UnimplementedService::Stub> stub; std::unique_ptr<grpc::cpp::test::util::UnimplementedService::Stub> stub;
stub = stub =
std::move(grpc::cpp::test::util::UnimplementedService::NewStub(channel)); std::move(grpc::cpp::test::util::UnimplementedService::NewStub(channel));

@ -76,7 +76,7 @@ class CrashTest : public ::testing::Test {
})); }));
GPR_ASSERT(server_); GPR_ASSERT(server_);
return grpc::cpp::test::util::TestService::NewStub( return grpc::cpp::test::util::TestService::NewStub(
CreateChannel(addr, InsecureCredentials(), ChannelArguments())); CreateChannel(addr, InsecureCredentials()));
} }
void KillServer() { server_.reset(); } void KillServer() { server_.reset(); }

@ -291,8 +291,8 @@ class End2endTest : public ::testing::TestWithParam<bool> {
ChannelArguments args; ChannelArguments args;
args.SetSslTargetNameOverride("foo.test.google.fr"); args.SetSslTargetNameOverride("foo.test.google.fr");
args.SetString(GRPC_ARG_SECONDARY_USER_AGENT_STRING, "end2end_test"); args.SetString(GRPC_ARG_SECONDARY_USER_AGENT_STRING, "end2end_test");
channel_ = channel_ = CreateCustomChannel(server_address_.str(),
CreateChannel(server_address_.str(), SslCredentials(ssl_opts), args); SslCredentials(ssl_opts), args);
} }
void ResetStub(bool use_proxy) { void ResetStub(bool use_proxy) {
@ -307,8 +307,7 @@ class End2endTest : public ::testing::TestWithParam<bool> {
builder.RegisterService(proxy_service_.get()); builder.RegisterService(proxy_service_.get());
proxy_server_ = builder.BuildAndStart(); proxy_server_ = builder.BuildAndStart();
channel_ = CreateChannel(proxyaddr.str(), InsecureCredentials(), channel_ = CreateChannel(proxyaddr.str(), InsecureCredentials());
ChannelArguments());
} }
stub_ = std::move(grpc::cpp::test::util::TestService::NewStub(channel_)); stub_ = std::move(grpc::cpp::test::util::TestService::NewStub(channel_));
@ -566,7 +565,7 @@ TEST_F(End2endTest, BadCredentials) {
std::shared_ptr<Credentials> bad_creds = ServiceAccountCredentials("", "", 1); std::shared_ptr<Credentials> bad_creds = ServiceAccountCredentials("", "", 1);
EXPECT_EQ(static_cast<Credentials*>(nullptr), bad_creds.get()); EXPECT_EQ(static_cast<Credentials*>(nullptr), bad_creds.get());
std::shared_ptr<Channel> channel = std::shared_ptr<Channel> channel =
CreateChannel(server_address_.str(), bad_creds, ChannelArguments()); CreateChannel(server_address_.str(), bad_creds);
std::unique_ptr<grpc::cpp::test::util::TestService::Stub> stub( std::unique_ptr<grpc::cpp::test::util::TestService::Stub> stub(
grpc::cpp::test::util::TestService::NewStub(channel)); grpc::cpp::test::util::TestService::NewStub(channel));
EchoRequest request; EchoRequest request;

@ -121,8 +121,8 @@ class GenericEnd2endTest : public ::testing::Test {
} }
void ResetStub() { void ResetStub() {
std::shared_ptr<Channel> channel = CreateChannel( std::shared_ptr<Channel> channel =
server_address_.str(), InsecureCredentials(), ChannelArguments()); CreateChannel(server_address_.str(), InsecureCredentials());
generic_stub_.reset(new GenericStub(channel)); generic_stub_.reset(new GenericStub(channel));
} }

@ -245,8 +245,8 @@ class MockTest : public ::testing::Test {
void TearDown() GRPC_OVERRIDE { server_->Shutdown(); } void TearDown() GRPC_OVERRIDE { server_->Shutdown(); }
void ResetStub() { void ResetStub() {
std::shared_ptr<Channel> channel = CreateChannel( std::shared_ptr<Channel> channel =
server_address_.str(), InsecureCredentials(), ChannelArguments()); CreateChannel(server_address_.str(), InsecureCredentials());
stub_ = std::move(grpc::cpp::test::util::TestService::NewStub(channel)); stub_ = std::move(grpc::cpp::test::util::TestService::NewStub(channel));
} }

@ -58,8 +58,8 @@ using namespace gflags;
int main(int argc, char** argv) { int main(int argc, char** argv) {
ParseCommandLineFlags(&argc, &argv, true); ParseCommandLineFlags(&argc, &argv, true);
auto stub = grpc::cpp::test::util::TestService::NewStub(grpc::CreateChannel( auto stub = grpc::cpp::test::util::TestService::NewStub(
FLAGS_address, grpc::InsecureCredentials(), grpc::ChannelArguments())); grpc::CreateChannel(FLAGS_address, grpc::InsecureCredentials()));
EchoRequest request; EchoRequest request;
EchoResponse response; EchoResponse response;

@ -95,7 +95,7 @@ class ShutdownTest : public ::testing::Test {
void ResetStub() { void ResetStub() {
string target = "dns:localhost:" + to_string(port_); string target = "dns:localhost:" + to_string(port_);
channel_ = CreateChannel(target, InsecureCredentials(), ChannelArguments()); channel_ = CreateChannel(target, InsecureCredentials());
stub_ = std::move(grpc::cpp::test::util::TestService::NewStub(channel_)); stub_ = std::move(grpc::cpp::test::util::TestService::NewStub(channel_));
} }

@ -191,8 +191,8 @@ class End2endTest : public ::testing::Test {
void TearDown() GRPC_OVERRIDE { server_->Shutdown(); } void TearDown() GRPC_OVERRIDE { server_->Shutdown(); }
void ResetStub() { void ResetStub() {
std::shared_ptr<Channel> channel = CreateChannel( std::shared_ptr<Channel> channel =
server_address_.str(), InsecureCredentials(), ChannelArguments()); CreateChannel(server_address_.str(), InsecureCredentials());
stub_ = std::move(grpc::cpp::test::util::TestService::NewStub(channel)); stub_ = std::move(grpc::cpp::test::util::TestService::NewStub(channel));
} }

@ -159,7 +159,7 @@ class ZookeeperTest : public ::testing::Test {
void ResetStub() { void ResetStub() {
string target = "zookeeper://" + zookeeper_address_ + "/test"; string target = "zookeeper://" + zookeeper_address_ + "/test";
channel_ = CreateChannel(target, InsecureCredentials(), ChannelArguments()); channel_ = CreateChannel(target, InsecureCredentials());
stub_ = std::move(grpc::cpp::test::util::TestService::NewStub(channel_)); stub_ = std::move(grpc::cpp::test::util::TestService::NewStub(channel_));
} }

@ -154,8 +154,8 @@ std::unique_ptr<ScenarioResult> RunScenario(
// where class contained in std::vector must have a copy constructor // where class contained in std::vector must have a copy constructor
auto* servers = new ServerData[num_servers]; auto* servers = new ServerData[num_servers];
for (size_t i = 0; i < num_servers; i++) { for (size_t i = 0; i < num_servers; i++) {
servers[i].stub = std::move(Worker::NewStub( servers[i].stub = std::move(
CreateChannel(workers[i], InsecureCredentials(), ChannelArguments()))); Worker::NewStub(CreateChannel(workers[i], InsecureCredentials())));
ServerArgs args; ServerArgs args;
result_server_config = server_config; result_server_config = server_config;
result_server_config.set_host(workers[i]); result_server_config.set_host(workers[i]);
@ -182,8 +182,8 @@ std::unique_ptr<ScenarioResult> RunScenario(
// where class contained in std::vector must have a copy constructor // where class contained in std::vector must have a copy constructor
auto* clients = new ClientData[num_clients]; auto* clients = new ClientData[num_clients];
for (size_t i = 0; i < num_clients; i++) { for (size_t i = 0; i < num_clients; i++) {
clients[i].stub = std::move(Worker::NewStub(CreateChannel( clients[i].stub = std::move(Worker::NewStub(
workers[i + num_servers], InsecureCredentials(), ChannelArguments()))); CreateChannel(workers[i + num_servers], InsecureCredentials())));
ClientArgs args; ClientArgs args;
result_client_config = client_config; result_client_config = client_config;
result_client_config.set_host(workers[i + num_servers]); result_client_config.set_host(workers[i + num_servers]);

@ -116,8 +116,8 @@ class PerfDbReporter : public Reporter {
test_name_(test_name), test_name_(test_name),
sys_info_(sys_info), sys_info_(sys_info),
tag_(tag) { tag_(tag) {
perf_db_client_.init(grpc::CreateChannel( perf_db_client_.init(
server_address, grpc::InsecureCredentials(), ChannelArguments())); grpc::CreateChannel(server_address, grpc::InsecureCredentials()));
} }
~PerfDbReporter() GRPC_OVERRIDE { SendData(); }; ~PerfDbReporter() GRPC_OVERRIDE { SendData(); };

@ -91,8 +91,7 @@ class CliCallTest : public ::testing::Test {
void TearDown() GRPC_OVERRIDE { server_->Shutdown(); } void TearDown() GRPC_OVERRIDE { server_->Shutdown(); }
void ResetStub() { void ResetStub() {
channel_ = CreateChannel(server_address_.str(), InsecureCredentials(), channel_ = CreateChannel(server_address_.str(), InsecureCredentials());
ChannelArguments());
stub_ = std::move(grpc::cpp::test::util::TestService::NewStub(channel_)); stub_ = std::move(grpc::cpp::test::util::TestService::NewStub(channel_));
} }

@ -74,9 +74,9 @@ std::shared_ptr<Channel> CreateTestChannel(
if (creds.get()) { if (creds.get()) {
channel_creds = CompositeCredentials(creds, channel_creds); channel_creds = CompositeCredentials(creds, channel_creds);
} }
return CreateChannel(connect_to, channel_creds, channel_args); return CreateCustomChannel(connect_to, channel_creds, channel_args);
} else { } else {
return CreateChannel(server, InsecureCredentials(), channel_args); return CreateChannel(server, InsecureCredentials());
} }
} }

@ -159,7 +159,7 @@ int main(int argc, char** argv) {
} }
} }
std::shared_ptr<grpc::Channel> channel = std::shared_ptr<grpc::Channel> channel =
grpc::CreateChannel(server_address, creds, grpc::ChannelArguments()); grpc::CreateChannel(server_address, creds);
grpc::string response; grpc::string response;
std::multimap<grpc::string, grpc::string> client_metadata; std::multimap<grpc::string, grpc::string> client_metadata;

Loading…
Cancel
Save