diff options
Diffstat (limited to 'examples/pubsub')
-rw-r--r-- | examples/pubsub/main.cc | 44 | ||||
-rw-r--r-- | examples/pubsub/publisher.cc | 7 | ||||
-rw-r--r-- | examples/pubsub/publisher_test.cc | 31 | ||||
-rw-r--r-- | examples/pubsub/subscriber.cc | 7 | ||||
-rw-r--r-- | examples/pubsub/subscriber_test.cc | 19 |
5 files changed, 49 insertions, 59 deletions
diff --git a/examples/pubsub/main.cc b/examples/pubsub/main.cc index 6f7737e247..cc5076f0a5 100644 --- a/examples/pubsub/main.cc +++ b/examples/pubsub/main.cc @@ -51,14 +51,14 @@ #include "examples/pubsub/subscriber.h" DEFINE_int32(server_port, 443, "Server port."); -DEFINE_string(server_host, - "pubsub-staging.googleapis.com", "Server host to connect to"); +DEFINE_string(server_host, "pubsub-staging.googleapis.com", + "Server host to connect to"); 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 gflags. This hack is enabling us to find both. -namespace google { } -namespace gflags { } +namespace google {} +namespace gflags {} using namespace google; using namespace gflags; @@ -92,32 +92,32 @@ int main(int argc, char** argv) { grpc::string topic = ss.str(); ss.str(""); - ss << FLAGS_project_id << "/" << kSubscriptionName; + ss << FLAGS_project_id << "/" << kSubscriptionName; grpc::string subscription_name = ss.str(); // Clean up test topic and subcription if they exist before. grpc::string subscription_topic; - if (subscriber.GetSubscription( - subscription_name, &subscription_topic).IsOk()) { + if (subscriber.GetSubscription(subscription_name, &subscription_topic) + .IsOk()) { subscriber.DeleteSubscription(subscription_name); } if (publisher.GetTopic(topic).IsOk()) publisher.DeleteTopic(topic); grpc::Status s = publisher.CreateTopic(topic); - gpr_log(GPR_INFO, "Create topic returns code %d, %s", - s.code(), s.details().c_str()); + gpr_log(GPR_INFO, "Create topic returns code %d, %s", s.code(), + s.details().c_str()); GPR_ASSERT(s.IsOk()); s = publisher.GetTopic(topic); - gpr_log(GPR_INFO, "Get topic returns code %d, %s", - s.code(), s.details().c_str()); + gpr_log(GPR_INFO, "Get topic returns code %d, %s", s.code(), + s.details().c_str()); GPR_ASSERT(s.IsOk()); std::vector<grpc::string> topics; s = publisher.ListTopics(FLAGS_project_id, &topics); - gpr_log(GPR_INFO, "List topic returns code %d, %s", - s.code(), s.details().c_str()); + gpr_log(GPR_INFO, "List topic returns code %d, %s", s.code(), + s.details().c_str()); bool topic_found = false; for (unsigned int i = 0; i < topics.size(); i++) { if (topics[i] == topic) topic_found = true; @@ -127,27 +127,27 @@ int main(int argc, char** argv) { GPR_ASSERT(topic_found); s = subscriber.CreateSubscription(topic, subscription_name); - gpr_log(GPR_INFO, "create subscrption returns code %d, %s", - s.code(), s.details().c_str()); + gpr_log(GPR_INFO, "create subscrption returns code %d, %s", s.code(), + s.details().c_str()); GPR_ASSERT(s.IsOk()); s = publisher.Publish(topic, kMessageData); - gpr_log(GPR_INFO, "Publish %s returns code %d, %s", - kMessageData, s.code(), s.details().c_str()); + gpr_log(GPR_INFO, "Publish %s returns code %d, %s", kMessageData, s.code(), + s.details().c_str()); GPR_ASSERT(s.IsOk()); grpc::string data; s = subscriber.Pull(subscription_name, &data); gpr_log(GPR_INFO, "Pull %s", data.c_str()); - s = subscriber.DeleteSubscription(subscription_name); - gpr_log(GPR_INFO, "Delete subscription returns code %d, %s", - s.code(), s.details().c_str()); + s = subscriber.DeleteSubscription(subscription_name); + gpr_log(GPR_INFO, "Delete subscription returns code %d, %s", s.code(), + s.details().c_str()); GPR_ASSERT(s.IsOk()); s = publisher.DeleteTopic(topic); - gpr_log(GPR_INFO, "Delete topic returns code %d, %s", - s.code(), s.details().c_str()); + gpr_log(GPR_INFO, "Delete topic returns code %d, %s", s.code(), + s.details().c_str()); GPR_ASSERT(s.IsOk()); subscriber.Shutdown(); diff --git a/examples/pubsub/publisher.cc b/examples/pubsub/publisher.cc index 308f9a77e5..458050af73 100644 --- a/examples/pubsub/publisher.cc +++ b/examples/pubsub/publisher.cc @@ -51,12 +51,9 @@ namespace examples { namespace pubsub { Publisher::Publisher(std::shared_ptr<ChannelInterface> channel) - : stub_(PublisherService::NewStub(channel)) { -} + : stub_(PublisherService::NewStub(channel)) {} -void Publisher::Shutdown() { - stub_.reset(); -} +void Publisher::Shutdown() { stub_.reset(); } Status Publisher::CreateTopic(const grpc::string& topic) { Topic request; diff --git a/examples/pubsub/publisher_test.cc b/examples/pubsub/publisher_test.cc index 62442c7384..ac4921283f 100644 --- a/examples/pubsub/publisher_test.cc +++ b/examples/pubsub/publisher_test.cc @@ -31,8 +31,6 @@ * */ -#include <google/protobuf/stubs/common.h> - #include <grpc++/channel_arguments.h> #include <grpc++/channel_interface.h> #include <grpc++/client_context.h> @@ -84,20 +82,19 @@ class PublisherServiceImpl : public tech::pubsub::PublisherService::Service { Status ListTopics( ServerContext* context, const ::tech::pubsub::ListTopicsRequest* request, ::tech::pubsub::ListTopicsResponse* response) GRPC_OVERRIDE { - std::ostringstream ss; - ss << "cloud.googleapis.com/project in (/projects/" << kProjectId << ")"; - EXPECT_EQ(request->query(), ss.str()); - 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); + std::ostringstream ss; + ss << "cloud.googleapis.com/project in (/projects/" << kProjectId << ")"; + EXPECT_EQ(request->query(), ss.str()); + 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; + } }; class PublisherTest : public ::testing::Test { @@ -107,11 +104,13 @@ class PublisherTest : public ::testing::Test { int port = grpc_pick_unused_port_or_die(); server_address_ << "localhost:" << port; ServerBuilder builder; - builder.AddListeningPort(server_address_.str(), grpc::InsecureServerCredentials()); + builder.AddListeningPort(server_address_.str(), + grpc::InsecureServerCredentials()); builder.RegisterService(&service_); 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_)); } diff --git a/examples/pubsub/subscriber.cc b/examples/pubsub/subscriber.cc index 29f6635b7c..d9e0292ba0 100644 --- a/examples/pubsub/subscriber.cc +++ b/examples/pubsub/subscriber.cc @@ -49,12 +49,9 @@ namespace examples { namespace pubsub { Subscriber::Subscriber(std::shared_ptr<ChannelInterface> channel) - : stub_(SubscriberService::NewStub(channel)) { -} + : stub_(SubscriberService::NewStub(channel)) {} -void Subscriber::Shutdown() { - stub_.reset(); -} +void Subscriber::Shutdown() { stub_.reset(); } Status Subscriber::CreateSubscription(const grpc::string& topic, const grpc::string& name) { diff --git a/examples/pubsub/subscriber_test.cc b/examples/pubsub/subscriber_test.cc index b8dd1f9486..9ab60ed6a7 100644 --- a/examples/pubsub/subscriber_test.cc +++ b/examples/pubsub/subscriber_test.cc @@ -31,8 +31,6 @@ * */ -#include <google/protobuf/stubs/common.h> - #include <grpc++/channel_arguments.h> #include <grpc++/channel_interface.h> #include <grpc++/client_context.h> @@ -95,7 +93,6 @@ class SubscriberServiceImpl : public tech::pubsub::SubscriberService::Service { proto2::Empty* response) GRPC_OVERRIDE { return Status::OK; } - }; class SubscriberTest : public ::testing::Test { @@ -105,11 +102,13 @@ class SubscriberTest : public ::testing::Test { int port = grpc_pick_unused_port_or_die(); server_address_ << "localhost:" << port; ServerBuilder builder; - builder.AddListeningPort(server_address_.str(), grpc::InsecureServerCredentials()); + builder.AddListeningPort(server_address_.str(), + grpc::InsecureServerCredentials()); builder.RegisterService(&service_); 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_)); } @@ -129,17 +128,15 @@ class SubscriberTest : public ::testing::Test { }; TEST_F(SubscriberTest, TestSubscriber) { - EXPECT_TRUE(subscriber_->CreateSubscription(kTopic, - kSubscriptionName).IsOk()); + EXPECT_TRUE( + subscriber_->CreateSubscription(kTopic, kSubscriptionName).IsOk()); grpc::string topic; - EXPECT_TRUE(subscriber_->GetSubscription(kSubscriptionName, - &topic).IsOk()); + EXPECT_TRUE(subscriber_->GetSubscription(kSubscriptionName, &topic).IsOk()); EXPECT_EQ(topic, kTopic); grpc::string data; - EXPECT_TRUE(subscriber_->Pull(kSubscriptionName, - &data).IsOk()); + EXPECT_TRUE(subscriber_->Pull(kSubscriptionName, &data).IsOk()); EXPECT_TRUE(subscriber_->DeleteSubscription(kSubscriptionName).IsOk()); } |