Class: NamedActions
- Inherits:
-
Object
- Object
- NamedActions
- Includes:
- Tech::Pubsub
- Defined in:
- src/ruby/bin/apis/pubsub_demo.rb
Overview
defines methods corresponding to each interop test case.
Constant Summary
Constants included from Tech::Pubsub
Tech::Pubsub::AcknowledgeRequest, Tech::Pubsub::DeleteSubscriptionRequest, Tech::Pubsub::DeleteTopicRequest, Tech::Pubsub::GetSubscriptionRequest, Tech::Pubsub::GetTopicRequest, Tech::Pubsub::ListSubscriptionsRequest, Tech::Pubsub::ListSubscriptionsResponse, Tech::Pubsub::ListTopicsRequest, Tech::Pubsub::ListTopicsResponse, Tech::Pubsub::ModifyAckDeadlineRequest, Tech::Pubsub::ModifyPushConfigRequest, Tech::Pubsub::NackRequest, Tech::Pubsub::PublishBatchRequest, Tech::Pubsub::PublishBatchResponse, Tech::Pubsub::PublishRequest, Tech::Pubsub::PubsubEvent, Tech::Pubsub::PubsubMessage, Tech::Pubsub::PullBatchRequest, Tech::Pubsub::PullBatchResponse, Tech::Pubsub::PullRequest, Tech::Pubsub::PullResponse, Tech::Pubsub::PushConfig, Tech::Pubsub::Subscription, Tech::Pubsub::Topic, Tech::Pubsub::TruncateSubscriptionRequest
Instance Method Summary collapse
-
#check_exists ⇒ Object
Checks if a topics exists in a project.
-
#create_topic ⇒ Object
Creates a test topic.
-
#initialize(pub, sub, args) ⇒ NamedActions
constructor
Initializes NamedActions.
-
#list_some_topics ⇒ Object
Lists topics in the project.
-
#random_pub_sub ⇒ Object
Publishes some messages.
-
#remove_topic ⇒ Object
Removes the test topic if it exists.
Constructor Details
#initialize(pub, sub, args) ⇒ NamedActions
Initializes NamedActions
84 85 86 87 88 |
# File 'src/ruby/bin/apis/pubsub_demo.rb', line 84 def initialize(pub, sub, args) @pub = pub @sub = sub @args = args end |
Instance Method Details
#check_exists ⇒ Object
Checks if a topics exists in a project
120 121 122 123 124 125 126 127 128 |
# File 'src/ruby/bin/apis/pubsub_demo.rb', line 120 def check_exists name = test_topic_name p "... checking for topic #{name}" exists = topic_exists?(name) p "#{name} is a topic" if exists p "#{name} is not a topic" unless exists rescue GRPC::BadStatus => e p "Could not check for a topics: rpc failed with '#{e}'" end |
#create_topic ⇒ Object
Creates a test topic
101 102 103 104 105 106 107 108 |
# File 'src/ruby/bin/apis/pubsub_demo.rb', line 101 def create_topic name = test_topic_name p "... creating Topic #{name}" resp = @pub.create_topic(Topic.new(name: name)) p "created Topic: #{resp.name} OK" rescue GRPC::BadStatus => e p "Could not create a topics: rpc failed with '#{e}'" end |
#list_some_topics ⇒ Object
Lists topics in the project
111 112 113 114 115 116 117 |
# File 'src/ruby/bin/apis/pubsub_demo.rb', line 111 def list_some_topics p 'Listing topics' p '-------------_' list_project_topics.topic.each { |t| p t.name } rescue GRPC::BadStatus => e p "Could not list topics: rpc failed with '#{e}'" end |
#random_pub_sub ⇒ Object
Publishes some messages
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'src/ruby/bin/apis/pubsub_demo.rb', line 131 def random_pub_sub topic_name, sub_name = test_topic_name, test_sub_name create_topic_if_needed(topic_name) @sub.create_subscription(Subscription.new(name: sub_name, topic: topic_name)) msg_count = rand(10..30) msg_count.times do |x| msg = PubsubMessage.new(data: "message #{x}") @pub.publish(PublishRequest.new(topic: topic_name, message: msg)) end p "Sent #{msg_count} messages to #{topic_name}, checking for them now." batch = @sub.pull_batch(PullBatchRequest.new(subscription: sub_name, max_events: msg_count)) ack_ids = batch.pull_responses.map { |x| x.ack_id } p "Got #{ack_ids.size} messages; acknowledging them.." @sub.acknowledge(AcknowledgeRequest.new(subscription: sub_name, ack_id: ack_ids)) p "Test messages were acknowledged OK, deleting the subscription" del_req = DeleteSubscriptionRequest.new(subscription: sub_name) @sub.delete_subscription(del_req) rescue GRPC::BadStatus => e p "Could not do random pub sub: rpc failed with '#{e}'" end |
#remove_topic ⇒ Object
Removes the test topic if it exists
91 92 93 94 95 96 97 98 |
# File 'src/ruby/bin/apis/pubsub_demo.rb', line 91 def remove_topic name = test_topic_name p "... removing Topic #{name}" @pub.delete_topic(DeleteTopicRequest.new(topic: name)) p "removed Topic: #{name} OK" rescue GRPC::BadStatus => e p "Could not delete a topics: rpc failed with '#{e}'" end |