aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Stanley Cheung <stanleycheung@google.com>2015-08-27 14:40:38 -0700
committerGravatar Stanley Cheung <stanleycheung@google.com>2015-08-27 14:40:38 -0700
commit23b371214154233153e95478f31f7b83dc850360 (patch)
treecbe026b6ba1d79ad4ed4f5190265813f0f740130
parent0a268216c2c8e112351b7ed038da04bf50b9eb5a (diff)
remove examples/pubsub
-rw-r--r--examples/pubsub/README22
-rw-r--r--examples/pubsub/main.cc146
-rw-r--r--examples/pubsub/publisher.cc121
-rw-r--r--examples/pubsub/publisher.h66
-rw-r--r--examples/pubsub/publisher_test.cc153
-rw-r--r--examples/pubsub/subscriber.cc115
-rw-r--r--examples/pubsub/subscriber.h67
-rw-r--r--examples/pubsub/subscriber_test.cc152
8 files changed, 0 insertions, 842 deletions
diff --git a/examples/pubsub/README b/examples/pubsub/README
deleted file mode 100644
index 36fcb08483..0000000000
--- a/examples/pubsub/README
+++ /dev/null
@@ -1,22 +0,0 @@
-NOTE: This example does not build and is being updated.
-Experimental example code, likely to change.
-Users should not attempt to run this code till this warning is removed.
-
-C++ Client implementation for Cloud Pub/Sub service
-(https://developers.google.com/apis-explorer/#p/pubsub/v1beta1/).
-
-"Google Cloud Pub/Sub" API needs to be enabled at
-https://console.developers.google.com/project to open the access for a client.
-Select the project name, select the "APIs" under "APIs & auth", and turn
-on "Google Cloud Pub/Sub" API.
-
-To run the client from Google Compute Engine (GCE), the GCE instance needs to
-be created with scope "https://www.googleapis.com/auth/cloud-platform" as below:
-
-gcloud compute instances create instance-name
- --image debian-7 --scopes https://www.googleapis.com/auth/cloud-platform
-
-
-To run the client:
-make pubsub_client
-bins/opt/pubsub_client --project_id="your project id"
diff --git a/examples/pubsub/main.cc b/examples/pubsub/main.cc
deleted file mode 100644
index 32102dcb5c..0000000000
--- a/examples/pubsub/main.cc
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- *
- * Copyright 2015, 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 <fstream>
-#include <memory>
-#include <sstream>
-#include <string>
-#include <thread>
-
-#include <gflags/gflags.h>
-#include <grpc/grpc.h>
-#include <grpc/support/log.h>
-#include <grpc++/channel.h>
-#include <grpc++/create_channel.h>
-#include <grpc++/credentials.h>
-
-#include "examples/pubsub/publisher.h"
-#include "examples/pubsub/subscriber.h"
-#include "test/cpp/util/test_config.h"
-
-DEFINE_int32(server_port, 443, "Server port.");
-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");
-
-namespace {
-
-const char kTopic[] = "testtopics";
-const char kSubscriptionName[] = "testsubscription";
-const char kMessageData[] = "Test Data";
-
-} // namespace
-
-int main(int argc, char** argv) {
- grpc::testing::InitTest(&argc, &argv, true);
- gpr_log(GPR_INFO, "Start PUBSUB client");
-
- std::ostringstream ss;
-
- ss << FLAGS_server_host << ":" << FLAGS_server_port;
-
- std::shared_ptr<grpc::Credentials> creds = grpc::GoogleDefaultCredentials();
- std::shared_ptr<grpc::Channel> channel =
- grpc::CreateChannel(ss.str(), creds, grpc::ChannelArguments());
-
- grpc::examples::pubsub::Publisher publisher(channel);
- grpc::examples::pubsub::Subscriber subscriber(channel);
-
- GPR_ASSERT(FLAGS_project_id != "");
- ss.str("");
- ss << "/topics/" << FLAGS_project_id << "/" << kTopic;
- grpc::string topic = ss.str();
-
- ss.str("");
- 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()) {
- 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_ASSERT(s.IsOk());
-
- s = publisher.GetTopic(topic);
- 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());
- bool topic_found = false;
- for (unsigned int i = 0; i < topics.size(); i++) {
- if (topics[i] == topic) topic_found = true;
- gpr_log(GPR_INFO, "topic: %s", topics[i].c_str());
- }
- GPR_ASSERT(s.IsOk());
- 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_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_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());
- 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_ASSERT(s.IsOk());
-
- subscriber.Shutdown();
- publisher.Shutdown();
- return 0;
-}
diff --git a/examples/pubsub/publisher.cc b/examples/pubsub/publisher.cc
deleted file mode 100644
index fd38ca92ed..0000000000
--- a/examples/pubsub/publisher.cc
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- *
- * Copyright 2015, 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 <sstream>
-
-#include <grpc++/client_context.h>
-
-#include "examples/pubsub/publisher.h"
-
-using tech::pubsub::Topic;
-using tech::pubsub::DeleteTopicRequest;
-using tech::pubsub::GetTopicRequest;
-using tech::pubsub::PublisherService;
-using tech::pubsub::ListTopicsRequest;
-using tech::pubsub::ListTopicsResponse;
-using tech::pubsub::PublishRequest;
-using tech::pubsub::PubsubMessage;
-
-namespace grpc {
-namespace examples {
-namespace pubsub {
-
-Publisher::Publisher(std::shared_ptr<Channel> channel)
- : stub_(PublisherService::NewStub(channel)) {}
-
-void Publisher::Shutdown() { stub_.reset(); }
-
-Status Publisher::CreateTopic(const grpc::string& topic) {
- Topic request;
- Topic response;
- request.set_name(topic);
- ClientContext context;
-
- return stub_->CreateTopic(&context, request, &response);
-}
-
-Status Publisher::ListTopics(const grpc::string& project_id,
- std::vector<grpc::string>* topics) {
- ListTopicsRequest request;
- ListTopicsResponse response;
- ClientContext context;
-
- std::ostringstream ss;
- ss << "cloud.googleapis.com/project in (/projects/" << project_id << ")";
- request.set_query(ss.str());
-
- Status s = stub_->ListTopics(&context, request, &response);
-
- tech::pubsub::Topic topic;
- for (int i = 0; i < response.topic_size(); i++) {
- topic = response.topic(i);
- topics->push_back(topic.name());
- }
-
- return s;
-}
-
-Status Publisher::GetTopic(const grpc::string& topic) {
- GetTopicRequest request;
- Topic response;
- ClientContext context;
-
- request.set_topic(topic);
-
- return stub_->GetTopic(&context, request, &response);
-}
-
-Status Publisher::DeleteTopic(const grpc::string& topic) {
- DeleteTopicRequest request;
- proto2::Empty response;
- ClientContext context;
-
- request.set_topic(topic);
-
- return stub_->DeleteTopic(&context, request, &response);
-}
-
-Status Publisher::Publish(const grpc::string& topic, const grpc::string& data) {
- PublishRequest request;
- proto2::Empty response;
- ClientContext context;
-
- request.mutable_message()->set_data(data);
- request.set_topic(topic);
-
- return stub_->Publish(&context, request, &response);
-}
-
-} // namespace pubsub
-} // namespace examples
-} // namespace grpc
diff --git a/examples/pubsub/publisher.h b/examples/pubsub/publisher.h
deleted file mode 100644
index 02e6194b0b..0000000000
--- a/examples/pubsub/publisher.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- *
- * Copyright 2015, 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.
- *
- */
-
-#ifndef GRPC_EXAMPLES_PUBSUB_PUBLISHER_H
-#define GRPC_EXAMPLES_PUBSUB_PUBLISHER_H
-
-#include <grpc++/channel.h>
-
-#include "examples/pubsub/pubsub.grpc.pb.h"
-
-namespace grpc {
-namespace examples {
-namespace pubsub {
-
-class Publisher {
- public:
- Publisher(std::shared_ptr<Channel> channel);
- void Shutdown();
-
- Status CreateTopic(const grpc::string& topic);
- Status GetTopic(const grpc::string& topic);
- Status DeleteTopic(const grpc::string& topic);
- Status ListTopics(const grpc::string& project_id,
- std::vector<grpc::string>* topics);
-
- Status Publish(const grpc::string& topic, const grpc::string& data);
-
- private:
- std::unique_ptr<tech::pubsub::PublisherService::Stub> stub_;
-};
-
-} // namespace pubsub
-} // namespace examples
-} // namespace grpc
-
-#endif // GRPC_EXAMPLES_PUBSUB_PUBLISHER_H
diff --git a/examples/pubsub/publisher_test.cc b/examples/pubsub/publisher_test.cc
deleted file mode 100644
index c2eb295ef2..0000000000
--- a/examples/pubsub/publisher_test.cc
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- *
- * Copyright 2015, 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.h>
-#include <grpc++/client_context.h>
-#include <grpc++/create_channel.h>
-#include <grpc++/server.h>
-#include <grpc++/server_builder.h>
-#include <grpc++/server_context.h>
-#include <grpc++/server_credentials.h>
-#include <gtest/gtest.h>
-
-#include "examples/pubsub/publisher.h"
-#include "test/core/util/port.h"
-#include "test/core/util/test_config.h"
-
-using grpc::Channel;
-
-namespace grpc {
-namespace testing {
-namespace {
-
-const char kProjectId[] = "project id";
-const char kTopic[] = "test topic";
-const char kMessageData[] = "test message data";
-
-class PublisherServiceImpl : public tech::pubsub::PublisherService::Service {
- public:
- Status CreateTopic(::grpc::ServerContext* context,
- const ::tech::pubsub::Topic* request,
- ::tech::pubsub::Topic* response) GRPC_OVERRIDE {
- EXPECT_EQ(request->name(), kTopic);
- return Status::OK;
- }
-
- Status Publish(ServerContext* context,
- const ::tech::pubsub::PublishRequest* request,
- ::proto2::Empty* response) GRPC_OVERRIDE {
- EXPECT_EQ(request->message().data(), kMessageData);
- return Status::OK;
- }
-
- Status GetTopic(ServerContext* context,
- const ::tech::pubsub::GetTopicRequest* request,
- ::tech::pubsub::Topic* response) GRPC_OVERRIDE {
- EXPECT_EQ(request->topic(), kTopic);
- return Status::OK;
- }
-
- 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);
- return Status::OK;
- }
-};
-
-class PublisherTest : public ::testing::Test {
- protected:
- // Setup a server and a client for PublisherService.
- void SetUp() GRPC_OVERRIDE {
- int port = grpc_pick_unused_port_or_die();
- server_address_ << "localhost:" << port;
- ServerBuilder builder;
- builder.AddListeningPort(server_address_.str(),
- grpc::InsecureServerCredentials());
- builder.RegisterService(&service_);
- server_ = builder.BuildAndStart();
-
- channel_ = CreateChannel(server_address_.str(), grpc::InsecureCredentials(),
- ChannelArguments());
-
- publisher_.reset(new grpc::examples::pubsub::Publisher(channel_));
- }
-
- void TearDown() GRPC_OVERRIDE {
- server_->Shutdown();
- publisher_->Shutdown();
- }
-
- std::ostringstream server_address_;
- std::unique_ptr<Server> server_;
- PublisherServiceImpl service_;
-
- std::shared_ptr<Channel> channel_;
-
- std::unique_ptr<grpc::examples::pubsub::Publisher> publisher_;
-};
-
-TEST_F(PublisherTest, TestPublisher) {
- EXPECT_TRUE(publisher_->CreateTopic(kTopic).IsOk());
-
- EXPECT_TRUE(publisher_->Publish(kTopic, kMessageData).IsOk());
-
- EXPECT_TRUE(publisher_->GetTopic(kTopic).IsOk());
-
- std::vector<grpc::string> topics;
- EXPECT_TRUE(publisher_->ListTopics(kProjectId, &topics).IsOk());
- EXPECT_EQ(topics.size(), static_cast<size_t>(1));
- EXPECT_EQ(topics[0], kTopic);
-}
-
-} // namespace
-} // namespace testing
-} // namespace grpc
-
-int main(int argc, char** argv) {
- grpc_test_init(argc, argv);
- ::testing::InitGoogleTest(&argc, argv);
- gpr_log(GPR_INFO, "Start test ...");
- int result = RUN_ALL_TESTS();
- return result;
-}
diff --git a/examples/pubsub/subscriber.cc b/examples/pubsub/subscriber.cc
deleted file mode 100644
index 0818f501db..0000000000
--- a/examples/pubsub/subscriber.cc
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- *
- * Copyright 2015, 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++/client_context.h>
-
-#include "examples/pubsub/subscriber.h"
-
-using tech::pubsub::Topic;
-using tech::pubsub::DeleteTopicRequest;
-using tech::pubsub::GetTopicRequest;
-using tech::pubsub::SubscriberService;
-using tech::pubsub::ListTopicsRequest;
-using tech::pubsub::ListTopicsResponse;
-using tech::pubsub::PublishRequest;
-using tech::pubsub::PubsubMessage;
-
-namespace grpc {
-namespace examples {
-namespace pubsub {
-
-Subscriber::Subscriber(std::shared_ptr<Channel> channel)
- : stub_(SubscriberService::NewStub(channel)) {}
-
-void Subscriber::Shutdown() { stub_.reset(); }
-
-Status Subscriber::CreateSubscription(const grpc::string& topic,
- const grpc::string& name) {
- tech::pubsub::Subscription request;
- tech::pubsub::Subscription response;
- ClientContext context;
-
- request.set_topic(topic);
- request.set_name(name);
-
- return stub_->CreateSubscription(&context, request, &response);
-}
-
-Status Subscriber::GetSubscription(const grpc::string& name,
- grpc::string* topic) {
- tech::pubsub::GetSubscriptionRequest request;
- tech::pubsub::Subscription response;
- ClientContext context;
-
- request.set_subscription(name);
-
- Status s = stub_->GetSubscription(&context, request, &response);
- *topic = response.topic();
- return s;
-}
-
-Status Subscriber::DeleteSubscription(const grpc::string& name) {
- tech::pubsub::DeleteSubscriptionRequest request;
- proto2::Empty response;
- ClientContext context;
-
- request.set_subscription(name);
-
- return stub_->DeleteSubscription(&context, request, &response);
-}
-
-Status Subscriber::Pull(const grpc::string& name, grpc::string* data) {
- tech::pubsub::PullRequest request;
- tech::pubsub::PullResponse response;
- ClientContext context;
-
- request.set_subscription(name);
- Status s = stub_->Pull(&context, request, &response);
- if (s.IsOk()) {
- tech::pubsub::PubsubEvent event = response.pubsub_event();
- if (event.has_message()) {
- *data = event.message().data();
- }
- tech::pubsub::AcknowledgeRequest ack;
- proto2::Empty empty;
- ClientContext ack_context;
- ack.set_subscription(name);
- ack.add_ack_id(response.ack_id());
- stub_->Acknowledge(&ack_context, ack, &empty);
- }
- return s;
-}
-
-} // namespace pubsub
-} // namespace examples
-} // namespace grpc
diff --git a/examples/pubsub/subscriber.h b/examples/pubsub/subscriber.h
deleted file mode 100644
index c5b1df0d3e..0000000000
--- a/examples/pubsub/subscriber.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- *
- * Copyright 2015, 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.
- *
- */
-
-#ifndef GRPC_EXAMPLES_PUBSUB_SUBSCRIBER_H
-#define GRPC_EXAMPLES_PUBSUB_SUBSCRIBER_H
-
-#include <grpc++/channel.h>
-
-#include "examples/pubsub/pubsub.grpc.pb.h"
-
-namespace grpc {
-namespace examples {
-namespace pubsub {
-
-class Subscriber {
- public:
- Subscriber(std::shared_ptr<Channel> channel);
- void Shutdown();
-
- Status CreateSubscription(const grpc::string& topic,
- const grpc::string& name);
-
- Status GetSubscription(const grpc::string& name, grpc::string* topic);
-
- Status DeleteSubscription(const grpc::string& name);
-
- Status Pull(const grpc::string& name, grpc::string* data);
-
- private:
- std::unique_ptr<tech::pubsub::SubscriberService::Stub> stub_;
-};
-
-} // namespace pubsub
-} // namespace examples
-} // namespace grpc
-
-#endif // GRPC_EXAMPLES_PUBSUB_SUBSCRIBER_H
diff --git a/examples/pubsub/subscriber_test.cc b/examples/pubsub/subscriber_test.cc
deleted file mode 100644
index c5a077f407..0000000000
--- a/examples/pubsub/subscriber_test.cc
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- *
- * Copyright 2015, 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.h>
-#include <grpc++/client_context.h>
-#include <grpc++/create_channel.h>
-#include <grpc++/server.h>
-#include <grpc++/server_builder.h>
-#include <grpc++/server_context.h>
-#include <grpc++/server_credentials.h>
-#include <gtest/gtest.h>
-
-#include "examples/pubsub/subscriber.h"
-#include "test/core/util/port.h"
-#include "test/core/util/test_config.h"
-
-namespace grpc {
-namespace testing {
-namespace {
-
-const char kTopic[] = "test topic";
-const char kSubscriptionName[] = "subscription name";
-const char kData[] = "Message data";
-
-class SubscriberServiceImpl : public tech::pubsub::SubscriberService::Service {
- public:
- Status CreateSubscription(
- ServerContext* context, const tech::pubsub::Subscription* request,
- tech::pubsub::Subscription* response) GRPC_OVERRIDE {
- EXPECT_EQ(request->topic(), kTopic);
- EXPECT_EQ(request->name(), kSubscriptionName);
- return Status::OK;
- }
-
- Status GetSubscription(ServerContext* context,
- const tech::pubsub::GetSubscriptionRequest* request,
- tech::pubsub::Subscription* response) GRPC_OVERRIDE {
- EXPECT_EQ(request->subscription(), kSubscriptionName);
- response->set_topic(kTopic);
- return Status::OK;
- }
-
- Status DeleteSubscription(
- ServerContext* context,
- const tech::pubsub::DeleteSubscriptionRequest* request,
- proto2::Empty* response) GRPC_OVERRIDE {
- EXPECT_EQ(request->subscription(), kSubscriptionName);
- return Status::OK;
- }
-
- Status Pull(ServerContext* context, const tech::pubsub::PullRequest* request,
- tech::pubsub::PullResponse* response) GRPC_OVERRIDE {
- EXPECT_EQ(request->subscription(), kSubscriptionName);
- response->set_ack_id("1");
- response->mutable_pubsub_event()->mutable_message()->set_data(kData);
- return Status::OK;
- }
-
- Status Acknowledge(ServerContext* context,
- const tech::pubsub::AcknowledgeRequest* request,
- proto2::Empty* response) GRPC_OVERRIDE {
- return Status::OK;
- }
-};
-
-class SubscriberTest : public ::testing::Test {
- protected:
- // Setup a server and a client for SubscriberService.
- void SetUp() GRPC_OVERRIDE {
- int port = grpc_pick_unused_port_or_die();
- server_address_ << "localhost:" << port;
- ServerBuilder builder;
- builder.AddListeningPort(server_address_.str(),
- grpc::InsecureServerCredentials());
- builder.RegisterService(&service_);
- server_ = builder.BuildAndStart();
-
- channel_ = CreateChannel(server_address_.str(), grpc::InsecureCredentials(),
- ChannelArguments());
-
- subscriber_.reset(new grpc::examples::pubsub::Subscriber(channel_));
- }
-
- void TearDown() GRPC_OVERRIDE {
- server_->Shutdown();
- subscriber_->Shutdown();
- }
-
- std::ostringstream server_address_;
- std::unique_ptr<Server> server_;
- SubscriberServiceImpl service_;
-
- std::shared_ptr<Channel> channel_;
-
- std::unique_ptr<grpc::examples::pubsub::Subscriber> subscriber_;
-};
-
-TEST_F(SubscriberTest, TestSubscriber) {
- EXPECT_TRUE(
- subscriber_->CreateSubscription(kTopic, kSubscriptionName).IsOk());
-
- grpc::string topic;
- EXPECT_TRUE(subscriber_->GetSubscription(kSubscriptionName, &topic).IsOk());
- EXPECT_EQ(topic, kTopic);
-
- grpc::string data;
- EXPECT_TRUE(subscriber_->Pull(kSubscriptionName, &data).IsOk());
-
- EXPECT_TRUE(subscriber_->DeleteSubscription(kSubscriptionName).IsOk());
-}
-
-} // namespace
-} // namespace testing
-} // namespace grpc
-
-int main(int argc, char** argv) {
- grpc_test_init(argc, argv);
- ::testing::InitGoogleTest(&argc, argv);
- gpr_log(GPR_INFO, "Start test ...");
- int result = RUN_ALL_TESTS();
- return result;
-}