Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Commit

Permalink
Merge pull request #2 from andrerod/optionsqueue
Browse files Browse the repository at this point in the history
#105 Queue: Inconsistent use of optional parameters vs. options parameter
  • Loading branch information
André Rodrigues committed Nov 18, 2012
2 parents 7f50e79 + 9e7a3ef commit 6286833
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 18 deletions.
51 changes: 36 additions & 15 deletions lib/azure/storage/queue/queue_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,20 @@ def clear_messages(queue_name)

# Public: Creates a new queue under the storage account.
#
# queue_name - String. The queue name.
# metadata - Hash. A hash of user defined metadata (optional)
# queue_name - String. The queue name.
# options - Hash. Optional parameters.
#
# Accepted key/value pairs in options parameter are:
# :metadata - Hash. A hash of user defined metadata (optional)
#
# See http://msdn.microsoft.com/en-us/library/windowsazure/dd179342
#
# Returns true on success
def create_queue(queue_name, metadata=nil)
def create_queue(queue_name, options={})
uri = queue_uri(queue_name)
headers = {}
add_metadata_to_headers(metadata || {}, headers)
add_metadata_to_headers(options[:metadata] || {}, headers) if options[:metadata]

call(:put, uri, nil, headers)
nil
end
Expand Down Expand Up @@ -182,16 +186,19 @@ def get_queue_acl(queue_name)

# Public: Sets the access control list (ACL) for the queue.
#
# queue_name - String. The queue name.
# signed_identifiers - Array. A list of Azure::Entity::SignedIdentifier instances
# queue_name - String. The queue name.
# options - Hash. Optional parameters.
#
# Accepted key/value pairs in options parameter are:
# :signed_identifiers - Array. A list of Azure::Entity::SignedIdentifier instances
#
# See http://msdn.microsoft.com/en-us/library/windowsazure/jj159099
#
# Returns true on success
def set_queue_acl(queue_name, signed_identifiers=[])
def set_queue_acl(queue_name, options={})
uri =queue_uri(queue_name, {"comp"=>"acl"})
body = nil
body = Serialization.signed_identifiers_to_xml(signed_identifiers) if signed_identifiers && signed_identifiers.length > 0
body = Serialization.signed_identifiers_to_xml(options[:signed_identifiers]) if options[:signed_identifiers] && options[:signed_identifiers].length > 0

call(:put, uri, body, {})
nil
Expand All @@ -201,7 +208,9 @@ def set_queue_acl(queue_name, signed_identifiers=[])
#
# queue_name - String. The queue name.
# message_text - String. The message contents. Note that the message content must be in a format that may be encoded with UTF-8.
# options - Hash. Optional parameters:
# options - Hash. Optional parameters.
#
# Accepted key/value pairs in options parameter are:
# :visibility_timeout - Integer. Specifies the new visibility timeout value, in seconds, relative to server
# time. The new value must be larger than or equal to 0, and cannot be larger than 7
# days. The visibility timeout of a message cannot be set to a value later than the
Expand All @@ -214,10 +223,10 @@ def set_queue_acl(queue_name, signed_identifiers=[])
# See http://msdn.microsoft.com/en-us/library/windowsazure/dd179346
#
# Returns true on success
def create_message(queue_name, message_text, options=nil)
def create_message(queue_name, message_text, options={})
query = {}

if options
unless options.empty?
query["visibilitytimeout"] = options[:visibility_timeout] if options[:visibility_timeout]
query["messagettl"] = options[:message_ttl] if options[:message_ttl]
end
Expand Down Expand Up @@ -287,12 +296,18 @@ def delete_message(queue_name, message_id, pop_receipt)
# Public: Retrieves one or more messages from the front of the queue, without changing the message visibility.
#
# queue_name - String. The name of the queue.
# number_of_messages - Integer. How many messages to return. (optional, Default: 1)
# options - Hash. Optional parameters.
#
# Accepted key/value pairs in options parameter are:
# :number_of_messages - Integer. How many messages to return. (optional, Default: 1)
#
# See http://msdn.microsoft.com/en-us/library/windowsazure/dd179472
#
# Returns a list of Azure::Entity::Queue::Message instances
def peek_messages(queue_name, number_of_messages=1)
def peek_messages(queue_name, options={})
number_of_messages=1
number_of_messages = options[:number_of_messages] if options[:number_of_messages]

uri = messages_uri(queue_name, { "peekonly" => "true", "numofmessages"=> number_of_messages.to_s})
response = call(:get, uri)

Expand All @@ -304,12 +319,18 @@ def peek_messages(queue_name, number_of_messages=1)
#
# queue_name - String. The name of the queue.
# visibility_timeout - Integer. The new visibility timeout value, in seconds, relative to server time.
# number_of_messages - Integer. How many messages to return. (optional, Default: 1)
# options - Hash. Optional parameters.
#
# Accepted key/value pairs in options parameter are:
# :number_of_messages - Integer. How many messages to return. (optional, Default: 1)
#
# See http://msdn.microsoft.com/en-us/library/windowsazure/dd179474
#
# Returns a list of Azure::Entity::Queue::Message instances
def list_messages(queue_name, visibility_timeout, number_of_messages=1)
def list_messages(queue_name, visibility_timeout, options={})
number_of_messages=1
number_of_messages = options[:number_of_messages] if options[:number_of_messages]

uri = messages_uri(queue_name, { "visibilitytimeout" => visibility_timeout.to_s, "numofmessages"=> number_of_messages.to_s})
response = call(:get, uri)

Expand Down
15 changes: 14 additions & 1 deletion test/integration/storage/queue/create_queue_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,26 @@

describe '#create_queue' do
let(:queue_name){ QueueNameHelper.name }
let(:metadata){ {"custommetadata" => "CustomMetadataValue"} }
after { QueueNameHelper.clean }

it "creates a queue with a valid name" do
result = subject.create_queue(queue_name)
result = subject.create_queue queue_name
result.must_be_nil
end

it "creates a queue with a valid name and metadata" do
result = subject.create_queue queue_name, { :metadata => metadata }
result.must_be_nil

message_count, queue_metadata = subject.get_queue_metadata queue_name

metadata.each { |k,v|
queue_metadata.must_include k
queue_metadata[k].must_equal v
}
end

it "errors on an invalid queue name" do
assert_raises(Azure::Core::Http::HTTPError) do
subject.create_queue "this_queue.cannot-exist!"
Expand Down
2 changes: 1 addition & 1 deletion test/integration/storage/queue/list_messages_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
msg_text2 = "some random text " + QueueNameHelper.name
subject.create_message queue_name, msg_text2

result = subject.list_messages queue_name, 3, 2
result = subject.list_messages queue_name, 3, { :number_of_messages => 2 }
result.wont_be_nil
result.wont_be_empty
result.length.must_equal 2
Expand Down
2 changes: 1 addition & 1 deletion test/integration/storage/queue/peek_messages_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
msg_text2 = "some random text " + QueueNameHelper.name
subject.create_message queue_name, msg_text2

result = subject.peek_messages queue_name, 2
result = subject.peek_messages queue_name, { :number_of_messages => 2 }
result.wont_be_nil
result.wont_be_empty
result.length.must_equal 2
Expand Down

0 comments on commit 6286833

Please sign in to comment.