зеркало из
1
0
Форкнуть 0

integration tests for QueueService

This commit is contained in:
Troy Howard 2012-10-18 20:33:37 -07:00
Родитель 4ada1c5fdf
Коммит ac4bec60c5
10 изменённых файлов: 544 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,41 @@
#-------------------------------------------------------------------------
# Copyright (c) Microsoft. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
require "integration/test_helper"
require "azure/storage/queue/queue_service"
describe Azure::Storage::Queue::QueueService do
subject { Azure::Storage::Queue::QueueService.new }
describe '#clear_messages' do
let(:queue_name){ QueueNameHelper.name }
before {
subject.create_queue queue_name
subject.create_message queue_name, "some random text " + QueueNameHelper.name
}
after { QueueNameHelper.clean }
it "clears the queue" do
assert subject.clear_messages queue_name
result = subject.peek_messages queue_name
result.must_be_empty
end
it "errors on an non-existent queue" do
assert_raises(Azure::Core::Http::HTTPError) do
subject.clear_messages QueueNameHelper.name
end
end
end
end

Просмотреть файл

@ -0,0 +1,70 @@
#-------------------------------------------------------------------------
# Copyright (c) Microsoft. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
require "integration/test_helper"
require "azure/storage/queue/queue_service"
describe Azure::Storage::Queue::QueueService do
subject { Azure::Storage::Queue::QueueService.new }
describe '#create_message' do
let(:queue_name){ QueueNameHelper.name }
let(:message_text) { "message text random value: #{QueueNameHelper.name}" }
before { subject.create_queue queue_name }
after { QueueNameHelper.clean }
it "creates a message in the specified queue and returns true on success" do
assert subject.create_message(queue_name, message_text), "create_message failed"
result = subject.peek_messages queue_name
result.wont_be_nil
result.wont_be_empty
result.length.must_equal 1
result[0].message_text.must_equal message_text
end
describe "when the options hash is used" do
let(:visibility_timeout) { 3 }
let(:message_ttl) { 600 }
it "the :visibility_timeout option causes the message to be invisible for a period of time" do
assert subject.create_message(queue_name, message_text, { :visibility_timeout=> visibility_timeout }), "create_message failed"
result = subject.peek_messages queue_name
result.length.must_equal 0
sleep(visibility_timeout)
result = subject.peek_messages queue_name
result.length.must_equal 1
result.wont_be_empty
result[0].message_text.must_equal message_text
end
it "the :message_ttl option modifies the expiration_date of the message" do
assert subject.create_message(queue_name, message_text, { :message_ttl=> message_ttl }), "create_message failed"
result = subject.peek_messages queue_name
result.wont_be_nil
result.wont_be_empty
message = result[0]
message.message_text.must_equal message_text
Time.parse(message.expiration_time).to_i.must_equal Time.parse(message.insertion_time).to_i + message_ttl
end
end
it "errors on an non-existent queue" do
assert_raises(Azure::Core::Http::HTTPError) do
subject.create_message QueueNameHelper.name, message_text
end
end
end
end

Просмотреть файл

@ -0,0 +1,36 @@
#-------------------------------------------------------------------------
# Copyright (c) Microsoft. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
require "integration/test_helper"
require "azure/storage/queue/queue_service"
require "azure/core/http/http_error"
describe Azure::Storage::Queue::QueueService do
subject { Azure::Storage::Queue::QueueService.new }
describe '#create_queue' do
let(:queue_name){ QueueNameHelper.name }
after { QueueNameHelper.clean }
it "creates a queue with a valid name" do
assert subject.create_queue(queue_name)
end
it "errors on an invalid queue name" do
assert_raises(Azure::Core::Http::HTTPError) do
subject.create_queue "this_queue.cannot-exist!"
end
end
end
end

Просмотреть файл

