waz-storage 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +9 -9
- data/CHANGELOG.rdoc +72 -72
- data/Gemfile +4 -4
- data/Gemfile.lock +46 -40
- data/LICENSE +18 -18
- data/README.rdoc +310 -310
- data/lib/waz-blobs.rb +4 -4
- data/lib/waz-queues.rb +6 -6
- data/lib/waz-storage.rb +39 -39
- data/lib/waz-tables.rb +4 -4
- data/lib/waz/blobs/blob_object.rb +122 -122
- data/lib/waz/blobs/container.rb +172 -161
- data/lib/waz/blobs/exceptions.rb +10 -10
- data/lib/waz/blobs/service.rb +181 -156
- data/lib/waz/queues/exceptions.rb +28 -28
- data/lib/waz/queues/message.rb +64 -64
- data/lib/waz/queues/queue.rb +164 -164
- data/lib/waz/queues/service.rb +105 -105
- data/lib/waz/storage/base.rb +70 -70
- data/lib/waz/storage/exceptions.rb +33 -33
- data/lib/waz/storage/validation_rules.rb +25 -25
- data/lib/waz/tables/edm_type_helper.rb +44 -44
- data/lib/waz/tables/exceptions.rb +44 -44
- data/lib/waz/tables/service.rb +178 -178
- data/lib/waz/tables/table.rb +74 -74
- data/lib/waz/tables/table_array.rb +10 -10
- data/rakefile +8 -21
- data/{tests → spec}/configuration.rb +22 -22
- data/{tests/waz/blobs/blob_object_test.rb → spec/waz/blobs/blob_object_spec.rb} +80 -80
- data/{tests/waz/blobs/container_test.rb → spec/waz/blobs/container_spec.rb} +175 -162
- data/{tests/waz/blobs/service_test.rb → spec/waz/blobs/service_spec.rb} +336 -282
- data/{tests/waz/queues/message_test.rb → spec/waz/queues/message_spec.rb} +32 -32
- data/{tests/waz/queues/queue_test.rb → spec/waz/queues/queue_spec.rb} +205 -205
- data/{tests/waz/queues/service_test.rb → spec/waz/queues/service_spec.rb} +298 -298
- data/{tests → spec}/waz/storage/base_tests.rb +81 -81
- data/{tests/waz/storage/shared_key_core_service_test.rb → spec/waz/storage/shared_key_core_service_spec.rb} +141 -141
- data/{tests/waz/tables/service_test.rb → spec/waz/tables/service_spec.rb} +613 -613
- data/{tests/waz/tables/table_test.rb → spec/waz/tables/table_spec.rb} +97 -97
- data/waz-storage.gemspec +29 -27
- metadata +47 -26
@@ -1,33 +1,33 @@
|
|
1
|
-
# enabling the load of files from root (on RSpec)
|
2
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../')
|
3
|
-
require '
|
4
|
-
require 'lib/waz-queues'
|
5
|
-
|
6
|
-
describe "Message object behavior" do
|
7
|
-
it "should delete message" do
|
8
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my-account", :access_key => "key"})
|
9
|
-
WAZ::Queues::Service.any_instance.expects(:delete_message).with("queue-10", "message id", "receipt")
|
10
|
-
options = {:message_id => "message id", :message_text => "text", :expiration_time => Time.new,
|
11
|
-
:insertion_time => Time.new, :pop_receipt => "receipt", :queue_name => "queue-10"}
|
12
|
-
|
13
|
-
message = WAZ::Queues::Message.new(options)
|
14
|
-
message.destroy!
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should throw when trying to delete a message peeked (no pop_receipt)" do
|
18
|
-
options = {:message_id => "message id", :message_text => "text", :expiration_time => Time.new,
|
19
|
-
:insertion_time => Time.new, :queue_name => "queue-10" }
|
20
|
-
|
21
|
-
message = WAZ::Queues::Message.new(options)
|
22
|
-
|
23
|
-
lambda { message.destroy! }.should raise_error(WAZ::Queues::InvalidOperation)
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should respond to dequeue_count property" do
|
27
|
-
options = {:message_id => "message id", :message_text => "text", :expiration_time => Time.new,
|
28
|
-
:insertion_time => Time.new, :pop_receipt => "receipt", :queue_name => "queue-10", :dequeue_count => 1}
|
29
|
-
|
30
|
-
message = WAZ::Queues::Message.new(options)
|
31
|
-
message.dequeue_count.should == 1
|
32
|
-
end
|
1
|
+
# enabling the load of files from root (on RSpec)
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../')
|
3
|
+
require 'spec/configuration'
|
4
|
+
require 'lib/waz-queues'
|
5
|
+
|
6
|
+
describe "Message object behavior" do
|
7
|
+
it "should delete message" do
|
8
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my-account", :access_key => "key"})
|
9
|
+
WAZ::Queues::Service.any_instance.expects(:delete_message).with("queue-10", "message id", "receipt")
|
10
|
+
options = {:message_id => "message id", :message_text => "text", :expiration_time => Time.new,
|
11
|
+
:insertion_time => Time.new, :pop_receipt => "receipt", :queue_name => "queue-10"}
|
12
|
+
|
13
|
+
message = WAZ::Queues::Message.new(options)
|
14
|
+
message.destroy!
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should throw when trying to delete a message peeked (no pop_receipt)" do
|
18
|
+
options = {:message_id => "message id", :message_text => "text", :expiration_time => Time.new,
|
19
|
+
:insertion_time => Time.new, :queue_name => "queue-10" }
|
20
|
+
|
21
|
+
message = WAZ::Queues::Message.new(options)
|
22
|
+
|
23
|
+
lambda { message.destroy! }.should raise_error(WAZ::Queues::InvalidOperation)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should respond to dequeue_count property" do
|
27
|
+
options = {:message_id => "message id", :message_text => "text", :expiration_time => Time.new,
|
28
|
+
:insertion_time => Time.new, :pop_receipt => "receipt", :queue_name => "queue-10", :dequeue_count => 1}
|
29
|
+
|
30
|
+
message = WAZ::Queues::Message.new(options)
|
31
|
+
message.dequeue_count.should == 1
|
32
|
+
end
|
33
33
|
end
|
@@ -1,206 +1,206 @@
|
|
1
|
-
# enabling the load of files from root (on RSpec)
|
2
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../')
|
3
|
-
require '
|
4
|
-
require 'lib/waz-queues'
|
5
|
-
|
6
|
-
describe "Queue object behavior" do
|
7
|
-
it "should list queues by name" do
|
8
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my-account", :access_key => "key"})
|
9
|
-
WAZ::Queues::Service.any_instance.expects(:list_queues).returns([{:name => 'queue1', :url => 'queue1_url'}, {:name => 'queue2', :url => 'queue2_url'}])
|
10
|
-
containers = WAZ::Queues::Queue.list
|
11
|
-
containers.size.should == 2
|
12
|
-
containers.first().name.should == "queue1"
|
13
|
-
containers.first().url.should == "queue1_url"
|
14
|
-
containers.last().name.should == "queue2"
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should throw when not name provided for the queue" do
|
18
|
-
lambda { WAZ::Queues::Queue.new({:foo => "bar"}) }.should raise_error(WAZ::Storage::InvalidOption)
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should throw when not url provided for the queue" do
|
22
|
-
lambda { WAZ::Queues::Queue.new({:name => "mock-queue"}) }.should raise_error(WAZ::Storage::InvalidOption)
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should create queue" do
|
26
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my-account", :access_key => "key"})
|
27
|
-
WAZ::Queues::Service.any_instance.expects(:create_queue)
|
28
|
-
queue = WAZ::Queues::Queue.create('queue1')
|
29
|
-
queue.name.should == "queue1"
|
30
|
-
queue.url.should == "http://my-account.queue.core.windows.net/queue1"
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should find queue" do
|
34
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my-account", :access_key => "key"})
|
35
|
-
WAZ::Queues::Service.any_instance.expects(:get_queue_metadata).returns { }
|
36
|
-
queue = WAZ::Queues::Queue.find('queue1')
|
37
|
-
queue.name.should == "queue1"
|
38
|
-
queue.url.should == "http://my-account.queue.core.windows.net/queue1"
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should return null when the queue isn't found" do
|
42
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my-account", :access_key => "key"})
|
43
|
-
WAZ::Queues::Service.any_instance.expects(:get_queue_metadata).with("queue1").raises(RestClient::ResourceNotFound)
|
44
|
-
queue = WAZ::Queues::Queue.find('queue1')
|
45
|
-
queue.nil?.should == true
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should delete queue" do
|
49
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my-account", :access_key => "key"})
|
50
|
-
WAZ::Queues::Service.any_instance.expects(:get_queue_metadata).with("queue1").returns({})
|
51
|
-
WAZ::Queues::Service.any_instance.expects(:delete_queue).with("queue1").returns()
|
52
|
-
queue = WAZ::Queues::Queue.find('queue1')
|
53
|
-
queue.destroy!
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should get queue metadata" do
|
57
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my-account", :access_key => "key"})
|
58
|
-
WAZ::Queues::Service.any_instance.expects(:get_queue_metadata).with("queue1").returns({:x_ms_meta_property => "value"}).twice
|
59
|
-
queue = WAZ::Queues::Queue.find('queue1')
|
60
|
-
queue.metadata[:x_ms_meta_property].should == "value"
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should get queue length" do
|
64
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my-account", :access_key => "key"})
|
65
|
-
WAZ::Queues::Service.any_instance.expects(:get_queue_metadata).with("queue1").returns({:x_ms_approximate_messages_count => "2"}).twice
|
66
|
-
queue = WAZ::Queues::Queue.find('queue1')
|
67
|
-
queue.size.should == 2
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should merge queue metadata new metadata" do
|
71
|
-
existing_metadata = {:x_ms_approximate_message_count => 2, :x_ms_request_id => 2, :x_ms_meta_property1 => "value1"}
|
72
|
-
valid_metadata = {:x_ms_meta_property1 => "value1"}
|
73
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my-account", :access_key => "key"})
|
74
|
-
WAZ::Queues::Service.any_instance.expects(:get_queue_metadata).with("queue1").returns(existing_metadata).twice
|
75
|
-
WAZ::Queues::Service.any_instance.expects(:set_queue_metadata).with(valid_metadata.merge(:x_ms_meta_property2 => "value2"))
|
76
|
-
queue = WAZ::Queues::Queue.find('queue1')
|
77
|
-
queue.put_properties!({:x_ms_meta_property2 => "value2"})
|
78
|
-
end
|
79
|
-
|
80
|
-
it "should override queue metadata new metadata" do
|
81
|
-
existing_metadata = {:x_ms_approximate_message_count => 2, :x_ms_request_id => 2, :x_ms_meta_property1 => "value1"}
|
82
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my-account", :access_key => "key"})
|
83
|
-
WAZ::Queues::Service.any_instance.expects(:get_queue_metadata).with("queue1").returns(existing_metadata)
|
84
|
-
WAZ::Queues::Service.any_instance.expects(:set_queue_metadata).with({:x_ms_meta_property2 => "value2"})
|
85
|
-
queue = WAZ::Queues::Queue.find('queue1')
|
86
|
-
queue.put_properties!({:x_ms_meta_property2 => "value2"}, true)
|
87
|
-
end
|
88
|
-
|
89
|
-
it "should enqueue message on the queue" do
|
90
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my-account", :access_key => "key"})
|
91
|
-
WAZ::Queues::Service.any_instance.expects(:get_queue_metadata).with("queue1").returns({}).once
|
92
|
-
WAZ::Queues::Service.any_instance.expects(:enqueue).with("queue1", "this is my message enqueued", 604800)
|
93
|
-
queue = WAZ::Queues::Queue.find('queue1')
|
94
|
-
queue.enqueue!("this is my message enqueued")
|
95
|
-
end
|
96
|
-
|
97
|
-
it "should enqueue message on the queue with specific time to live" do
|
98
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my-account", :access_key => "key"})
|
99
|
-
WAZ::Queues::Service.any_instance.expects(:get_queue_metadata).with("queue1").returns({}).once
|
100
|
-
WAZ::Queues::Service.any_instance.expects(:enqueue).with("queue1", "this is my message enqueued", 600)
|
101
|
-
queue = WAZ::Queues::Queue.find('queue1')
|
102
|
-
queue.enqueue!("this is my message enqueued", 600)
|
103
|
-
end
|
104
|
-
|
105
|
-
it "should peek lock a single message from the queue" do
|
106
|
-
expected_message = {:message_id => "message id", :message_text => "text", :expiration_time => Time.new, :insertion_time => Time.new, :pop_receipt => "receipt"}
|
107
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my-account", :access_key => "key"})
|
108
|
-
WAZ::Queues::Service.any_instance.expects(:get_queue_metadata).with("queue1").returns({}).once
|
109
|
-
WAZ::Queues::Service.any_instance.expects(:get_messages).with('queue1', {:num_of_messages => 1}).returns([expected_message])
|
110
|
-
queue = WAZ::Queues::Queue.find('queue1')
|
111
|
-
message = queue.lock()
|
112
|
-
message.queue_name == "queue1"
|
113
|
-
message.message_id.should == "message id"
|
114
|
-
message.message_text.should == "text"
|
115
|
-
message.pop_receipt.should == "receipt"
|
116
|
-
end
|
117
|
-
|
118
|
-
it "should peek lock messages from the queue" do
|
119
|
-
expected_messages = [ {:message_id => "message id", :message_text => "text", :expiration_time => Time.new, :insertion_time => Time.new, :pop_receipt => "receipt"},
|
120
|
-
{:message_id => "message id2", :message_text => "text-second", :expiration_time => Time.new, :insertion_time => Time.new, :pop_receipt => "receipt"}]
|
121
|
-
|
122
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my-account", :access_key => "key"})
|
123
|
-
WAZ::Queues::Service.any_instance.expects(:get_queue_metadata).with("queue1").returns({}).once
|
124
|
-
WAZ::Queues::Service.any_instance.expects(:get_messages).with('queue1', {:num_of_messages => 2}).returns(expected_messages)
|
125
|
-
queue = WAZ::Queues::Queue.find('queue1')
|
126
|
-
messages = queue.lock(2)
|
127
|
-
messages.last().queue_name == "queue1"
|
128
|
-
messages.last().message_id.should == "message id2"
|
129
|
-
messages.last().message_text.should == "text-second"
|
130
|
-
messages.last().pop_receipt.should == "receipt"
|
131
|
-
end
|
132
|
-
|
133
|
-
it "should peek a single message from the queue" do
|
134
|
-
expected_message = {:message_id => "message id", :message_text => "text", :expiration_time => Time.new, :insertion_time => Time.new, :pop_receipt => "receipt"}
|
135
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my-account", :access_key => "key"})
|
136
|
-
WAZ::Queues::Service.any_instance.expects(:get_queue_metadata).with("queue1").returns({}).once
|
137
|
-
WAZ::Queues::Service.any_instance.expects(:peek).with('queue1', {:num_of_messages => 1}).returns([expected_message])
|
138
|
-
queue = WAZ::Queues::Queue.find('queue1')
|
139
|
-
message = queue.peek()
|
140
|
-
message.queue_name == "queue1"
|
141
|
-
message.message_id.should == "message id"
|
142
|
-
message.message_text.should == "text"
|
143
|
-
message.pop_receipt.should == "receipt"
|
144
|
-
end
|
145
|
-
|
146
|
-
it "should peek messages from the queue" do
|
147
|
-
expected_messages = [{:message_id => "message id", :message_text => "text", :expiration_time => Time.new, :insertion_time => Time.new, :pop_receipt => "receipt"},
|
148
|
-
{:message_id => "message id2", :message_text => "text-second", :expiration_time => Time.new, :insertion_time => Time.new, :pop_receipt => "receipt"}]
|
149
|
-
|
150
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my-account", :access_key => "key"})
|
151
|
-
WAZ::Queues::Service.any_instance.expects(:get_queue_metadata).with("queue1").returns({}).once
|
152
|
-
WAZ::Queues::Service.any_instance.expects(:peek).with('queue1', {:num_of_messages => 2}).returns(expected_messages)
|
153
|
-
queue = WAZ::Queues::Queue.find('queue1')
|
154
|
-
messages = queue.peek(2)
|
155
|
-
messages.last().queue_name == "queue1"
|
156
|
-
messages.last().message_id.should == "message id2"
|
157
|
-
messages.last().message_text.should == "text-second"
|
158
|
-
messages.last().pop_receipt.should == "receipt"
|
159
|
-
end
|
160
|
-
|
161
|
-
it "should clear queue" do
|
162
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my-account", :access_key => "key"})
|
163
|
-
WAZ::Queues::Service.any_instance.expects(:get_queue_metadata).with("queue1").returns({}).once
|
164
|
-
WAZ::Queues::Service.any_instance.expects(:clear_queue).with('queue1').returns()
|
165
|
-
queue = WAZ::Queues::Queue.find('queue1')
|
166
|
-
queue.clear()
|
167
|
-
end
|
168
|
-
|
169
|
-
it "should list queues including metadata when requested" do
|
170
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my-account", :access_key => "key"})
|
171
|
-
WAZ::Queues::Service.any_instance.expects(:list_queues).with({:include => 'metadata'}).returns({}).once
|
172
|
-
queue = WAZ::Queues::Queue.list(true)
|
173
|
-
end
|
174
|
-
|
175
|
-
it "should raise an exception when queue name starts with - (hypen)" do
|
176
|
-
lambda { WAZ::Queues::Queue.create('-queue') }.should raise_error(WAZ::Storage::InvalidParameterValue)
|
177
|
-
end
|
178
|
-
|
179
|
-
it "should raise an exception when queue name ends with - (hypen)" do
|
180
|
-
lambda { WAZ::Queues::Queue.create('queue-') }.should raise_error(WAZ::Storage::InvalidParameterValue)
|
181
|
-
end
|
182
|
-
|
183
|
-
it "should raise an exception when queue name is less than 3" do
|
184
|
-
lambda { WAZ::Queues::Queue.create('q') }.should raise_error(WAZ::Storage::InvalidParameterValue)
|
185
|
-
end
|
186
|
-
|
187
|
-
it "should raise an exception when queue name is longer than 63" do
|
188
|
-
lambda { WAZ::Queues::Queue.create('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa') }.should raise_error(WAZ::Storage::InvalidParameterValue)
|
189
|
-
end
|
190
|
-
|
191
|
-
it "should create the queue if it doesn't exists when calling ensure" do
|
192
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my-account", :access_key => "key"})
|
193
|
-
WAZ::Queues::Queue.expects(:create).with("queue1")
|
194
|
-
WAZ::Queues::Queue.expects(:find).with("queue1").returns(nil)
|
195
|
-
|
196
|
-
queue = WAZ::Queues::Queue.ensure("queue1")
|
197
|
-
end
|
198
|
-
|
199
|
-
it "should retrieve the queue if it already exists when calling ensure" do
|
200
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my-account", :access_key => "key"})
|
201
|
-
WAZ::Queues::Queue.expects(:create).with("queue1").never
|
202
|
-
WAZ::Queues::Queue.expects(:find).with("queue1").returns(mock())
|
203
|
-
|
204
|
-
queue = WAZ::Queues::Queue.ensure("queue1")
|
205
|
-
end
|
1
|
+
# enabling the load of files from root (on RSpec)
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../')
|
3
|
+
require 'spec/configuration'
|
4
|
+
require 'lib/waz-queues'
|
5
|
+
|
6
|
+
describe "Queue object behavior" do
|
7
|
+
it "should list queues by name" do
|
8
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my-account", :access_key => "key"})
|
9
|
+
WAZ::Queues::Service.any_instance.expects(:list_queues).returns([{:name => 'queue1', :url => 'queue1_url'}, {:name => 'queue2', :url => 'queue2_url'}])
|
10
|
+
containers = WAZ::Queues::Queue.list
|
11
|
+
containers.size.should == 2
|
12
|
+
containers.first().name.should == "queue1"
|
13
|
+
containers.first().url.should == "queue1_url"
|
14
|
+
containers.last().name.should == "queue2"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should throw when not name provided for the queue" do
|
18
|
+
lambda { WAZ::Queues::Queue.new({:foo => "bar"}) }.should raise_error(WAZ::Storage::InvalidOption)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should throw when not url provided for the queue" do
|
22
|
+
lambda { WAZ::Queues::Queue.new({:name => "mock-queue"}) }.should raise_error(WAZ::Storage::InvalidOption)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should create queue" do
|
26
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my-account", :access_key => "key"})
|
27
|
+
WAZ::Queues::Service.any_instance.expects(:create_queue)
|
28
|
+
queue = WAZ::Queues::Queue.create('queue1')
|
29
|
+
queue.name.should == "queue1"
|
30
|
+
queue.url.should == "http://my-account.queue.core.windows.net/queue1"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should find queue" do
|
34
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my-account", :access_key => "key"})
|
35
|
+
WAZ::Queues::Service.any_instance.expects(:get_queue_metadata).returns { }
|
36
|
+
queue = WAZ::Queues::Queue.find('queue1')
|
37
|
+
queue.name.should == "queue1"
|
38
|
+
queue.url.should == "http://my-account.queue.core.windows.net/queue1"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should return null when the queue isn't found" do
|
42
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my-account", :access_key => "key"})
|
43
|
+
WAZ::Queues::Service.any_instance.expects(:get_queue_metadata).with("queue1").raises(RestClient::ResourceNotFound)
|
44
|
+
queue = WAZ::Queues::Queue.find('queue1')
|
45
|
+
queue.nil?.should == true
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should delete queue" do
|
49
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my-account", :access_key => "key"})
|
50
|
+
WAZ::Queues::Service.any_instance.expects(:get_queue_metadata).with("queue1").returns({})
|
51
|
+
WAZ::Queues::Service.any_instance.expects(:delete_queue).with("queue1").returns()
|
52
|
+
queue = WAZ::Queues::Queue.find('queue1')
|
53
|
+
queue.destroy!
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should get queue metadata" do
|
57
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my-account", :access_key => "key"})
|
58
|
+
WAZ::Queues::Service.any_instance.expects(:get_queue_metadata).with("queue1").returns({:x_ms_meta_property => "value"}).twice
|
59
|
+
queue = WAZ::Queues::Queue.find('queue1')
|
60
|
+
queue.metadata[:x_ms_meta_property].should == "value"
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should get queue length" do
|
64
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my-account", :access_key => "key"})
|
65
|
+
WAZ::Queues::Service.any_instance.expects(:get_queue_metadata).with("queue1").returns({:x_ms_approximate_messages_count => "2"}).twice
|
66
|
+
queue = WAZ::Queues::Queue.find('queue1')
|
67
|
+
queue.size.should == 2
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should merge queue metadata new metadata" do
|
71
|
+
existing_metadata = {:x_ms_approximate_message_count => 2, :x_ms_request_id => 2, :x_ms_meta_property1 => "value1"}
|
72
|
+
valid_metadata = {:x_ms_meta_property1 => "value1"}
|
73
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my-account", :access_key => "key"})
|
74
|
+
WAZ::Queues::Service.any_instance.expects(:get_queue_metadata).with("queue1").returns(existing_metadata).twice
|
75
|
+
WAZ::Queues::Service.any_instance.expects(:set_queue_metadata).with(valid_metadata.merge(:x_ms_meta_property2 => "value2"))
|
76
|
+
queue = WAZ::Queues::Queue.find('queue1')
|
77
|
+
queue.put_properties!({:x_ms_meta_property2 => "value2"})
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should override queue metadata new metadata" do
|
81
|
+
existing_metadata = {:x_ms_approximate_message_count => 2, :x_ms_request_id => 2, :x_ms_meta_property1 => "value1"}
|
82
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my-account", :access_key => "key"})
|
83
|
+
WAZ::Queues::Service.any_instance.expects(:get_queue_metadata).with("queue1").returns(existing_metadata)
|
84
|
+
WAZ::Queues::Service.any_instance.expects(:set_queue_metadata).with({:x_ms_meta_property2 => "value2"})
|
85
|
+
queue = WAZ::Queues::Queue.find('queue1')
|
86
|
+
queue.put_properties!({:x_ms_meta_property2 => "value2"}, true)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should enqueue message on the queue" do
|
90
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my-account", :access_key => "key"})
|
91
|
+
WAZ::Queues::Service.any_instance.expects(:get_queue_metadata).with("queue1").returns({}).once
|
92
|
+
WAZ::Queues::Service.any_instance.expects(:enqueue).with("queue1", "this is my message enqueued", 604800)
|
93
|
+
queue = WAZ::Queues::Queue.find('queue1')
|
94
|
+
queue.enqueue!("this is my message enqueued")
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should enqueue message on the queue with specific time to live" do
|
98
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my-account", :access_key => "key"})
|
99
|
+
WAZ::Queues::Service.any_instance.expects(:get_queue_metadata).with("queue1").returns({}).once
|
100
|
+
WAZ::Queues::Service.any_instance.expects(:enqueue).with("queue1", "this is my message enqueued", 600)
|
101
|
+
queue = WAZ::Queues::Queue.find('queue1')
|
102
|
+
queue.enqueue!("this is my message enqueued", 600)
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should peek lock a single message from the queue" do
|
106
|
+
expected_message = {:message_id => "message id", :message_text => "text", :expiration_time => Time.new, :insertion_time => Time.new, :pop_receipt => "receipt"}
|
107
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my-account", :access_key => "key"})
|
108
|
+
WAZ::Queues::Service.any_instance.expects(:get_queue_metadata).with("queue1").returns({}).once
|
109
|
+
WAZ::Queues::Service.any_instance.expects(:get_messages).with('queue1', {:num_of_messages => 1}).returns([expected_message])
|
110
|
+
queue = WAZ::Queues::Queue.find('queue1')
|
111
|
+
message = queue.lock()
|
112
|
+
message.queue_name == "queue1"
|
113
|
+
message.message_id.should == "message id"
|
114
|
+
message.message_text.should == "text"
|
115
|
+
message.pop_receipt.should == "receipt"
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should peek lock messages from the queue" do
|
119
|
+
expected_messages = [ {:message_id => "message id", :message_text => "text", :expiration_time => Time.new, :insertion_time => Time.new, :pop_receipt => "receipt"},
|
120
|
+
{:message_id => "message id2", :message_text => "text-second", :expiration_time => Time.new, :insertion_time => Time.new, :pop_receipt => "receipt"}]
|
121
|
+
|
122
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my-account", :access_key => "key"})
|
123
|
+
WAZ::Queues::Service.any_instance.expects(:get_queue_metadata).with("queue1").returns({}).once
|
124
|
+
WAZ::Queues::Service.any_instance.expects(:get_messages).with('queue1', {:num_of_messages => 2}).returns(expected_messages)
|
125
|
+
queue = WAZ::Queues::Queue.find('queue1')
|
126
|
+
messages = queue.lock(2)
|
127
|
+
messages.last().queue_name == "queue1"
|
128
|
+
messages.last().message_id.should == "message id2"
|
129
|
+
messages.last().message_text.should == "text-second"
|
130
|
+
messages.last().pop_receipt.should == "receipt"
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should peek a single message from the queue" do
|
134
|
+
expected_message = {:message_id => "message id", :message_text => "text", :expiration_time => Time.new, :insertion_time => Time.new, :pop_receipt => "receipt"}
|
135
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my-account", :access_key => "key"})
|
136
|
+
WAZ::Queues::Service.any_instance.expects(:get_queue_metadata).with("queue1").returns({}).once
|
137
|
+
WAZ::Queues::Service.any_instance.expects(:peek).with('queue1', {:num_of_messages => 1}).returns([expected_message])
|
138
|
+
queue = WAZ::Queues::Queue.find('queue1')
|
139
|
+
message = queue.peek()
|
140
|
+
message.queue_name == "queue1"
|
141
|
+
message.message_id.should == "message id"
|
142
|
+
message.message_text.should == "text"
|
143
|
+
message.pop_receipt.should == "receipt"
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should peek messages from the queue" do
|
147
|
+
expected_messages = [{:message_id => "message id", :message_text => "text", :expiration_time => Time.new, :insertion_time => Time.new, :pop_receipt => "receipt"},
|
148
|
+
{:message_id => "message id2", :message_text => "text-second", :expiration_time => Time.new, :insertion_time => Time.new, :pop_receipt => "receipt"}]
|
149
|
+
|
150
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my-account", :access_key => "key"})
|
151
|
+
WAZ::Queues::Service.any_instance.expects(:get_queue_metadata).with("queue1").returns({}).once
|
152
|
+
WAZ::Queues::Service.any_instance.expects(:peek).with('queue1', {:num_of_messages => 2}).returns(expected_messages)
|
153
|
+
queue = WAZ::Queues::Queue.find('queue1')
|
154
|
+
messages = queue.peek(2)
|
155
|
+
messages.last().queue_name == "queue1"
|
156
|
+
messages.last().message_id.should == "message id2"
|
157
|
+
messages.last().message_text.should == "text-second"
|
158
|
+
messages.last().pop_receipt.should == "receipt"
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should clear queue" do
|
162
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my-account", :access_key => "key"})
|
163
|
+
WAZ::Queues::Service.any_instance.expects(:get_queue_metadata).with("queue1").returns({}).once
|
164
|
+
WAZ::Queues::Service.any_instance.expects(:clear_queue).with('queue1').returns()
|
165
|
+
queue = WAZ::Queues::Queue.find('queue1')
|
166
|
+
queue.clear()
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should list queues including metadata when requested" do
|
170
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my-account", :access_key => "key"})
|
171
|
+
WAZ::Queues::Service.any_instance.expects(:list_queues).with({:include => 'metadata'}).returns({}).once
|
172
|
+
queue = WAZ::Queues::Queue.list(true)
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should raise an exception when queue name starts with - (hypen)" do
|
176
|
+
lambda { WAZ::Queues::Queue.create('-queue') }.should raise_error(WAZ::Storage::InvalidParameterValue)
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should raise an exception when queue name ends with - (hypen)" do
|
180
|
+
lambda { WAZ::Queues::Queue.create('queue-') }.should raise_error(WAZ::Storage::InvalidParameterValue)
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should raise an exception when queue name is less than 3" do
|
184
|
+
lambda { WAZ::Queues::Queue.create('q') }.should raise_error(WAZ::Storage::InvalidParameterValue)
|
185
|
+
end
|
186
|
+
|
187
|
+
it "should raise an exception when queue name is longer than 63" do
|
188
|
+
lambda { WAZ::Queues::Queue.create('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa') }.should raise_error(WAZ::Storage::InvalidParameterValue)
|
189
|
+
end
|
190
|
+
|
191
|
+
it "should create the queue if it doesn't exists when calling ensure" do
|
192
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my-account", :access_key => "key"})
|
193
|
+
WAZ::Queues::Queue.expects(:create).with("queue1")
|
194
|
+
WAZ::Queues::Queue.expects(:find).with("queue1").returns(nil)
|
195
|
+
|
196
|
+
queue = WAZ::Queues::Queue.ensure("queue1")
|
197
|
+
end
|
198
|
+
|
199
|
+
it "should retrieve the queue if it already exists when calling ensure" do
|
200
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my-account", :access_key => "key"})
|
201
|
+
WAZ::Queues::Queue.expects(:create).with("queue1").never
|
202
|
+
WAZ::Queues::Queue.expects(:find).with("queue1").returns(mock())
|
203
|
+
|
204
|
+
queue = WAZ::Queues::Queue.ensure("queue1")
|
205
|
+
end
|
206
206
|
end
|