From 332b2f082f970fc03f776efaf2f26e5a52be9db9 Mon Sep 17 00:00:00 2001 From: Mike Moore Date: Thu, 13 Dec 2018 16:20:30 -0700 Subject: [PATCH] Update Pub/Sub reference/resource documentation (#2725) * Add reference?/resource? helper methods * Topic#reference? * Topic#resource? * Subscription#reference? * Subscription#resource? * Add documentation for methods that will make an API call when called on a reference object. * Topic#labels * Subscription#topic * Subscription#deadline * Subscription#retain_acked * Subscription#retention * Subscription#endpoint * Subscription#labels * Subscription#exists? * Subscription#listen (without deadline optional argument) * Add example code for avoiding API calls to Overview guide. --- google-cloud-pubsub/OVERVIEW.md | 38 ++++ .../acceptance/pubsub/pubsub_test.rb | 2 +- .../lib/google/cloud/pubsub/project.rb | 4 +- .../lib/google/cloud/pubsub/snapshot.rb | 2 +- .../lib/google/cloud/pubsub/subscription.rb | 165 +++++++++++++----- .../google/cloud/pubsub/subscription/list.rb | 2 +- .../lib/google/cloud/pubsub/topic.rb | 70 +++++--- .../test/google/cloud/pubsub/message_test.rb | 3 +- .../test/google/cloud/pubsub/project_test.rb | 54 ++++-- .../cloud/pubsub/received_message_test.rb | 3 +- .../test/google/cloud/pubsub/snapshot_test.rb | 3 +- .../pubsub/subscription/acknowledge_test.rb | 8 +- .../cloud/pubsub/subscription/attrs_test.rb | 14 +- .../cloud/pubsub/subscription/delete_test.rb | 8 +- .../cloud/pubsub/subscription/exists_test.rb | 8 +- .../cloud/pubsub/subscription/lazy_test.rb | 15 +- .../subscription/modify_ack_deadline_test.rb | 8 +- .../cloud/pubsub/subscription/name_test.rb | 8 +- .../cloud/pubsub/subscription/pull_test.rb | 8 +- .../cloud/pubsub/subscription/seek_test.rb | 8 +- .../cloud/pubsub/subscription/update_test.rb | 49 +++--- .../google/cloud/pubsub/subscription_test.rb | 3 +- .../cloud/pubsub/topic/autocreate_test.rb | 20 +-- .../google/cloud/pubsub/topic/exists_test.rb | 13 +- .../google/cloud/pubsub/topic/lazy_test.rb | 10 +- .../google/cloud/pubsub/topic/name_test.rb | 3 +- .../google/cloud/pubsub/topic/policy_test.rb | 3 +- .../cloud/pubsub/topic/publish_async_test.rb | 11 +- .../google/cloud/pubsub/topic/publish_test.rb | 13 +- .../cloud/pubsub/topic/subscribe_test.rb | 13 +- .../cloud/pubsub/topic/subscription_test.rb | 28 +-- .../cloud/pubsub/topic/subscriptions_test.rb | 19 +- .../google/cloud/pubsub/topic/update_test.rb | 10 +- .../test/google/cloud/pubsub/topic_test.rb | 54 ++++-- 34 files changed, 428 insertions(+), 252 deletions(-) diff --git a/google-cloud-pubsub/OVERVIEW.md b/google-cloud-pubsub/OVERVIEW.md index 72c0160ac76b..c9f1a303d81f 100644 --- a/google-cloud-pubsub/OVERVIEW.md +++ b/google-cloud-pubsub/OVERVIEW.md @@ -316,6 +316,44 @@ received_messages = sub.pull sub.modify_ack_deadline 120, received_messages ``` +## Minimizing API calls before receiving and acknowledging messages + +A subscription object can be created without making any API calls by providing +the `skip_lookup` argument to {Google::Cloud::Pubsub::Project#subscription +Project#subscription} or {Google::Cloud::Pubsub::Topic#subscription +Topic#subscription}. A subscriber object can also be created without an API call +by providing the `deadline` optional argument to +{Google::Cloud::Pubsub::Subscription#listen Subscription#listen}: + +```ruby +require "google/cloud/pubsub" + +pubsub = Google::Cloud::Pubsub.new + +# No API call is made to retrieve the subscription resource. +sub = pubsub.subscription "my-topic-sub", skip_lookup: true + +# No API call is made to retrieve the subscription deadline. +subscriber = sub.listen deadline: 60 do |received_message| + # process message + received_message.acknowledge! +end + +# Start background threads that will call block passed to listen. +subscriber.start + +# Shut down the subscriber when ready to stop receiving messages. +subscriber.stop.wait! +``` + +Skipping API calls may be used to avoid `Google::Cloud::PermissionDeniedError` +if your account has limited access to the Pub/Sub API. In particular, the role +`roles/pubsub.subscriber` does not have the permission +`pubsub.subscriptions.get`, which is required to retrieve a subscription +resource. See [Access Control - +Roles](https://cloud.google.com/pubsub/docs/access-control#tbl_roles) for the +complete list of Pub/Sub roles and permissions. + ## Creating a snapshot and using seek You can create a snapshot to retain the existing backlog on a subscription. The diff --git a/google-cloud-pubsub/acceptance/pubsub/pubsub_test.rb b/google-cloud-pubsub/acceptance/pubsub/pubsub_test.rb index fac72e495df7..e99f144af59a 100644 --- a/google-cloud-pubsub/acceptance/pubsub/pubsub_test.rb +++ b/google-cloud-pubsub/acceptance/pubsub/pubsub_test.rb @@ -33,7 +33,7 @@ def retrieve_snapshot project, subscription, snapshot_name let(:new_topic_name) { $topic_names[0] } let(:topic_names) { $topic_names[3..6] } - let(:lazy_topic_name) { $topic_names[7] } + let(:reference_topic_name) { $topic_names[7] } let(:labels) { { "foo" => "bar" } } before do diff --git a/google-cloud-pubsub/lib/google/cloud/pubsub/project.rb b/google-cloud-pubsub/lib/google/cloud/pubsub/project.rb index 9b02d2587414..67d187726a81 100644 --- a/google-cloud-pubsub/lib/google/cloud/pubsub/project.rb +++ b/google-cloud-pubsub/lib/google/cloud/pubsub/project.rb @@ -150,7 +150,7 @@ def project_id def topic topic_name, project: nil, skip_lookup: nil, async: nil ensure_service! options = { project: project } - return Topic.new_lazy(topic_name, service, options) if skip_lookup + return Topic.from_name(topic_name, service, options) if skip_lookup grpc = service.get_topic topic_name Topic.from_grpc grpc, service, async: async rescue Google::Cloud::NotFoundError @@ -282,7 +282,7 @@ def subscription subscription_name, project: nil, skip_lookup: nil ensure_service! options = { project: project } if skip_lookup - return Subscription.new_lazy subscription_name, service, options + return Subscription.from_name subscription_name, service, options end grpc = service.get_subscription subscription_name Subscription.from_grpc grpc, service diff --git a/google-cloud-pubsub/lib/google/cloud/pubsub/snapshot.rb b/google-cloud-pubsub/lib/google/cloud/pubsub/snapshot.rb index 4d9afde6c554..ed8d0ee826dc 100644 --- a/google-cloud-pubsub/lib/google/cloud/pubsub/snapshot.rb +++ b/google-cloud-pubsub/lib/google/cloud/pubsub/snapshot.rb @@ -79,7 +79,7 @@ def name # snapshot.topic.name #=> "projects/my-project/topics/my-topic" # def topic - Topic.new_lazy @grpc.topic, service + Topic.from_name @grpc.topic, service end ## diff --git a/google-cloud-pubsub/lib/google/cloud/pubsub/subscription.rb b/google-cloud-pubsub/lib/google/cloud/pubsub/subscription.rb index 1f6f6cd62ede..e0a8881ee081 100644 --- a/google-cloud-pubsub/lib/google/cloud/pubsub/subscription.rb +++ b/google-cloud-pubsub/lib/google/cloud/pubsub/subscription.rb @@ -60,19 +60,25 @@ class Subscription def initialize @service = nil @grpc = nil - @lazy = nil + @resource_name = nil @exists = nil end ## # The name of the subscription. + # + # @return [String] def name + return @resource_name if reference? @grpc.name end ## # The {Topic} from which this subscription receives messages. # + # Makes an API call to retrieve the topic information when called on a + # reference object. See {#reference?}. + # # @return [Topic] # # @example @@ -85,24 +91,36 @@ def name # def topic ensure_grpc! - Topic.new_lazy @grpc.topic, service + Topic.from_name @grpc.topic, service end ## # This value is the maximum number of seconds after a subscriber # receives a message before the subscriber should acknowledge the # message. + # + # Makes an API call to retrieve the deadline value when called on a + # reference object. See {#reference?}. + # + # @return [Integer] def deadline ensure_grpc! @grpc.ack_deadline_seconds end + ## + # Sets the maximum number of seconds after a subscriber + # receives a message before the subscriber should acknowledge the + # message. + # + # @param [Integer] new_deadline The new deadline value. + # def deadline= new_deadline - update_grpc = @grpc.dup - update_grpc.ack_deadline_seconds = new_deadline + update_grpc = Google::Pubsub::V1::Subscription.new \ + name: name, ack_deadline_seconds: new_deadline @grpc = service.update_subscription update_grpc, :ack_deadline_seconds - @lazy = nil + @resource_name = nil end ## @@ -111,6 +129,9 @@ def deadline= new_deadline # they are acknowledged, until they fall out of the {#retention} window. # Default is `false`. # + # Makes an API call to retrieve the retain_acked value when called on a + # reference object. See {#reference?}. + # # @return [Boolean] Returns `true` if acknowledged messages are # retained. # @@ -119,12 +140,18 @@ def retain_acked @grpc.retain_acked_messages end + ## + # Sets whether to retain acknowledged messages. + # + # @param [Boolean] new_retain_acked The new retain acknowledged messages + # value. + # def retain_acked= new_retain_acked - update_grpc = @grpc.dup - update_grpc.retain_acked_messages = !(!new_retain_acked) + update_grpc = Google::Pubsub::V1::Subscription.new \ + name: name, retain_acked_messages: !(!new_retain_acked) @grpc = service.update_subscription update_grpc, :retain_acked_messages - @lazy = nil + @resource_name = nil end ## @@ -136,6 +163,9 @@ def retain_acked= new_retain_acked # less than 600 seconds (10 minutes). Default is 604,800 seconds (7 # days). # + # Makes an API call to retrieve the retention value when called on a + # reference object. See {#reference?}. + # # @return [Numeric] The message retention duration in seconds. # def retention @@ -143,18 +173,29 @@ def retention Convert.duration_to_number @grpc.message_retention_duration end + ## + # Sets the message retention duration in seconds. + # + # @param [Numeric] new_retention The new retention value. + # def retention= new_retention - update_grpc = @grpc.dup - update_grpc.message_retention_duration = \ - Convert.number_to_duration new_retention + new_retention_duration = Convert.number_to_duration new_retention + update_grpc = Google::Pubsub::V1::Subscription.new \ + name: name, message_retention_duration: new_retention_duration @grpc = service.update_subscription update_grpc, :message_retention_duration - @lazy = nil + @resource_name = nil end ## # Returns the URL locating the endpoint to which messages should be # pushed. + # + # Makes an API call to retrieve the endpoint value when called on a + # reference object. See {#reference?}. + # + # @return [String] + # def endpoint ensure_grpc! @grpc.push_config.push_endpoint if @grpc.push_config @@ -162,11 +203,14 @@ def endpoint ## # Sets the URL locating the endpoint to which messages should be pushed. + # + # @param [String] new_endpoint The new endpoint value. + # def endpoint= new_endpoint ensure_service! service.modify_push_config name, new_endpoint, {} - return unless @grpc + return if reference? @grpc.push_config = Google::Pubsub::V1::PushConfig.new( push_endpoint: new_endpoint, @@ -182,9 +226,13 @@ def endpoint= new_endpoint # The returned hash is frozen and changes are not allowed. Use # {#labels=} to update the labels for this subscription. # + # Makes an API call to retrieve the labels value when called on a + # reference object. See {#reference?}. + # # @return [Hash] The frozen labels hash. # def labels + ensure_grpc! @grpc.labels.to_h.freeze end @@ -202,17 +250,20 @@ def labels # def labels= new_labels raise ArgumentError, "Value must be a Hash" if new_labels.nil? - labels_map = Google::Protobuf::Map.new(:string, :string) - Hash(new_labels).each { |k, v| labels_map[String(k)] = String(v) } - update_grpc = @grpc.dup - update_grpc.labels = labels_map + update_grpc = Google::Pubsub::V1::Subscription.new \ + name: name, labels: new_labels @grpc = service.update_subscription update_grpc, :labels - @lazy = nil + @resource_name = nil end ## # Determines whether the subscription exists in the Pub/Sub service. # + # Makes an API call to determine whether the subscription resource + # exists when called on a reference object. See {#reference?}. + # + # @return [Boolean] + # # @example # require "google/cloud/pubsub" # @@ -222,8 +273,8 @@ def labels= new_labels # sub.exists? #=> true # def exists? - # Always true if the object is not set as lazy - return true unless lazy? + # Always true if the object is not set as reference + return true unless reference? # If we have a value, return it return @exists unless @exists.nil? ensure_grpc! @@ -232,23 +283,6 @@ def exists? @exists = false end - ## - # @private - # Determines whether the subscription object was created with an - # HTTP call. - # - # @example - # require "google/cloud/pubsub" - # - # pubsub = Google::Cloud::Pubsub.new - # - # sub = pubsub.get_subscription "my-topic-sub" - # sub.lazy? #=> nil - # - def lazy? - @lazy - end - ## # Deletes an existing subscription. # All pending messages in the subscription are immediately dropped. @@ -370,6 +404,9 @@ def wait_for_messages max: 100 # will hold received messages before modifying the message's ack # deadline. The minimum is 10, the maximum is 600. Default is # {#deadline}. Optional. + # + # Makes an API call to retrieve the deadline value when called on a + # reference object. See {#reference?}. # @param [Integer] streams The number of concurrent streams to open to # pull messages from the subscription. Default is 4. Optional. # @param [Integer] inventory The number of received messages to be @@ -608,6 +645,44 @@ def seek snapshot true end + ## + # Determines whether the subscription object was created without + # retrieving the resource representation from the Pub/Sub service. + # + # @return [Boolean] `true` when the subscription was created without a + # resource representation, `false` otherwise. + # + # @example + # require "google/cloud/pubsub" + # + # pubsub = Google::Cloud::Pubsub.new + # + # sub = pubsub.get_subscription "my-topic-sub", skip_lookup: true + # sub.reference? #=> true + # + def reference? + @grpc.nil? + end + + ## + # Determines whether the subscription object was created with a resource + # representation from the Pub/Sub service. + # + # @return [Boolean] `true` when the subscription was created with a + # resource representation, `false` otherwise. + # + # @example + # require "google/cloud/pubsub" + # + # pubsub = Google::Cloud::Pubsub.new + # + # sub = pubsub.get_subscription "my-topic-sub" + # sub.resource? #=> true + # + def resource? + !@grpc.nil? + end + ## # Gets the [Cloud IAM](https://cloud.google.com/iam/) access control # policy for this subscription. @@ -737,12 +812,12 @@ def self.from_grpc grpc, service end ## - # @private New lazy {Topic} object without making an HTTP request. - def self.new_lazy name, service, options = {} - lazy_grpc = Google::Pubsub::V1::Subscription.new \ - name: service.subscription_path(name, options) - from_grpc(lazy_grpc, service).tap do |s| - s.instance_variable_set :@lazy, true + # @private New reference {Subscription} object without making an HTTP + # request. + def self.from_name name, service, options = {} + name = service.subscription_path name, options + from_grpc(nil, service).tap do |s| + s.instance_variable_set :@resource_name, name end end @@ -759,8 +834,8 @@ def ensure_service! # Ensures a Google::Pubsub::V1::Subscription object exists. def ensure_grpc! ensure_service! - @grpc = service.get_subscription name if lazy? - @lazy = nil + @grpc = service.get_subscription name if reference? + @resource_name = nil end ## diff --git a/google-cloud-pubsub/lib/google/cloud/pubsub/subscription/list.rb b/google-cloud-pubsub/lib/google/cloud/pubsub/subscription/list.rb index 566475db34c9..24c87f61bf51 100644 --- a/google-cloud-pubsub/lib/google/cloud/pubsub/subscription/list.rb +++ b/google-cloud-pubsub/lib/google/cloud/pubsub/subscription/list.rb @@ -167,7 +167,7 @@ def self.from_grpc grpc_list, service, max = nil # Google::Pubsub::V1::ListTopicSubscriptionsResponse object. def self.from_topic_grpc grpc_list, service, topic, max = nil subs = new(Array(grpc_list.subscriptions).map do |grpc| - Subscription.new_lazy grpc, service + Subscription.from_name grpc, service end) token = grpc_list.next_page_token token = nil if token == "".freeze diff --git a/google-cloud-pubsub/lib/google/cloud/pubsub/topic.rb b/google-cloud-pubsub/lib/google/cloud/pubsub/topic.rb index 46a0040a181c..caba9bf86b7c 100644 --- a/google-cloud-pubsub/lib/google/cloud/pubsub/topic.rb +++ b/google-cloud-pubsub/lib/google/cloud/pubsub/topic.rb @@ -52,7 +52,7 @@ class Topic def initialize @service = nil @grpc = nil - @lazy = nil + @resource_name = nil @exists = nil @async_opts = {} end @@ -90,6 +90,7 @@ def async_publisher # @return [String] # def name + return @resource_name if reference? @grpc.name end @@ -101,9 +102,13 @@ def name # The returned hash is frozen and changes are not allowed. Use # {#labels=} to update the labels for this topic. # + # Makes an API call to retrieve the labels values when called on a + # reference object. See {#reference?}. + # # @return [Hash] The frozen labels hash. # def labels + ensure_grpc! @grpc.labels.to_h.freeze end @@ -121,12 +126,10 @@ def labels # def labels= new_labels raise ArgumentError, "Value must be a Hash" if new_labels.nil? - labels_map = Google::Protobuf::Map.new(:string, :string) - Hash(new_labels).each { |k, v| labels_map[String(k)] = String(v) } - update_grpc = @grpc.dup - update_grpc.labels = labels_map + update_grpc = Google::Pubsub::V1::Topic.new \ + name: name, labels: new_labels @grpc = service.update_topic update_grpc, :labels - @lazy = nil + @resource_name = nil end ## @@ -248,7 +251,9 @@ def subscribe subscription_name, deadline: nil, retain_acked: false, # def subscription subscription_name, skip_lookup: nil ensure_service! - return Subscription.new_lazy subscription_name, service if skip_lookup + if skip_lookup + return Subscription.from_name subscription_name, service + end grpc = service.get_subscription subscription_name Subscription.from_grpc grpc, service rescue Google::Cloud::NotFoundError @@ -553,8 +558,8 @@ def test_permissions *permissions # topic.exists? #=> true # def exists? - # Always true if the object is not set as lazy - return true unless lazy? + # Always true if the object is not set as reference + return true unless reference? # If we have a value, return it return @exists unless @exists.nil? ensure_grpc! @@ -564,8 +569,30 @@ def exists? end ## - # @private - # Determines whether the topic object was created with an HTTP call. + # Determines whether the topic object was created without retrieving the + # resource representation from the Pub/Sub service. + # + # @return [Boolean] `true` when the topic was created without a resource + # representation, `false` otherwise. + # + # @example + # require "google/cloud/pubsub" + # + # pubsub = Google::Cloud::Pubsub.new + # + # topic = pubsub.topic "my-topic", skip_lookup: true + # topic.reference? #=> true + # + def reference? + @grpc.nil? + end + + ## + # Determines whether the topic object was created with a resource + # representation from the Pub/Sub service. + # + # @return [Boolean] `true` when the topic was created with a resource + # representation, `false` otherwise. # # @example # require "google/cloud/pubsub" @@ -573,10 +600,10 @@ def exists? # pubsub = Google::Cloud::Pubsub.new # # topic = pubsub.topic "my-topic" - # topic.lazy? #=> nil + # topic.resource? #=> true # - def lazy? - @lazy + def resource? + !@grpc.nil? end ## @@ -590,12 +617,11 @@ def self.from_grpc grpc, service, async: nil end ## - # @private New lazy {Topic} object without making an HTTP request. - def self.new_lazy name, service, options = {} - lazy_grpc = Google::Pubsub::V1::Topic.new \ - name: service.topic_path(name, options) - from_grpc(lazy_grpc, service).tap do |t| - t.instance_variable_set :@lazy, true + # @private New reference {Topic} object without making an HTTP request. + def self.from_name name, service, options = {} + name = service.topic_path name, options + from_grpc(nil, service).tap do |t| + t.instance_variable_set :@resource_name, name end end @@ -612,8 +638,8 @@ def ensure_service! # Ensures a Google::Pubsub::V1::Topic object exists. def ensure_grpc! ensure_service! - @grpc = service.get_topic name if lazy? - @lazy = nil + @grpc = service.get_topic name if reference? + @resource_name = nil end ## diff --git a/google-cloud-pubsub/test/google/cloud/pubsub/message_test.rb b/google-cloud-pubsub/test/google/cloud/pubsub/message_test.rb index 5381384c62d1..52ed7a04ad7b 100644 --- a/google-cloud-pubsub/test/google/cloud/pubsub/message_test.rb +++ b/google-cloud-pubsub/test/google/cloud/pubsub/message_test.rb @@ -30,8 +30,7 @@ describe "from gapi" do let(:topic_name) { "topic-name-goes-here" } - let(:topic) { Google::Cloud::Pubsub::Topic.from_grpc Google::Pubsub::V1::Topic.decode_json(topic_json(topic_name)), - pubsub.service } + let(:topic) { Google::Cloud::Pubsub::Topic.from_grpc Google::Pubsub::V1::Topic.decode_json(topic_json(topic_name)), pubsub.service } let(:subscription_name) { "subscription-name-goes-here" } let(:subscription_grpc) { Google::Pubsub::V1::Subscription.decode_json(subscription_json(topic_name, subscription_name)) } let(:subscription) { Google::Cloud::Pubsub::Subscription.from_grpc subscription_grpc, pubsub.service } diff --git a/google-cloud-pubsub/test/google/cloud/pubsub/project_test.rb b/google-cloud-pubsub/test/google/cloud/pubsub/project_test.rb index 6d7f156c52ba..43c0899efa6e 100644 --- a/google-cloud-pubsub/test/google/cloud/pubsub/project_test.rb +++ b/google-cloud-pubsub/test/google/cloud/pubsub/project_test.rb @@ -117,7 +117,8 @@ mock.verify topic.name.must_equal topic_path(topic_name) - topic.wont_be :lazy? + topic.wont_be :reference? + topic.must_be :resource? end it "gets a topic with get_topic alias" do @@ -133,7 +134,8 @@ mock.verify topic.name.must_equal topic_path(topic_name) - topic.wont_be :lazy? + topic.wont_be :reference? + topic.must_be :resource? end it "gets a topic with find_topic alias" do @@ -149,7 +151,8 @@ mock.verify topic.name.must_equal topic_path(topic_name) - topic.wont_be :lazy? + topic.wont_be :reference? + topic.must_be :resource? end it "returns nil when getting an non-existent topic" do @@ -173,7 +176,8 @@ def stub.get_topic *args topic = pubsub.find_topic topic_name, skip_lookup: true topic.name.must_equal topic_path(topic_name) - topic.must_be :lazy? + topic.must_be :reference? + topic.wont_be :resource? end it "gets a topic with skip_lookup and project options" do @@ -182,7 +186,8 @@ def stub.get_topic *args topic = pubsub.find_topic topic_name, skip_lookup: true, project: "custom" topic.name.must_equal "projects/custom/topics/found-topic" - topic.must_be :lazy? + topic.must_be :reference? + topic.wont_be :resource? end it "lists topics" do @@ -381,7 +386,8 @@ def stub.get_topic *args sub.wont_be :nil? sub.must_be_kind_of Google::Cloud::Pubsub::Subscription sub.name.must_equal subscription_path(sub_name) - sub.wont_be :lazy? + sub.wont_be :reference? + sub.must_be :resource? end it "gets a subscription with get_subscription alias" do @@ -399,7 +405,8 @@ def stub.get_topic *args sub.wont_be :nil? sub.must_be_kind_of Google::Cloud::Pubsub::Subscription sub.name.must_equal subscription_path(sub_name) - sub.wont_be :lazy? + sub.wont_be :reference? + sub.must_be :resource? end it "gets a subscription with find_subscription alias" do @@ -417,7 +424,8 @@ def stub.get_topic *args sub.wont_be :nil? sub.must_be_kind_of Google::Cloud::Pubsub::Subscription sub.name.must_equal subscription_path(sub_name) - sub.wont_be :lazy? + sub.wont_be :reference? + sub.must_be :resource? end it "returns nil when getting an non-existent subscription" do @@ -443,7 +451,8 @@ def stub.get_subscription *args sub.wont_be :nil? sub.must_be_kind_of Google::Cloud::Pubsub::Subscription sub.name.must_equal subscription_path(sub_name) - sub.must_be :lazy? + sub.must_be :reference? + sub.wont_be :resource? end it "gets a subscription with skip_lookup and project options" do @@ -454,7 +463,8 @@ def stub.get_subscription *args sub.wont_be :nil? sub.must_be_kind_of Google::Cloud::Pubsub::Subscription sub.name.must_equal "projects/custom/subscriptions/#{sub_name}" - sub.must_be :lazy? + sub.must_be :reference? + sub.wont_be :resource? end it "lists subscriptions" do @@ -554,14 +564,16 @@ def stub.get_subscription *args first_subs.next?.must_equal true first_subs.each do |sub| sub.must_be_kind_of Google::Cloud::Pubsub::Subscription - sub.wont_be :lazy? + sub.wont_be :reference? + sub.must_be :resource? end second_subs.count.must_equal 2 second_subs.next?.must_equal false second_subs.each do |sub| sub.must_be_kind_of Google::Cloud::Pubsub::Subscription - sub.wont_be :lazy? + sub.wont_be :reference? + sub.must_be :resource? end end @@ -581,14 +593,16 @@ def stub.get_subscription *args first_subs.next?.must_equal true first_subs.each do |sub| sub.must_be_kind_of Google::Cloud::Pubsub::Subscription - sub.wont_be :lazy? + sub.wont_be :reference? + sub.must_be :resource? end second_subs.count.must_equal 2 second_subs.next?.must_equal false second_subs.each do |sub| sub.must_be_kind_of Google::Cloud::Pubsub::Subscription - sub.wont_be :lazy? + sub.wont_be :reference? + sub.must_be :resource? end end @@ -606,7 +620,8 @@ def stub.get_subscription *args subs.count.must_equal 5 subs.each do |sub| sub.must_be_kind_of Google::Cloud::Pubsub::Subscription - sub.wont_be :lazy? + sub.wont_be :reference? + sub.must_be :resource? end end @@ -624,7 +639,8 @@ def stub.get_subscription *args subs.count.must_equal 5 subs.each do |sub| sub.must_be_kind_of Google::Cloud::Pubsub::Subscription - sub.wont_be :lazy? + sub.wont_be :reference? + sub.must_be :resource? end end @@ -642,7 +658,8 @@ def stub.get_subscription *args subs.count.must_equal 5 subs.each do |sub| sub.must_be_kind_of Google::Cloud::Pubsub::Subscription - sub.wont_be :lazy? + sub.wont_be :reference? + sub.must_be :resource? end end @@ -660,7 +677,8 @@ def stub.get_subscription *args subs.count.must_equal 6 subs.each do |sub| sub.must_be_kind_of Google::Cloud::Pubsub::Subscription - sub.wont_be :lazy? + sub.wont_be :reference? + sub.must_be :resource? end end diff --git a/google-cloud-pubsub/test/google/cloud/pubsub/received_message_test.rb b/google-cloud-pubsub/test/google/cloud/pubsub/received_message_test.rb index 5c147f63d2ec..903311f96225 100644 --- a/google-cloud-pubsub/test/google/cloud/pubsub/received_message_test.rb +++ b/google-cloud-pubsub/test/google/cloud/pubsub/received_message_test.rb @@ -16,8 +16,7 @@ describe Google::Cloud::Pubsub::ReceivedMessage, :mock_pubsub do let(:topic_name) { "topic-name-goes-here" } - let(:topic) { Google::Cloud::Pubsub::Topic.from_grpc Google::Pubsub::V1::Topic.decode_json(topic_json(topic_name)), - pubsub.service } + let(:topic) { Google::Cloud::Pubsub::Topic.from_grpc Google::Pubsub::V1::Topic.decode_json(topic_json(topic_name)), pubsub.service } let(:subscription_name) { "subscription-name-goes-here" } let(:subscription_grpc) { Google::Pubsub::V1::Subscription.decode_json(subscription_json(topic_name, subscription_name)) } let(:subscription) { Google::Cloud::Pubsub::Subscription.from_grpc subscription_grpc, pubsub.service } diff --git a/google-cloud-pubsub/test/google/cloud/pubsub/snapshot_test.rb b/google-cloud-pubsub/test/google/cloud/pubsub/snapshot_test.rb index ae4777ec4bc9..a53aeaedeec7 100644 --- a/google-cloud-pubsub/test/google/cloud/pubsub/snapshot_test.rb +++ b/google-cloud-pubsub/test/google/cloud/pubsub/snapshot_test.rb @@ -33,7 +33,8 @@ it "knows its topic" do snapshot.topic.must_be_kind_of Google::Cloud::Pubsub::Topic - snapshot.topic.must_be :lazy? + snapshot.topic.must_be :reference? + snapshot.topic.wont_be :resource? snapshot.topic.name.must_equal topic_path(topic_name) end diff --git a/google-cloud-pubsub/test/google/cloud/pubsub/subscription/acknowledge_test.rb b/google-cloud-pubsub/test/google/cloud/pubsub/subscription/acknowledge_test.rb index 5e7edc4d393d..be09e6f9ad9e 100644 --- a/google-cloud-pubsub/test/google/cloud/pubsub/subscription/acknowledge_test.rb +++ b/google-cloud-pubsub/test/google/cloud/pubsub/subscription/acknowledge_test.rb @@ -104,9 +104,9 @@ mock.verify end - describe "lazy subscription object of a subscription that does exist" do + describe "reference subscription object of a subscription that does exist" do let :subscription do - Google::Cloud::Pubsub::Subscription.new_lazy sub_name, + Google::Cloud::Pubsub::Subscription.from_name sub_name, pubsub.service end @@ -184,9 +184,9 @@ end end - describe "lazy subscription object of a subscription that does not exist" do + describe "reference subscription object of a subscription that does not exist" do let :subscription do - Google::Cloud::Pubsub::Subscription.new_lazy sub_name, + Google::Cloud::Pubsub::Subscription.from_name sub_name, pubsub.service end diff --git a/google-cloud-pubsub/test/google/cloud/pubsub/subscription/attrs_test.rb b/google-cloud-pubsub/test/google/cloud/pubsub/subscription/attrs_test.rb index ec0945df191a..6d9c2eb341b4 100644 --- a/google-cloud-pubsub/test/google/cloud/pubsub/subscription/attrs_test.rb +++ b/google-cloud-pubsub/test/google/cloud/pubsub/subscription/attrs_test.rb @@ -27,7 +27,8 @@ it "gets topic from the Google API object" do # No mocked service means no API calls are happening. subscription.topic.must_be_kind_of Google::Cloud::Pubsub::Topic - subscription.topic.must_be :lazy? + subscription.topic.must_be :reference? + subscription.topic.wont_be :resource? subscription.topic.name.must_equal topic_path(topic_name) end @@ -60,9 +61,9 @@ mock.verify end - describe "lazy subscription object of a subscription that does exist" do + describe "reference subscription object of a subscription that does exist" do let :subscription do - Google::Cloud::Pubsub::Subscription.new_lazy sub_name, + Google::Cloud::Pubsub::Subscription.from_name sub_name, pubsub.service end @@ -76,7 +77,8 @@ mock.verify - subscription.topic.must_be :lazy? + subscription.topic.must_be :reference? + subscription.topic.wont_be :resource? subscription.topic.name.must_equal topic_path(topic_name) end @@ -127,9 +129,9 @@ end end - describe "lazy subscription object of a subscription that does not exist" do + describe "reference subscription object of a subscription that does not exist" do let :subscription do - Google::Cloud::Pubsub::Subscription.new_lazy sub_name, + Google::Cloud::Pubsub::Subscription.from_name sub_name, pubsub.service end diff --git a/google-cloud-pubsub/test/google/cloud/pubsub/subscription/delete_test.rb b/google-cloud-pubsub/test/google/cloud/pubsub/subscription/delete_test.rb index 257c44e7b7e5..161d54605a3d 100644 --- a/google-cloud-pubsub/test/google/cloud/pubsub/subscription/delete_test.rb +++ b/google-cloud-pubsub/test/google/cloud/pubsub/subscription/delete_test.rb @@ -33,9 +33,9 @@ mock.verify end - describe "lazy subscription object of a subscription that does exist" do + describe "reference subscription object of a subscription that does exist" do let :subscription do - Google::Cloud::Pubsub::Subscription.new_lazy sub_name, + Google::Cloud::Pubsub::Subscription.from_name sub_name, pubsub.service end @@ -51,9 +51,9 @@ end end - describe "lazy subscription object of a subscription that does not exist" do + describe "reference subscription object of a subscription that does not exist" do let :subscription do - Google::Cloud::Pubsub::Subscription.new_lazy sub_name, + Google::Cloud::Pubsub::Subscription.from_name sub_name, pubsub.service end diff --git a/google-cloud-pubsub/test/google/cloud/pubsub/subscription/exists_test.rb b/google-cloud-pubsub/test/google/cloud/pubsub/subscription/exists_test.rb index 62d136479ae1..78eba483bb59 100644 --- a/google-cloud-pubsub/test/google/cloud/pubsub/subscription/exists_test.rb +++ b/google-cloud-pubsub/test/google/cloud/pubsub/subscription/exists_test.rb @@ -29,9 +29,9 @@ subscription.must_be :exists? end - describe "lazy subscription object of a subscription that exists" do + describe "reference subscription object of a subscription that exists" do let :subscription do - Google::Cloud::Pubsub::Subscription.new_lazy sub_name, + Google::Cloud::Pubsub::Subscription.from_name sub_name, pubsub.service end @@ -50,9 +50,9 @@ end end - describe "lazy subscription object of a subscription that does not exist" do + describe "reference subscription object of a subscription that does not exist" do let :subscription do - Google::Cloud::Pubsub::Subscription.new_lazy sub_name, + Google::Cloud::Pubsub::Subscription.from_name sub_name, pubsub.service end diff --git a/google-cloud-pubsub/test/google/cloud/pubsub/subscription/lazy_test.rb b/google-cloud-pubsub/test/google/cloud/pubsub/subscription/lazy_test.rb index 6c52c6686a58..21b9bd3a053d 100644 --- a/google-cloud-pubsub/test/google/cloud/pubsub/subscription/lazy_test.rb +++ b/google-cloud-pubsub/test/google/cloud/pubsub/subscription/lazy_test.rb @@ -22,18 +22,19 @@ let(:sub_grpc) { Google::Pubsub::V1::Subscription.decode_json(sub_json) } let(:subscription) { Google::Cloud::Pubsub::Subscription.from_grpc sub_grpc, pubsub.service } - it "is not lazy when created with an HTTP method" do - subscription.wont_be :lazy? + it "is not reference when created with an HTTP method" do + subscription.wont_be :reference? + subscription.must_be :resource? end - describe "lazy subscription" do + describe "reference subscription" do let :subscription do - Google::Cloud::Pubsub::Subscription.new_lazy sub_name, - pubsub.service + Google::Cloud::Pubsub::Subscription.from_name sub_name, pubsub.service end - it "is lazy" do - subscription.must_be :lazy? + it "is reference" do + subscription.must_be :reference? + subscription.wont_be :resource? end end end diff --git a/google-cloud-pubsub/test/google/cloud/pubsub/subscription/modify_ack_deadline_test.rb b/google-cloud-pubsub/test/google/cloud/pubsub/subscription/modify_ack_deadline_test.rb index 6a9aa54b5de2..aa1ae8d10193 100644 --- a/google-cloud-pubsub/test/google/cloud/pubsub/subscription/modify_ack_deadline_test.rb +++ b/google-cloud-pubsub/test/google/cloud/pubsub/subscription/modify_ack_deadline_test.rb @@ -105,9 +105,9 @@ mock.verify end - describe "lazy subscription object of a subscription that does exist" do + describe "reference subscription object of a subscription that does exist" do let :subscription do - Google::Cloud::Pubsub::Subscription.new_lazy sub_name, + Google::Cloud::Pubsub::Subscription.from_name sub_name, pubsub.service end @@ -189,9 +189,9 @@ end end - describe "lazy subscription object of a subscription that does not exist" do + describe "reference subscription object of a subscription that does not exist" do let :subscription do - Google::Cloud::Pubsub::Subscription.new_lazy sub_name, + Google::Cloud::Pubsub::Subscription.from_name sub_name, pubsub.service end diff --git a/google-cloud-pubsub/test/google/cloud/pubsub/subscription/name_test.rb b/google-cloud-pubsub/test/google/cloud/pubsub/subscription/name_test.rb index 6e9dc31d8bfe..8569ab3978f8 100644 --- a/google-cloud-pubsub/test/google/cloud/pubsub/subscription/name_test.rb +++ b/google-cloud-pubsub/test/google/cloud/pubsub/subscription/name_test.rb @@ -26,9 +26,9 @@ subscription.name.must_equal sub_path end - describe "lazy subscription given the short name" do + describe "reference subscription given the short name" do let :subscription do - Google::Cloud::Pubsub::Subscription.new_lazy sub_name, + Google::Cloud::Pubsub::Subscription.from_name sub_name, pubsub.service end @@ -37,9 +37,9 @@ end end - describe "lazy subscription object given the full path" do + describe "reference subscription object given the full path" do let :subscription do - Google::Cloud::Pubsub::Subscription.new_lazy sub_path, + Google::Cloud::Pubsub::Subscription.from_name sub_path, pubsub.service end diff --git a/google-cloud-pubsub/test/google/cloud/pubsub/subscription/pull_test.rb b/google-cloud-pubsub/test/google/cloud/pubsub/subscription/pull_test.rb index fdaf64ddd4a5..8c53cca0fc51 100644 --- a/google-cloud-pubsub/test/google/cloud/pubsub/subscription/pull_test.rb +++ b/google-cloud-pubsub/test/google/cloud/pubsub/subscription/pull_test.rb @@ -37,9 +37,9 @@ rec_messages.first.message.data.must_equal rec_message_msg end - describe "lazy subscription object of a subscription that does exist" do + describe "reference subscription object of a subscription that does exist" do let :subscription do - Google::Cloud::Pubsub::Subscription.new_lazy sub_name, + Google::Cloud::Pubsub::Subscription.from_name sub_name, pubsub.service end @@ -59,9 +59,9 @@ end end - describe "lazy subscription object of a subscription that does not exist" do + describe "reference subscription object of a subscription that does not exist" do let :subscription do - Google::Cloud::Pubsub::Subscription.new_lazy sub_name, + Google::Cloud::Pubsub::Subscription.from_name sub_name, pubsub.service end diff --git a/google-cloud-pubsub/test/google/cloud/pubsub/subscription/seek_test.rb b/google-cloud-pubsub/test/google/cloud/pubsub/subscription/seek_test.rb index 405dd540d021..e4475d8e8790 100644 --- a/google-cloud-pubsub/test/google/cloud/pubsub/subscription/seek_test.rb +++ b/google-cloud-pubsub/test/google/cloud/pubsub/subscription/seek_test.rb @@ -55,9 +55,9 @@ mock.verify end - describe "lazy subscription object of a subscription that does exist" do + describe "reference subscription object of a subscription that does exist" do let :subscription do - Google::Cloud::Pubsub::Subscription.new_lazy sub_name, + Google::Cloud::Pubsub::Subscription.from_name sub_name, pubsub.service end @@ -73,9 +73,9 @@ end end - describe "lazy subscription object of a subscription that does not exist" do + describe "reference subscription object of a subscription that does not exist" do let :subscription do - Google::Cloud::Pubsub::Subscription.new_lazy sub_name, + Google::Cloud::Pubsub::Subscription.from_name sub_name, pubsub.service end diff --git a/google-cloud-pubsub/test/google/cloud/pubsub/subscription/update_test.rb b/google-cloud-pubsub/test/google/cloud/pubsub/subscription/update_test.rb index 843aecaf7129..4dd1e4b1a35f 100644 --- a/google-cloud-pubsub/test/google/cloud/pubsub/subscription/update_test.rb +++ b/google-cloud-pubsub/test/google/cloud/pubsub/subscription/update_test.rb @@ -17,6 +17,7 @@ describe Google::Cloud::Pubsub::Subscription, :update, :mock_pubsub do let(:topic_name) { "topic-name-goes-here" } let(:sub_name) { "subscription-name-goes-here" } + let(:sub_path) { subscription_path sub_name } let(:labels) { { "foo" => "bar" } } let(:new_labels) { { "baz" => "qux" } } let(:new_labels_map) do @@ -34,8 +35,8 @@ it "updates deadline" do subscription.deadline.must_equal 60 - update_sub = sub_grpc.dup - update_sub.ack_deadline_seconds = 30 + update_sub = update_sub = Google::Pubsub::V1::Subscription.new \ + name: sub_path, ack_deadline_seconds: 30 update_mask = Google::Protobuf::FieldMask.new paths: ["ack_deadline_seconds"] mock = Minitest::Mock.new mock.expect :update_subscription, update_sub, [update_sub, update_mask, options: default_options] @@ -51,8 +52,8 @@ it "updates retain_acked" do subscription.retain_acked.must_equal true - update_sub = sub_grpc.dup - update_sub.retain_acked_messages = false + update_sub = update_sub = Google::Pubsub::V1::Subscription.new \ + name: sub_path, retain_acked_messages: false update_mask = Google::Protobuf::FieldMask.new paths: ["retain_acked_messages"] mock = Minitest::Mock.new mock.expect :update_subscription, update_sub, [update_sub, update_mask, options: default_options] @@ -68,8 +69,8 @@ it "updates retention" do subscription.retention.must_equal 600.9 - update_sub = sub_grpc.dup - update_sub.message_retention_duration = Google::Cloud::Pubsub::Convert.number_to_duration 600.2 + update_sub = Google::Pubsub::V1::Subscription.new \ + name: sub_path, message_retention_duration: Google::Cloud::Pubsub::Convert.number_to_duration(600.2) update_mask = Google::Protobuf::FieldMask.new paths: ["message_retention_duration"] mock = Minitest::Mock.new mock.expect :update_subscription, update_sub, [update_sub, update_mask, options: default_options] @@ -85,8 +86,8 @@ it "updates labels" do subscription.labels.must_equal labels - update_sub = sub_grpc.dup - update_sub.labels = new_labels_map + update_sub = Google::Pubsub::V1::Subscription.new \ + name: sub_path, labels: new_labels update_mask = Google::Protobuf::FieldMask.new paths: ["labels"] mock = Minitest::Mock.new mock.expect :update_subscription, update_sub, [update_sub, update_mask, options: default_options] @@ -102,8 +103,8 @@ it "updates labels to empty hash" do subscription.labels.must_equal labels - update_sub = sub_grpc.dup - update_sub.labels = Google::Protobuf::Map.new(:string, :string) + update_sub = Google::Pubsub::V1::Subscription.new \ + name: sub_path, labels: {} update_mask = Google::Protobuf::FieldMask.new paths: ["labels"] mock = Minitest::Mock.new @@ -126,11 +127,12 @@ subscription.labels.must_equal labels end - describe :lazy do - let(:subscription) { Google::Cloud::Pubsub::Subscription.new_lazy sub_name, pubsub.service } + describe :reference do + let(:subscription) { Google::Cloud::Pubsub::Subscription.from_name sub_name, pubsub.service } it "updates deadline" do - subscription.must_be :lazy? + subscription.must_be :reference? + subscription.wont_be :resource? update_sub = Google::Pubsub::V1::Subscription.new \ name: subscription_path(sub_name), @@ -145,12 +147,14 @@ mock.verify - subscription.wont_be :lazy? + subscription.wont_be :reference? + subscription.must_be :resource? subscription.deadline.must_equal 30 end it "updates retain_acked" do - subscription.must_be :lazy? + subscription.must_be :reference? + subscription.wont_be :resource? update_sub = Google::Pubsub::V1::Subscription.new \ name: subscription_path(sub_name), @@ -165,12 +169,14 @@ mock.verify - subscription.wont_be :lazy? + subscription.wont_be :reference? + subscription.must_be :resource? subscription.retain_acked.must_equal true end it "updates retention" do - subscription.must_be :lazy? + subscription.must_be :reference? + subscription.wont_be :resource? update_sub = Google::Pubsub::V1::Subscription.new \ name: subscription_path(sub_name), @@ -185,12 +191,14 @@ mock.verify - subscription.wont_be :lazy? + subscription.wont_be :reference? + subscription.must_be :resource? subscription.retention.must_equal 600.2 end it "updates labels" do - subscription.must_be :lazy? + subscription.must_be :reference? + subscription.wont_be :resource? update_sub = Google::Pubsub::V1::Subscription.new \ name: subscription_path(sub_name), @@ -205,7 +213,8 @@ mock.verify - subscription.wont_be :lazy? + subscription.wont_be :reference? + subscription.must_be :resource? subscription.labels.must_equal new_labels end end diff --git a/google-cloud-pubsub/test/google/cloud/pubsub/subscription_test.rb b/google-cloud-pubsub/test/google/cloud/pubsub/subscription_test.rb index ee5ab380b96e..086de6a0ffab 100644 --- a/google-cloud-pubsub/test/google/cloud/pubsub/subscription_test.rb +++ b/google-cloud-pubsub/test/google/cloud/pubsub/subscription_test.rb @@ -27,7 +27,8 @@ it "knows its topic" do subscription.topic.must_be_kind_of Google::Cloud::Pubsub::Topic - subscription.topic.must_be :lazy? + subscription.topic.must_be :reference? + subscription.topic.wont_be :resource? subscription.topic.name.must_equal topic_path(topic_name) end diff --git a/google-cloud-pubsub/test/google/cloud/pubsub/topic/autocreate_test.rb b/google-cloud-pubsub/test/google/cloud/pubsub/topic/autocreate_test.rb index 5c22605da744..d978fa8a5048 100644 --- a/google-cloud-pubsub/test/google/cloud/pubsub/topic/autocreate_test.rb +++ b/google-cloud-pubsub/test/google/cloud/pubsub/topic/autocreate_test.rb @@ -14,21 +14,21 @@ require "helper" -describe Google::Cloud::Pubsub::Topic, :lazy, :mock_pubsub do +describe Google::Cloud::Pubsub::Topic, :reference, :mock_pubsub do let(:topic_name) { "topic-name-goes-here" } - let(:topic) { Google::Cloud::Pubsub::Topic.from_grpc Google::Pubsub::V1::Topic.decode_json(topic_json(topic_name)), - pubsub.service } + let(:topic) { Google::Cloud::Pubsub::Topic.from_grpc Google::Pubsub::V1::Topic.decode_json(topic_json(topic_name)), pubsub.service } - it "will not be lazy when created with an HTTP method" do - topic.wont_be :lazy? + it "will not be reference when created with an HTTP method" do + topic.wont_be :reference? + topic.must_be :resource? end - describe "lazy topic" do - let(:topic) { Google::Cloud::Pubsub::Topic.new_lazy topic_name, - pubsub.service } + describe "reference topic" do + let(:topic) { Google::Cloud::Pubsub::Topic.from_name topic_name, pubsub.service } - it "will be lazy when created lazily" do - topic.must_be :lazy? + it "will be reference when created lazily" do + topic.must_be :reference? + topic.wont_be :resource? end end end diff --git a/google-cloud-pubsub/test/google/cloud/pubsub/topic/exists_test.rb b/google-cloud-pubsub/test/google/cloud/pubsub/topic/exists_test.rb index e9a610e355ff..e138a11b7165 100644 --- a/google-cloud-pubsub/test/google/cloud/pubsub/topic/exists_test.rb +++ b/google-cloud-pubsub/test/google/cloud/pubsub/topic/exists_test.rb @@ -16,8 +16,7 @@ describe Google::Cloud::Pubsub::Topic, :exists, :mock_pubsub do let(:topic_name) { "topic-name-goes-here" } - let(:topic) { Google::Cloud::Pubsub::Topic.from_grpc Google::Pubsub::V1::Topic.decode_json(topic_json(topic_name)), - pubsub.service } + let(:topic) { Google::Cloud::Pubsub::Topic.from_grpc Google::Pubsub::V1::Topic.decode_json(topic_json(topic_name)), pubsub.service } it "knows if it exists when created with an HTTP method" do # The absense of a mock means this test will fail @@ -27,9 +26,8 @@ topic.must_be :exists? end - describe "lazy topic object of a topic that exists" do - let(:topic) { Google::Cloud::Pubsub::Topic.new_lazy topic_name, - pubsub.service } + describe "reference topic object of a topic that exists" do + let(:topic) { Google::Cloud::Pubsub::Topic.from_name topic_name, pubsub.service } it "checks if the topic exists by making an HTTP call" do get_res = Google::Pubsub::V1::Topic.decode_json topic_json(topic_name) @@ -45,9 +43,8 @@ end end - describe "lazy topic object of a topic that does not exist" do - let(:topic) { Google::Cloud::Pubsub::Topic.new_lazy topic_name, - pubsub.service } + describe "reference topic object of a topic that does not exist" do + let(:topic) { Google::Cloud::Pubsub::Topic.from_name topic_name, pubsub.service } it "checks if the topic exists by making an HTTP call" do stub = Object.new diff --git a/google-cloud-pubsub/test/google/cloud/pubsub/topic/lazy_test.rb b/google-cloud-pubsub/test/google/cloud/pubsub/topic/lazy_test.rb index cc45f2bb3dbb..6286eb9b0a03 100644 --- a/google-cloud-pubsub/test/google/cloud/pubsub/topic/lazy_test.rb +++ b/google-cloud-pubsub/test/google/cloud/pubsub/topic/lazy_test.rb @@ -14,12 +14,12 @@ require "helper" -describe Google::Cloud::Pubsub::Topic, :lazy, :mock_pubsub do +describe Google::Cloud::Pubsub::Topic, :reference, :mock_pubsub do let(:topic_name) { "topic-name-goes-here" } - let(:topic) { Google::Cloud::Pubsub::Topic.from_grpc Google::Pubsub::V1::Topic.decode_json(topic_json(topic_name)), - pubsub.service } + let(:topic) { Google::Cloud::Pubsub::Topic.from_grpc Google::Pubsub::V1::Topic.decode_json(topic_json(topic_name)), pubsub.service } - it "is not lazy when created with an HTTP method" do - topic.wont_be :lazy? + it "is not reference when created with an HTTP method" do + topic.wont_be :reference? + topic.must_be :resource? end end diff --git a/google-cloud-pubsub/test/google/cloud/pubsub/topic/name_test.rb b/google-cloud-pubsub/test/google/cloud/pubsub/topic/name_test.rb index ff20f3b2f118..0229aaa7d986 100644 --- a/google-cloud-pubsub/test/google/cloud/pubsub/topic/name_test.rb +++ b/google-cloud-pubsub/test/google/cloud/pubsub/topic/name_test.rb @@ -16,8 +16,7 @@ describe Google::Cloud::Pubsub::Topic, :name, :mock_pubsub do let(:topic_name) { "topic-name-goes-here" } - let(:topic) { Google::Cloud::Pubsub::Topic.from_grpc Google::Pubsub::V1::Topic.decode_json(topic_json(topic_name)), - pubsub.service } + let(:topic) { Google::Cloud::Pubsub::Topic.from_grpc Google::Pubsub::V1::Topic.decode_json(topic_json(topic_name)), pubsub.service } it "gives the name returned from the HTTP method" do topic.name.must_equal "projects/#{project}/topics/#{topic_name}" diff --git a/google-cloud-pubsub/test/google/cloud/pubsub/topic/policy_test.rb b/google-cloud-pubsub/test/google/cloud/pubsub/topic/policy_test.rb index ce11d583f4b8..72d0cab13e08 100644 --- a/google-cloud-pubsub/test/google/cloud/pubsub/topic/policy_test.rb +++ b/google-cloud-pubsub/test/google/cloud/pubsub/topic/policy_test.rb @@ -16,8 +16,7 @@ describe Google::Cloud::Pubsub::Topic, :policy, :mock_pubsub do let(:topic_name) { "topic-name-goes-here" } - let(:topic) { Google::Cloud::Pubsub::Topic.from_grpc Google::Pubsub::V1::Topic.decode_json(topic_json(topic_name)), - pubsub.service } + let(:topic) { Google::Cloud::Pubsub::Topic.from_grpc Google::Pubsub::V1::Topic.decode_json(topic_json(topic_name)), pubsub.service } it "gets the IAM Policy" do policy_json = { diff --git a/google-cloud-pubsub/test/google/cloud/pubsub/topic/publish_async_test.rb b/google-cloud-pubsub/test/google/cloud/pubsub/topic/publish_async_test.rb index 144b64d754d6..d8b5886a2ae4 100644 --- a/google-cloud-pubsub/test/google/cloud/pubsub/topic/publish_async_test.rb +++ b/google-cloud-pubsub/test/google/cloud/pubsub/topic/publish_async_test.rb @@ -16,8 +16,7 @@ describe Google::Cloud::Pubsub::Topic, :publish_async, :mock_pubsub do let(:topic_name) { "topic-name-goes-here" } - let(:topic) { Google::Cloud::Pubsub::Topic.from_grpc Google::Pubsub::V1::Topic.decode_json(topic_json(topic_name)), - pubsub.service } + let(:topic) { Google::Cloud::Pubsub::Topic.from_grpc Google::Pubsub::V1::Topic.decode_json(topic_json(topic_name)), pubsub.service } it "publishes a message" do messages = [ @@ -234,8 +233,8 @@ mock.verify end - describe "lazy topic that exists" do - let(:topic) { Google::Cloud::Pubsub::Topic.new_lazy topic_name, + describe "reference topic that exists" do + let(:topic) { Google::Cloud::Pubsub::Topic.from_name topic_name, pubsub.service, autocreate: false } @@ -318,8 +317,8 @@ end end - describe "lazy topic that does not exist" do - let(:topic) { Google::Cloud::Pubsub::Topic.new_lazy topic_name, + describe "reference topic that does not exist" do + let(:topic) { Google::Cloud::Pubsub::Topic.from_name topic_name, pubsub.service, autocreate: false } let(:gax_error) do diff --git a/google-cloud-pubsub/test/google/cloud/pubsub/topic/publish_test.rb b/google-cloud-pubsub/test/google/cloud/pubsub/topic/publish_test.rb index 201c81f6f41a..28a635c5b901 100644 --- a/google-cloud-pubsub/test/google/cloud/pubsub/topic/publish_test.rb +++ b/google-cloud-pubsub/test/google/cloud/pubsub/topic/publish_test.rb @@ -16,8 +16,7 @@ describe Google::Cloud::Pubsub::Topic, :publish, :mock_pubsub do let(:topic_name) { "topic-name-goes-here" } - let(:topic) { Google::Cloud::Pubsub::Topic.from_grpc Google::Pubsub::V1::Topic.decode_json(topic_json(topic_name)), - pubsub.service } + let(:topic) { Google::Cloud::Pubsub::Topic.from_grpc Google::Pubsub::V1::Topic.decode_json(topic_json(topic_name)), pubsub.service } let(:message1) { "new-message-here" } let(:message2) { "second-new-message" } let(:message3) { "third-new-message" } @@ -128,9 +127,8 @@ msgs.last.attributes["format"].must_equal "none" end - describe "lazy topic that exists" do - let(:topic) { Google::Cloud::Pubsub::Topic.new_lazy topic_name, - pubsub.service } + describe "reference topic that exists" do + let(:topic) { Google::Cloud::Pubsub::Topic.from_name topic_name, pubsub.service } it "publishes a message" do messages = [ @@ -194,9 +192,8 @@ end end - describe "lazy topic that does not exist" do - let(:topic) { Google::Cloud::Pubsub::Topic.new_lazy topic_name, - pubsub.service } + describe "reference topic that does not exist" do + let(:topic) { Google::Cloud::Pubsub::Topic.from_name topic_name, pubsub.service } it "publishes a message" do stub = Object.new diff --git a/google-cloud-pubsub/test/google/cloud/pubsub/topic/subscribe_test.rb b/google-cloud-pubsub/test/google/cloud/pubsub/topic/subscribe_test.rb index 6ec125fb73e1..65577cb03e24 100644 --- a/google-cloud-pubsub/test/google/cloud/pubsub/topic/subscribe_test.rb +++ b/google-cloud-pubsub/test/google/cloud/pubsub/topic/subscribe_test.rb @@ -16,8 +16,7 @@ describe Google::Cloud::Pubsub::Topic, :subscribe, :mock_pubsub do let(:topic_name) { "topic-name-goes-here" } - let(:topic) { Google::Cloud::Pubsub::Topic.from_grpc Google::Pubsub::V1::Topic.decode_json(topic_json(topic_name)), - pubsub.service } + let(:topic) { Google::Cloud::Pubsub::Topic.from_grpc Google::Pubsub::V1::Topic.decode_json(topic_json(topic_name)), pubsub.service } let(:new_sub_name) { "new-sub-#{Time.now.to_i}" } let(:labels) { { "foo" => "bar" } } @@ -51,9 +50,8 @@ sub.labels.must_be :frozen? end - describe "lazy topic that exists" do - let(:topic) { Google::Cloud::Pubsub::Topic.new_lazy topic_name, - pubsub.service } + describe "reference topic that exists" do + let(:topic) { Google::Cloud::Pubsub::Topic.from_name topic_name, pubsub.service } it "creates a subscription when calling subscribe" do create_res = Google::Pubsub::V1::Subscription.decode_json subscription_json(topic_name, new_sub_name) @@ -70,9 +68,8 @@ end end - describe "lazy topic that does not exist" do - let(:topic) { Google::Cloud::Pubsub::Topic.new_lazy topic_name, - pubsub.service } + describe "reference topic that does not exist" do + let(:topic) { Google::Cloud::Pubsub::Topic.from_name topic_name, pubsub.service } it "raises NotFoundError when calling subscribe" do stub = Object.new diff --git a/google-cloud-pubsub/test/google/cloud/pubsub/topic/subscription_test.rb b/google-cloud-pubsub/test/google/cloud/pubsub/topic/subscription_test.rb index 525823ac45dc..f402ae45fa00 100644 --- a/google-cloud-pubsub/test/google/cloud/pubsub/topic/subscription_test.rb +++ b/google-cloud-pubsub/test/google/cloud/pubsub/topic/subscription_test.rb @@ -16,8 +16,7 @@ describe Google::Cloud::Pubsub::Topic, :subscription, :mock_pubsub do let(:topic_name) { "topic-name-goes-here" } - let(:topic) { Google::Cloud::Pubsub::Topic.from_grpc Google::Pubsub::V1::Topic.decode_json(topic_json(topic_name)), - pubsub.service } + let(:topic) { Google::Cloud::Pubsub::Topic.from_grpc Google::Pubsub::V1::Topic.decode_json(topic_json(topic_name)), pubsub.service } let(:found_sub_name) { "found-sub-#{Time.now.to_i}" } let(:not_found_sub_name) { "found-sub-#{Time.now.to_i}" } @@ -32,7 +31,8 @@ mock.verify sub.must_be_kind_of Google::Cloud::Pubsub::Subscription - sub.wont_be :lazy? + sub.wont_be :reference? + sub.must_be :resource? end it "gets an existing subscription with get_subscription alias" do @@ -46,7 +46,8 @@ mock.verify sub.must_be_kind_of Google::Cloud::Pubsub::Subscription - sub.wont_be :lazy? + sub.wont_be :reference? + sub.must_be :resource? end it "gets an existing subscription with find_subscription alias" do @@ -60,7 +61,8 @@ mock.verify sub.must_be_kind_of Google::Cloud::Pubsub::Subscription - sub.wont_be :lazy? + sub.wont_be :reference? + sub.must_be :resource? end it "returns nil when getting an non-existant subscription" do @@ -81,12 +83,12 @@ def stub.get_subscription *args sub = topic.find_subscription found_sub_name, skip_lookup: true sub.must_be_kind_of Google::Cloud::Pubsub::Subscription - sub.must_be :lazy? + sub.must_be :reference? + sub.wont_be :resource? end - describe "lazy topic that exists" do - let(:topic) { Google::Cloud::Pubsub::Topic.new_lazy topic_name, - pubsub.service } + describe "reference topic that exists" do + let(:topic) { Google::Cloud::Pubsub::Topic.from_name topic_name, pubsub.service } it "gets an existing subscription" do get_res = Google::Pubsub::V1::Subscription.decode_json subscription_json(topic_name, found_sub_name) @@ -99,7 +101,8 @@ def stub.get_subscription *args mock.verify sub.must_be_kind_of Google::Cloud::Pubsub::Subscription - sub.wont_be :lazy? + sub.wont_be :reference? + sub.must_be :resource? end it "returns nil when getting an non-existant subscription" do @@ -116,9 +119,8 @@ def stub.get_subscription *args end end - describe "lazy topic that does not exist" do - let(:topic) { Google::Cloud::Pubsub::Topic.new_lazy topic_name, - pubsub.service } + describe "reference topic that does not exist" do + let(:topic) { Google::Cloud::Pubsub::Topic.from_name topic_name, pubsub.service } it "returns nil when getting an non-existant subscription" do stub = Object.new diff --git a/google-cloud-pubsub/test/google/cloud/pubsub/topic/subscriptions_test.rb b/google-cloud-pubsub/test/google/cloud/pubsub/topic/subscriptions_test.rb index 6e4b6438269a..f2696d20b70a 100644 --- a/google-cloud-pubsub/test/google/cloud/pubsub/topic/subscriptions_test.rb +++ b/google-cloud-pubsub/test/google/cloud/pubsub/topic/subscriptions_test.rb @@ -16,8 +16,7 @@ describe Google::Cloud::Pubsub::Topic, :subscriptions, :mock_pubsub do let(:topic_name) { "topic-name-goes-here" } - let(:topic) { Google::Cloud::Pubsub::Topic.from_grpc Google::Pubsub::V1::Topic.decode_json(topic_json(topic_name)), - pubsub.service } + let(:topic) { Google::Cloud::Pubsub::Topic.from_grpc Google::Pubsub::V1::Topic.decode_json(topic_json(topic_name)), pubsub.service } let(:subscriptions_with_token) do response = Google::Pubsub::V1::ListTopicSubscriptionsResponse.decode_json topic_subscriptions_json(3, "next_page_token") paged_enum_struct response @@ -35,13 +34,13 @@ subs.count.must_equal 3 subs.each do |sub| sub.must_be_kind_of Google::Cloud::Pubsub::Subscription - sub.must_be :lazy? + sub.must_be :reference? + sub.wont_be :resource? end end - describe "lazy topic that exists" do - let(:topic) { Google::Cloud::Pubsub::Topic.new_lazy topic_name, - pubsub.service } + describe "reference topic that exists" do + let(:topic) { Google::Cloud::Pubsub::Topic.from_name topic_name, pubsub.service } it "lists subscriptions" do mock = Minitest::Mock.new @@ -55,14 +54,14 @@ subs.count.must_equal 3 subs.each do |sub| sub.must_be_kind_of Google::Cloud::Pubsub::Subscription - sub.must_be :lazy? + sub.must_be :reference? + sub.wont_be :resource? end end end - describe "lazy topic that does not exist" do - let(:topic) { Google::Cloud::Pubsub::Topic.new_lazy topic_name, - pubsub.service } + describe "reference topic that does not exist" do + let(:topic) { Google::Cloud::Pubsub::Topic.from_name topic_name, pubsub.service } it "lists subscriptions" do stub = Object.new diff --git a/google-cloud-pubsub/test/google/cloud/pubsub/topic/update_test.rb b/google-cloud-pubsub/test/google/cloud/pubsub/topic/update_test.rb index e59c40e2ea8e..2adba26fa8aa 100644 --- a/google-cloud-pubsub/test/google/cloud/pubsub/topic/update_test.rb +++ b/google-cloud-pubsub/test/google/cloud/pubsub/topic/update_test.rb @@ -70,11 +70,12 @@ topic.labels.must_equal labels end - describe :lazy do - let(:topic) { Google::Cloud::Pubsub::Topic.new_lazy topic_name, pubsub.service } + describe :reference do + let(:topic) { Google::Cloud::Pubsub::Topic.from_name topic_name, pubsub.service } it "updates labels" do - topic.must_be :lazy? + topic.must_be :reference? + topic.wont_be :resource? update_grpc = Google::Pubsub::V1::Topic.new \ name: topic_path(topic_name), @@ -89,7 +90,8 @@ mock.verify - topic.wont_be :lazy? + topic.wont_be :reference? + topic.must_be :resource? topic.labels.must_equal new_labels end end diff --git a/google-cloud-pubsub/test/google/cloud/pubsub/topic_test.rb b/google-cloud-pubsub/test/google/cloud/pubsub/topic_test.rb index 6163c3e9434b..bf3bac47328f 100644 --- a/google-cloud-pubsub/test/google/cloud/pubsub/topic_test.rb +++ b/google-cloud-pubsub/test/google/cloud/pubsub/topic_test.rb @@ -17,8 +17,7 @@ describe Google::Cloud::Pubsub::Topic, :mock_pubsub do let(:topic_name) { "topic-name-goes-here" } let(:labels) { { "foo" => "bar" } } - let(:topic) { Google::Cloud::Pubsub::Topic.from_grpc Google::Pubsub::V1::Topic.decode_json(topic_json(topic_name, labels: labels)), - pubsub.service } + let(:topic) { Google::Cloud::Pubsub::Topic.from_grpc Google::Pubsub::V1::Topic.decode_json(topic_json(topic_name, labels: labels)), pubsub.service } let(:subscriptions_with_token) do response = Google::Pubsub::V1::ListTopicSubscriptionsResponse.decode_json topic_subscriptions_json(3, "next_page_token") paged_enum_struct response @@ -211,7 +210,8 @@ def stub.create_subscription *args sub.wont_be :nil? sub.must_be_kind_of Google::Cloud::Pubsub::Subscription - sub.wont_be :lazy? + sub.wont_be :reference? + sub.must_be :resource? end it "gets a subscription with get_subscription alias" do @@ -228,7 +228,8 @@ def stub.create_subscription *args sub.wont_be :nil? sub.must_be_kind_of Google::Cloud::Pubsub::Subscription - sub.wont_be :lazy? + sub.wont_be :reference? + sub.must_be :resource? end it "gets a subscription with find_subscription alias" do @@ -245,7 +246,8 @@ def stub.create_subscription *args sub.wont_be :nil? sub.must_be_kind_of Google::Cloud::Pubsub::Subscription - sub.wont_be :lazy? + sub.wont_be :reference? + sub.must_be :resource? end it "lists subscriptions" do @@ -260,7 +262,8 @@ def stub.create_subscription *args subs.count.must_equal 3 subs.each do |sub| sub.must_be_kind_of Google::Cloud::Pubsub::Subscription - sub.must_be :lazy? + sub.must_be :reference? + sub.wont_be :resource? end end @@ -274,7 +277,8 @@ def stub.create_subscription *args subs.count.must_equal 3 subs.each do |sub| sub.must_be_kind_of Google::Cloud::Pubsub::Subscription - sub.must_be :lazy? + sub.must_be :reference? + sub.wont_be :resource? end end @@ -290,7 +294,8 @@ def stub.create_subscription *args subs.count.must_equal 3 subs.each do |sub| sub.must_be_kind_of Google::Cloud::Pubsub::Subscription - sub.must_be :lazy? + sub.must_be :reference? + sub.wont_be :resource? end end @@ -312,14 +317,16 @@ def stub.create_subscription *args token.must_equal "next_page_token" first_subs.each do |sub| sub.must_be_kind_of Google::Cloud::Pubsub::Subscription - sub.must_be :lazy? + sub.must_be :reference? + sub.wont_be :resource? end second_subs.count.must_equal 2 second_subs.token.must_be :nil? second_subs.each do |sub| sub.must_be_kind_of Google::Cloud::Pubsub::Subscription - sub.must_be :lazy? + sub.must_be :reference? + sub.wont_be :resource? end end @@ -338,7 +345,8 @@ def stub.create_subscription *args token.must_equal "next_page_token" subs.each do |sub| sub.must_be_kind_of Google::Cloud::Pubsub::Subscription - sub.must_be :lazy? + sub.must_be :reference? + sub.wont_be :resource? end end @@ -358,14 +366,16 @@ def stub.create_subscription *args first_subs.next?.must_equal true first_subs.each do |sub| sub.must_be_kind_of Google::Cloud::Pubsub::Subscription - sub.must_be :lazy? + sub.must_be :reference? + sub.wont_be :resource? end second_subs.count.must_equal 2 second_subs.next?.must_equal false second_subs.each do |sub| sub.must_be_kind_of Google::Cloud::Pubsub::Subscription - sub.must_be :lazy? + sub.must_be :reference? + sub.wont_be :resource? end end @@ -385,14 +395,16 @@ def stub.create_subscription *args first_subs.next?.must_equal true first_subs.each do |sub| sub.must_be_kind_of Google::Cloud::Pubsub::Subscription - sub.must_be :lazy? + sub.must_be :reference? + sub.wont_be :resource? end second_subs.count.must_equal 2 second_subs.next?.must_equal false second_subs.each do |sub| sub.must_be_kind_of Google::Cloud::Pubsub::Subscription - sub.must_be :lazy? + sub.must_be :reference? + sub.wont_be :resource? end end @@ -410,7 +422,8 @@ def stub.create_subscription *args subs.count.must_equal 5 subs.each do |sub| sub.must_be_kind_of Google::Cloud::Pubsub::Subscription - sub.must_be :lazy? + sub.must_be :reference? + sub.wont_be :resource? end end @@ -428,7 +441,8 @@ def stub.create_subscription *args subs.count.must_equal 5 subs.each do |sub| sub.must_be_kind_of Google::Cloud::Pubsub::Subscription - sub.must_be :lazy? + sub.must_be :reference? + sub.wont_be :resource? end end @@ -446,7 +460,8 @@ def stub.create_subscription *args subs.count.must_equal 5 subs.each do |sub| sub.must_be_kind_of Google::Cloud::Pubsub::Subscription - sub.must_be :lazy? + sub.must_be :reference? + sub.wont_be :resource? end end @@ -464,7 +479,8 @@ def stub.create_subscription *args subs.count.must_equal 6 subs.each do |sub| sub.must_be_kind_of Google::Cloud::Pubsub::Subscription - sub.must_be :lazy? + sub.must_be :reference? + sub.wont_be :resource? end end