@ -0,0 +1,66 @@
#-------------------------------------------------------------------------
# Copyright (c) Microsoft. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
require "integration/test_helper"
require "azure/storage/queue/queue_service"
describe Azure::Storage::Queue::QueueService do
subject { Azure::Storage::Queue::QueueService.new }
describe '#delete_message' do
let(:queue_name){ QueueNameHelper.name }
before {
subject.create_queue queue_name
subject.create_message queue_name, "some random text " + QueueNameHelper.name
}
after { QueueNameHelper.clean }
it "deletes a message" do
messages = subject.list_messages queue_name, 500
messages.length.must_equal 1
message = messages.first
assert subject.delete_message queue_name, message.id, message.pop_receipt
result = subject.peek_messages queue_name
result.must_be_empty
end
it "errors on an non-existent queue" do
assert_raises(Azure::Core::Http::HTTPError) do
subject.delete_message QueueNameHelper.name, "message.id", "message.pop_receipt"
end
end
it "errors on an non-existent message id" do
messages = subject.list_messages queue_name, 500
messages.length.must_equal 1
message = messages.first
assert_raises(Azure::Core::Http::HTTPError) do
subject.delete_message queue_name, "bad.message.id", message.pop_receipt
end
end
it "errors on an non-existent pop_receipt" do
messages = subject.list_messages queue_name, 500
messages.length.must_equal 1
message = messages.first
assert_raises(Azure::Core::Http::HTTPError) do
subject.delete_message queue_name, message.id, "bad.message.pop_receipt"
end
end
end
end

Просмотреть файл

@ -0,0 +1,44 @@
#-------------------------------------------------------------------------
# Copyright (c) Microsoft. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
require "integration/test_helper"
require "azure/storage/queue/queue_service"
describe Azure::Storage::Queue::QueueService do
subject { Azure::Storage::Queue::QueueService.new }
describe '#delete_queue' do
let(:queue_name){ QueueNameHelper.name }
before { subject.create_queue queue_name }
after { QueueNameHelper.clean }
it "deletes a queue and returns true on success" do
assert subject.delete_queue(queue_name)
result = subject.list_queues
result.queues.each { |q| q.name.wont_equal queue_name }
end
it "errors on an non-existent queue" do
assert_raises(Azure::Core::Http::HTTPError) do
subject.delete_queue QueueNameHelper.name
end
end
it "errors on an invalid queue" do
assert_raises(Azure::Core::Http::HTTPError) do
subject.delete_queue "this_queue.cannot-exist!"
end
end
end
end

Просмотреть файл

@ -0,0 +1,79 @@
#-------------------------------------------------------------------------
# Copyright (c) Microsoft. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
require "integration/test_helper"
require "azure/storage/queue/queue_service"
describe Azure::Storage::Queue::QueueService do
subject { Azure::Storage::Queue::QueueService.new }
describe '#list_messages' do
let(:queue_name){ QueueNameHelper.name }
let(:message_text){ "some random text " + QueueNameHelper.name }
before {
subject.create_queue queue_name
subject.create_message queue_name, message_text
}
after { QueueNameHelper.clean }
it "returns a message from the queue, marking it as invisible" do
result = subject.list_messages queue_name, 3
result.wont_be_nil
result.wont_be_empty
result.length.must_equal 1
message = result[0]
message.message_text.must_equal message_text
# queue should be empty
result = subject.list_messages queue_name, 1
result.must_be_empty
end
it "returns multiple messages if passed the optional parameter" do
msg_text2 = "some random text " + QueueNameHelper.name
subject.create_message queue_name, msg_text2
result = subject.list_messages queue_name, 3, 2
result.wont_be_nil
result.wont_be_empty
result.length.must_equal 2
result[0].message_text.must_equal message_text
result[1].message_text.must_equal msg_text2
result[0].id.wont_equal result[1].id
end
it "the visibility_timeout parameter sets the message invisible for the period of time pending delete/update" do
result = subject.list_messages queue_name, 3
result.wont_be_nil
result.wont_be_empty
result.length.must_equal 1
message = result[0]
message.message_text.must_equal message_text
# queue should be empty
result = subject.list_messages queue_name, 1
result.must_be_empty
sleep(3)
# same message is back at the top of the queue after timeout period
result = subject.list_messages queue_name, 3
result.wont_be_nil
result.wont_be_empty
result.length.must_equal 1
message2 = result[0]
message2.id.must_equal message.id
end
end
end

Просмотреть файл

@ -0,0 +1,36 @@
#-------------------------------------------------------------------------
# Copyright (c) Microsoft. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
require "integration/test_helper"
require "azure/storage/queue/queue_service"
describe Azure::Storage::Queue::QueueService do
subject { Azure::Storage::Queue::QueueService.new }
describe '#list_queues' do
let(:queue_names){ [QueueNameHelper.name, QueueNameHelper.name] }
before { queue_names.each { |q| subject.create_queue q } }
after { QueueNameHelper.clean }
it 'lists the available queues' do
result = subject.list_queues
expected_queues = 0
result.queues.each { |q|
expected_queues += 1 if queue_names.include? q.name
}
expected_queues.must_equal queue_names.length
end
end
end

