Merge pull request #1133 from yang-g/cleanup

clean up
pull/1130/merge
Nicolas Noble 10 years ago
commit 96e32aa0a5
  1. 44
      examples/pubsub/main.cc
  2. 7
      examples/pubsub/publisher.cc
  3. 31
      examples/pubsub/publisher_test.cc
  4. 7
      examples/pubsub/subscriber.cc
  5. 19
      examples/pubsub/subscriber_test.cc
  6. 2
      src/cpp/client/insecure_credentials.cc
  7. 2
      src/cpp/client/secure_credentials.cc
  8. 1
      test/cpp/end2end/async_end2end_test.cc
  9. 1
      test/cpp/end2end/end2end_test.cc
  10. 1
      test/cpp/end2end/generic_end2end_test.cc

@ -51,14 +51,14 @@
#include "examples/pubsub/subscriber.h" #include "examples/pubsub/subscriber.h"
DEFINE_int32(server_port, 443, "Server port."); DEFINE_int32(server_port, 443, "Server port.");
DEFINE_string(server_host, DEFINE_string(server_host, "pubsub-staging.googleapis.com",
"pubsub-staging.googleapis.com", "Server host to connect to"); "Server host to connect to");
DEFINE_string(project_id, "", "GCE project id such as stoked-keyword-656"); DEFINE_string(project_id, "", "GCE project id such as stoked-keyword-656");
// In some distros, gflags is in the namespace google, and in some others, // In some distros, gflags is in the namespace google, and in some others,
// in gflags. This hack is enabling us to find both. // in gflags. This hack is enabling us to find both.
namespace google { } namespace google {}
namespace gflags { } namespace gflags {}
using namespace google; using namespace google;
using namespace gflags; using namespace gflags;
@ -92,32 +92,32 @@ int main(int argc, char** argv) {
grpc::string topic = ss.str(); grpc::string topic = ss.str();
ss.str(""); ss.str("");
ss << FLAGS_project_id << "/" << kSubscriptionName; ss << FLAGS_project_id << "/" << kSubscriptionName;
grpc::string subscription_name = ss.str(); grpc::string subscription_name = ss.str();
// Clean up test topic and subcription if they exist before. // Clean up test topic and subcription if they exist before.
grpc::string subscription_topic; grpc::string subscription_topic;
if (subscriber.GetSubscription( if (subscriber.GetSubscription(subscription_name, &subscription_topic)
subscription_name, &subscription_topic).IsOk()) { .IsOk()) {
subscriber.DeleteSubscription(subscription_name); subscriber.DeleteSubscription(subscription_name);
} }
if (publisher.GetTopic(topic).IsOk()) publisher.DeleteTopic(topic); if (publisher.GetTopic(topic).IsOk()) publisher.DeleteTopic(topic);
grpc::Status s = publisher.CreateTopic(topic); grpc::Status s = publisher.CreateTopic(topic);
gpr_log(GPR_INFO, "Create topic returns code %d, %s", gpr_log(GPR_INFO, "Create topic returns code %d, %s", s.code(),
s.code(), s.details().c_str()); s.details().c_str());
GPR_ASSERT(s.IsOk()); GPR_ASSERT(s.IsOk());
s = publisher.GetTopic(topic); s = publisher.GetTopic(topic);
gpr_log(GPR_INFO, "Get topic returns code %d, %s", gpr_log(GPR_INFO, "Get topic returns code %d, %s", s.code(),
s.code(), s.details().c_str()); s.details().c_str());
GPR_ASSERT(s.IsOk()); GPR_ASSERT(s.IsOk());
std::vector<grpc::string> topics; std::vector<grpc::string> topics;
s = publisher.ListTopics(FLAGS_project_id, &topics); s = publisher.ListTopics(FLAGS_project_id, &topics);
gpr_log(GPR_INFO, "List topic returns code %d, %s", gpr_log(GPR_INFO, "List topic returns code %d, %s", s.code(),
s.code(), s.details().c_str()); s.details().c_str());
bool topic_found = false; bool topic_found = false;
for (unsigned int i = 0; i < topics.size(); i++) { for (unsigned int i = 0; i < topics.size(); i++) {
if (topics[i] == topic) topic_found = true; if (topics[i] == topic) topic_found = true;
@ -127,27 +127,27 @@ int main(int argc, char** argv) {
GPR_ASSERT(topic_found); GPR_ASSERT(topic_found);
s = subscriber.CreateSubscription(topic, subscription_name); s = subscriber.CreateSubscription(topic, subscription_name);
gpr_log(GPR_INFO, "create subscrption returns code %d, %s", gpr_log(GPR_INFO, "create subscrption returns code %d, %s", s.code(),
s.code(), s.details().c_str()); s.details().c_str());
GPR_ASSERT(s.IsOk()); GPR_ASSERT(s.IsOk());
s = publisher.Publish(topic, kMessageData); s = publisher.Publish(topic, kMessageData);
gpr_log(GPR_INFO, "Publish %s returns code %d, %s", gpr_log(GPR_INFO, "Publish %s returns code %d, %s", kMessageData, s.code(),
kMessageData, s.code(), s.details().c_str()); s.details().c_str());
GPR_ASSERT(s.IsOk()); GPR_ASSERT(s.IsOk());
grpc::string data; grpc::string data;
s = subscriber.Pull(subscription_name, &data); s = subscriber.Pull(subscription_name, &data);
gpr_log(GPR_INFO, "Pull %s", data.c_str()); gpr_log(GPR_INFO, "Pull %s", data.c_str());
s = subscriber.DeleteSubscription(subscription_name); s = subscriber.DeleteSubscription(subscription_name);
gpr_log(GPR_INFO, "Delete subscription returns code %d, %s", gpr_log(GPR_INFO, "Delete subscription returns code %d, %s", s.code(),
s.code(), s.details().c_str()); s.details().c_str());
GPR_ASSERT(s.IsOk()); GPR_ASSERT(s.IsOk());
s = publisher.DeleteTopic(topic); s = publisher.DeleteTopic(topic);
gpr_log(GPR_INFO, "Delete topic returns code %d, %s", gpr_log(GPR_INFO, "Delete topic returns code %d, %s", s.code(),
s.code(), s.details().c_str()); s.details().c_str());
GPR_ASSERT(s.IsOk()); GPR_ASSERT(s.IsOk());
subscriber.Shutdown(); subscriber.Shutdown();

@ -51,12 +51,9 @@ namespace examples {
namespace pubsub { namespace pubsub {
Publisher::Publisher(std::shared_ptr<ChannelInterface> channel) Publisher::Publisher(std::shared_ptr<ChannelInterface> channel)
: stub_(PublisherService::NewStub(channel)) { : stub_(PublisherService::NewStub(channel)) {}
}
void Publisher::Shutdown() { void Publisher::Shutdown() { stub_.reset(); }
stub_.reset();
}
Status Publisher::CreateTopic(const grpc::string& topic) { Status Publisher::CreateTopic(const grpc::string& topic) {
Topic request; Topic request;

@ -31,8 +31,6 @@
* *
*/ */
#include <google/protobuf/stubs/common.h>
#include <grpc++/channel_arguments.h> #include <grpc++/channel_arguments.h>
#include <grpc++/channel_interface.h> #include <grpc++/channel_interface.h>
#include <grpc++/client_context.h> #include <grpc++/client_context.h>
@ -84,20 +82,19 @@ class PublisherServiceImpl : public tech::pubsub::PublisherService::Service {
Status ListTopics( Status ListTopics(
ServerContext* context, const ::tech::pubsub::ListTopicsRequest* request, ServerContext* context, const ::tech::pubsub::ListTopicsRequest* request,
::tech::pubsub::ListTopicsResponse* response) GRPC_OVERRIDE { ::tech::pubsub::ListTopicsResponse* response) GRPC_OVERRIDE {
std::ostringstream ss; std::ostringstream ss;
ss << "cloud.googleapis.com/project in (/projects/" << kProjectId << ")"; ss << "cloud.googleapis.com/project in (/projects/" << kProjectId << ")";
EXPECT_EQ(request->query(), ss.str()); EXPECT_EQ(request->query(), ss.str());
response->add_topic()->set_name(kTopic); response->add_topic()->set_name(kTopic);
return Status::OK;
}
Status DeleteTopic(ServerContext* context,
const ::tech::pubsub::DeleteTopicRequest* request,
::proto2::Empty* response) GRPC_OVERRIDE {
EXPECT_EQ(request->topic(), kTopic);
return Status::OK; return Status::OK;
} }
Status DeleteTopic(ServerContext* context,
const ::tech::pubsub::DeleteTopicRequest* request,
::proto2::Empty* response) GRPC_OVERRIDE {
EXPECT_EQ(request->topic(), kTopic);
return Status::OK;
}
}; };
class PublisherTest : public ::testing::Test { class PublisherTest : public ::testing::Test {
@ -107,11 +104,13 @@ class PublisherTest : public ::testing::Test {
int port = grpc_pick_unused_port_or_die(); int port = grpc_pick_unused_port_or_die();
server_address_ << "localhost:" << port; server_address_ << "localhost:" << port;
ServerBuilder builder; ServerBuilder builder;
builder.AddListeningPort(server_address_.str(), grpc::InsecureServerCredentials()); builder.AddListeningPort(server_address_.str(),
grpc::InsecureServerCredentials());
builder.RegisterService(&service_); builder.RegisterService(&service_);
server_ = builder.BuildAndStart(); server_ = builder.BuildAndStart();
channel_ = CreateChannel(server_address_.str(), grpc::InsecureCredentials(), ChannelArguments()); channel_ = CreateChannel(server_address_.str(), grpc::InsecureCredentials(),
ChannelArguments());
publisher_.reset(new grpc::examples::pubsub::Publisher(channel_)); publisher_.reset(new grpc::examples::pubsub::Publisher(channel_));
} }

@ -49,12 +49,9 @@ namespace examples {
namespace pubsub { namespace pubsub {
Subscriber::Subscriber(std::shared_ptr<ChannelInterface> channel) Subscriber::Subscriber(std::shared_ptr<ChannelInterface> channel)
: stub_(SubscriberService::NewStub(channel)) { : stub_(SubscriberService::NewStub(channel)) {}
}
void Subscriber::Shutdown() { void Subscriber::Shutdown() { stub_.reset(); }
stub_.reset();
}
Status Subscriber::CreateSubscription(const grpc::string& topic, Status Subscriber::CreateSubscription(const grpc::string& topic,
const grpc::string& name) { const grpc::string& name) {

@ -31,8 +31,6 @@
* *
*/ */
#include <google/protobuf/stubs/common.h>
#include <grpc++/channel_arguments.h> #include <grpc++/channel_arguments.h>
#include <grpc++/channel_interface.h> #include <grpc++/channel_interface.h>
#include <grpc++/client_context.h> #include <grpc++/client_context.h>
@ -95,7 +93,6 @@ class SubscriberServiceImpl : public tech::pubsub::SubscriberService::Service {
proto2::Empty* response) GRPC_OVERRIDE { proto2::Empty* response) GRPC_OVERRIDE {
return Status::OK; return Status::OK;
} }
}; };
class SubscriberTest : public ::testing::Test { class SubscriberTest : public ::testing::Test {
@ -105,11 +102,13 @@ class SubscriberTest : public ::testing::Test {
int port = grpc_pick_unused_port_or_die(); int port = grpc_pick_unused_port_or_die();
server_address_ << "localhost:" << port; server_address_ << "localhost:" << port;
ServerBuilder builder; ServerBuilder builder;
builder.AddListeningPort(server_address_.str(), grpc::InsecureServerCredentials()); builder.AddListeningPort(server_address_.str(),
grpc::InsecureServerCredentials());
builder.RegisterService(&service_); builder.RegisterService(&service_);
server_ = builder.BuildAndStart(); server_ = builder.BuildAndStart();
channel_ = CreateChannel(server_address_.str(), grpc::InsecureCredentials(), ChannelArguments()); channel_ = CreateChannel(server_address_.str(), grpc::InsecureCredentials(),
ChannelArguments());
subscriber_.reset(new grpc::examples::pubsub::Subscriber(channel_)); subscriber_.reset(new grpc::examples::pubsub::Subscriber(channel_));
} }
@ -129,17 +128,15 @@ class SubscriberTest : public ::testing::Test {
}; };
TEST_F(SubscriberTest, TestSubscriber) { TEST_F(SubscriberTest, TestSubscriber) {
EXPECT_TRUE(subscriber_->CreateSubscription(kTopic, EXPECT_TRUE(
kSubscriptionName).IsOk()); subscriber_->CreateSubscription(kTopic, kSubscriptionName).IsOk());
grpc::string topic; grpc::string topic;
EXPECT_TRUE(subscriber_->GetSubscription(kSubscriptionName, EXPECT_TRUE(subscriber_->GetSubscription(kSubscriptionName, &topic).IsOk());
&topic).IsOk());
EXPECT_EQ(topic, kTopic); EXPECT_EQ(topic, kTopic);
grpc::string data; grpc::string data;
EXPECT_TRUE(subscriber_->Pull(kSubscriptionName, EXPECT_TRUE(subscriber_->Pull(kSubscriptionName, &data).IsOk());
&data).IsOk());
EXPECT_TRUE(subscriber_->DeleteSubscription(kSubscriptionName).IsOk()); EXPECT_TRUE(subscriber_->DeleteSubscription(kSubscriptionName).IsOk());
} }

@ -31,8 +31,6 @@
* *
*/ */
#include <string>
#include <grpc/grpc.h> #include <grpc/grpc.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>

@ -31,8 +31,6 @@
* *
*/ */
#include <string>
#include <grpc/grpc_security.h> #include <grpc/grpc_security.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>

@ -595,6 +595,5 @@ int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv); ::testing::InitGoogleTest(&argc, argv);
int result = RUN_ALL_TESTS(); int result = RUN_ALL_TESTS();
grpc_shutdown(); grpc_shutdown();
google::protobuf::ShutdownProtobufLibrary();
return result; return result;
} }

@ -432,6 +432,5 @@ int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv); ::testing::InitGoogleTest(&argc, argv);
int result = RUN_ALL_TESTS(); int result = RUN_ALL_TESTS();
grpc_shutdown(); grpc_shutdown();
google::protobuf::ShutdownProtobufLibrary();
return result; return result;
} }

@ -265,6 +265,5 @@ int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv); ::testing::InitGoogleTest(&argc, argv);
int result = RUN_ALL_TESTS(); int result = RUN_ALL_TESTS();
grpc_shutdown(); grpc_shutdown();
google::protobuf::ShutdownProtobufLibrary();
return result; return result;
} }

Loading…
Cancel
Save