Просмотреть файл

@ -0,0 +1,59 @@
#-------------------------------------------------------------------------
# Copyright (c) Microsoft. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
require "integration/test_helper"
require "azure/storage/queue/queue_service"
describe Azure::Storage::Queue::QueueService do
subject { Azure::Storage::Queue::QueueService.new }
describe '#peek_messages' do
let(:queue_name){ QueueNameHelper.name }
let(:message_text) { "some random text " + QueueNameHelper.name}
before {
subject.create_queue queue_name
subject.create_message queue_name, message_text
}
after { QueueNameHelper.clean }
it "returns a message from the queue without marking it as invisible" do
result = subject.peek_messages queue_name
result.wont_be_nil
result.wont_be_empty
result.length.must_equal 1
message = result[0]
message.message_text.must_equal message_text
# the same message is returned on another call, because it's still at the top of the queue
result = subject.peek_messages queue_name
result.wont_be_nil
result.wont_be_empty
result.length.must_equal 1
result[0].id.must_equal message.id
end
it "returns multiple messages if passed the optional parameter" do
msg_text2 = "some random text " + QueueNameHelper.name
subject.create_message queue_name, msg_text2
result = subject.peek_messages queue_name, 2
result.wont_be_nil
result.wont_be_empty
result.length.must_equal 2
result[0].message_text.must_equal message_text
result[1].message_text.must_equal msg_text2
result[0].id.wont_equal result[1].id
end
end
end

Просмотреть файл

@ -0,0 +1,39 @@
#-------------------------------------------------------------------------
# Copyright (c) Microsoft. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
require "integration/test_helper"
require "azure/storage/queue/queue_service"
describe Azure::Storage::Queue::QueueService do
subject { Azure::Storage::Queue::QueueService.new }
describe '#set/get_queue_metadata' do
let(:queue_name){ QueueNameHelper.name }
before {
subject.create_queue queue_name
subject.create_message queue_name, "some random text " + QueueNameHelper.name
}
after { QueueNameHelper.clean }
it 'can set and retrieve queue metadata' do
assert subject.set_queue_metadata queue_name, {"CustomMetadataProperty" => "Custom Metadata Value"}
message_count, metadata = subject.get_queue_metadata queue_name
message_count.must_equal 1
# note: case insensitive! even though it was sent in mixed case, it will be returned in downcase
metadata.must_include "custommetadataproperty"
metadata["custommetadataproperty"].must_equal "Custom Metadata Value"
end
end
end

Просмотреть файл

@ -0,0 +1,74 @@
#-------------------------------------------------------------------------
# Copyright (c) Microsoft. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
require "integration/test_helper"
require "azure/storage/queue/queue_service"
require 'azure/core/http/http_error'
describe Azure::Storage::Queue::QueueService do
subject { Azure::Storage::Queue::QueueService.new }
describe '#update_message' do
let(:queue_name){ QueueNameHelper.name }
let(:message_text){ "some random text " + QueueNameHelper.name }
let(:new_message_text){ "this is new text!!" }
before {
subject.create_queue queue_name
subject.create_message queue_name, message_text
}
after { QueueNameHelper.clean }
it "updates a message" do
messages = subject.list_messages queue_name, 500
messages.length.must_equal 1
message = messages.first
message.message_text.must_equal message_text
pop_receipt, time_next_visible = subject.update_message queue_name, message.id, message.pop_receipt, new_message_text, 0
result = subject.peek_messages queue_name
result.wont_be_empty
message2 = result[0]
message2.id.must_equal message.id
message2.message_text.must_equal new_message_text
end
it "errors on an non-existent queue" do
assert_raises(Azure::Core::Http::HTTPError) do
subject.update_message QueueNameHelper.name, "message.id", "message.pop_receipt", new_message_text, 0
end
end
it "errors on an non-existent message id" do
messages = subject.list_messages queue_name, 500
messages.length.must_equal 1
message = messages.first
assert_raises(Azure::Core::Http::HTTPError) do
subject.update_message queue_name, "bad.message.id", message.pop_receipt, new_message_text, 0
end
end
it "errors on an non-existent pop_receipt" do
messages = subject.list_messages queue_name, 500
messages.length.must_equal 1
message = messages.first
assert_raises(Azure::Core::Http::HTTPError) do
subject.update_message queue_name, message.id, "bad.message.pop_receipt", new_message_text, 0
end
end
end
end