waz-storage 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/.gitignore +9 -9
  2. data/CHANGELOG.rdoc +72 -72
  3. data/Gemfile +4 -4
  4. data/Gemfile.lock +46 -46
  5. data/LICENSE +18 -18
  6. data/README.rdoc +310 -310
  7. data/lib/waz-blobs.rb +4 -4
  8. data/lib/waz-queues.rb +6 -6
  9. data/lib/waz-storage.rb +39 -39
  10. data/lib/waz-tables.rb +4 -4
  11. data/lib/waz/blobs/blob_object.rb +122 -122
  12. data/lib/waz/blobs/container.rb +172 -172
  13. data/lib/waz/blobs/exceptions.rb +10 -10
  14. data/lib/waz/blobs/service.rb +181 -181
  15. data/lib/waz/queues/exceptions.rb +28 -28
  16. data/lib/waz/queues/message.rb +64 -64
  17. data/lib/waz/queues/queue.rb +164 -164
  18. data/lib/waz/queues/service.rb +105 -105
  19. data/lib/waz/storage/base.rb +70 -70
  20. data/lib/waz/storage/core_service.rb +2 -1
  21. data/lib/waz/storage/exceptions.rb +33 -33
  22. data/lib/waz/storage/validation_rules.rb +25 -25
  23. data/lib/waz/tables/edm_type_helper.rb +44 -44
  24. data/lib/waz/tables/exceptions.rb +44 -44
  25. data/lib/waz/tables/service.rb +178 -178
  26. data/lib/waz/tables/table.rb +74 -74
  27. data/lib/waz/tables/table_array.rb +10 -10
  28. data/rakefile +7 -7
  29. data/spec/configuration.rb +22 -22
  30. data/spec/waz/blobs/blob_object_spec.rb +80 -80
  31. data/spec/waz/blobs/container_spec.rb +175 -175
  32. data/spec/waz/blobs/service_spec.rb +336 -336
  33. data/spec/waz/queues/message_spec.rb +32 -32
  34. data/spec/waz/queues/queue_spec.rb +205 -205
  35. data/spec/waz/queues/service_spec.rb +298 -298
  36. data/spec/waz/storage/base_tests.rb +81 -81
  37. data/spec/waz/storage/shared_key_core_service_spec.rb +141 -141
  38. data/spec/waz/tables/service_spec.rb +613 -613
  39. data/spec/waz/tables/table_spec.rb +97 -97
  40. data/waz-storage.gemspec +29 -29
  41. metadata +3 -3
@@ -1,299 +1,299 @@
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 "Windows Azure Queues API service" do
7
- it "should list queues" do
8
- # setup mocks
9
- expected_url = "http://my_account.queue.core.windows.net/?comp=list"
10
- expected_response = <<-eos
11
- <?xml version="1.0" encoding="utf-8"?>
12
- <EnumerationResults AccountName="http://myaccount.queue.core.windows.net">
13
- <Queues>
14
- <Queue>
15
- <Name>mock-queue</Name>
16
- <Url>http://myaccount.queue.core.windows.net/mock-queue</Url>
17
- </Queue>
18
- </Queues>
19
- </EnumerationResults>
20
- eos
21
-
22
- mock_request = RestClient::Request.new(:method => :get, :url => expected_url)
23
- mock_request.expects(:execute).returns(expected_response)
24
-
25
- service = WAZ::Queues::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
26
- # setup mocha expectations
27
- service.expects(:generate_request_uri).with(nil, :comp => 'list').returns(expected_url)
28
- service.expects(:generate_request).with(:get, expected_url, {:x_ms_version => '2009-09-19'}, nil).returns(mock_request)
29
-
30
- queues = service.list_queues()
31
- queues.first()[:name].should == "mock-queue"
32
- queues.first()[:url].should == "http://myaccount.queue.core.windows.net/mock-queue"
33
- end
34
-
35
- it "should create queue" do
36
- expected_url = "http://myaccount.queue.core.windows.net/mock-queue"
37
- mock_request = RestClient::Request.new(:method => :get, :url => expected_url)
38
- mock_request.stubs(:execute)
39
-
40
- service = WAZ::Queues::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
41
- # setup mocha expectations
42
- service.expects(:generate_request_uri).with("mock-queue", nil).returns(expected_url)
43
- service.expects(:generate_request).with(:put, expected_url, {:x_ms_meta_priority => "high-importance", :x_ms_version => '2009-09-19'}, nil).returns(mock_request)
44
-
45
- service.create_queue("mock-queue", {:x_ms_meta_priority => "high-importance"})
46
- end
47
-
48
- it "should delete queue" do
49
- expected_url = "http://myaccount.queue.core.windows.net/mock-queue"
50
- mock_response = mock()
51
- mock_request = RestClient::Request.new(:method => :get, :url => expected_url)
52
- mock_request.stubs(:execute).returns(mock_response)
53
-
54
- service = WAZ::Queues::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
55
- # setup mocha expectations
56
- service.expects(:generate_request_uri).with("mock-queue", {}).returns(expected_url)
57
- service.expects(:generate_request).with(:delete, expected_url, {:x_ms_version => '2009-09-19'}, nil).returns(mock_request)
58
- service.delete_queue('mock-queue')
59
- end
60
-
61
- it "should get queue metadata" do
62
- expected_url = "http://myaccount.queue.core.windows.net/mock-queue?comp=metadata"
63
- mock_response = mock()
64
- mock_response.stubs(:headers).returns({ :x_ms_request_id => "fake-id" })
65
- mock_request = RestClient::Request.new(:method => :head, :url => expected_url)
66
- mock_request.stubs(:execute).returns(mock_response)
67
-
68
- service = WAZ::Queues::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
69
- # setup mocha expectations
70
- service.expects(:generate_request_uri).with("mock-queue", {:comp => 'metadata'}).returns(expected_url)
71
- service.expects(:generate_request).with(:head, expected_url, {:x_ms_version => '2009-09-19'}, nil).returns(mock_request)
72
- service.get_queue_metadata('mock-queue').should == mock_response.headers
73
- end
74
-
75
- it "should set queue metadata" do
76
- expected_url = "http://myaccount.queue.core.windows.net/mock-queue"
77
- mock_request = RestClient::Request.new(:method => :get, :url => expected_url)
78
- mock_request.stubs(:execute)
79
-
80
- service = WAZ::Queues::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
81
- # setup mocha expectations
82
- service.expects(:generate_request_uri).with("mock-queue", :comp => 'metadata').returns(expected_url)
83
- service.expects(:generate_request).with(:put, expected_url, {:x_ms_version => '2009-09-19', :x_ms_meta_priority => "high-importance"}, nil).returns(mock_request)
84
-
85
- service.set_queue_metadata("mock-queue", {:x_ms_meta_priority => "high-importance"})
86
- end
87
-
88
- it "should enqueue message" do
89
- expected_url = "http://myaccount.queue.core.windows.net/mock-queue/messages?messagettl=604800"
90
- mock_request = RestClient::Request.new(:method => :post, :url => expected_url)
91
- mock_request.stubs(:execute)
92
-
93
- service = WAZ::Queues::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
94
- # setup mocha expectations
95
- payload = "<?xml version=\"1.0\" encoding=\"utf-8\"?><QueueMessage><MessageText>this is the message payload</MessageText></QueueMessage>"
96
- service.expects(:generate_request_uri).with("mock-queue/messages", { :messagettl => 604800 }).returns(expected_url)
97
- service.expects(:generate_request).with(:post, expected_url, { 'Content-Type' => "application/xml", :x_ms_version => '2009-09-19'}, payload).returns(mock_request)
98
-
99
- service.enqueue("mock-queue", "this is the message payload")
100
- end
101
-
102
- it "should get messages from queue" do
103
- expected_url = "http://myaccount.queue.core.windows.net/mock-queue/messages"
104
- expected_response = <<-eos
105
- <?xml version="1.0" encoding="utf-8"?>
106
- <QueueMessagesList>
107
- <QueueMessage>
108
- <MessageId>message_id</MessageId>
109
- <InsertionTime>Mon, 22 Sep 2008 23:29:20 GMT</InsertionTime>
110
- <ExpirationTime>Mon, 29 Sep 2008 23:29:20 GMT</ExpirationTime>
111
- <PopReceipt>receipt</PopReceipt>
112
- <TimeNextVisible>Tue, 23 Sep 2008 05:29:20 GMT</TimeNextVisible>
113
- <MessageText>text</MessageText>
114
- </QueueMessage>
115
- </QueueMessagesList>
116
- eos
117
-
118
- mock_request = RestClient::Request.new(:method => :get, :url => expected_url)
119
- mock_request.stubs(:execute).returns(expected_response)
120
- service = WAZ::Queues::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
121
-
122
- # setup mocha expectations
123
- service.expects(:generate_request_uri).with("mock-queue/messages", {}).returns(expected_url)
124
- service.expects(:generate_request).with(:get, expected_url, {:x_ms_version => "2009-09-19"}, nil).returns(mock_request)
125
-
126
- messages = service.get_messages("mock-queue")
127
- messages.first()[:message_id].should == "message_id"
128
- messages.first()[:pop_receipt].should == "receipt"
129
- messages.first()[:message_text].should == "text"
130
- messages.first()[:insertion_time].nil?.should == false
131
- messages.first()[:expiration_time].nil?.should == false
132
- messages.first()[:time_next_visible].nil?.should == false
133
- end
134
-
135
- it "should get messages from queue specifiying additional parameters" do
136
- expected_url = "http://myaccount.queue.core.windows.net/mock-queue/messages"
137
- expected_response = <<-eos
138
- <?xml version="1.0" encoding="utf-8"?>
139
- <QueueMessagesList>
140
- <QueueMessage>
141
- <MessageId>message_id</MessageId>
142
- <InsertionTime>Mon, 22 Sep 2008 23:29:20 GMT</InsertionTime>
143
- <ExpirationTime>Mon, 29 Sep 2008 23:29:20 GMT</ExpirationTime>
144
- <PopReceipt>receipt</PopReceipt>
145
- <TimeNextVisible>Tue, 23 Sep 2008 05:29:20 GMT</TimeNextVisible>
146
- <MessageText>text</MessageText>
147
- </QueueMessage>
148
- </QueueMessagesList>
149
- eos
150
-
151
- mock_request = RestClient::Request.new(:method => :get, :url => expected_url)
152
- mock_request.stubs(:execute).returns(expected_response)
153
- service = WAZ::Queues::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
154
-
155
- # setup mocha expectations
156
- service.expects(:generate_request_uri).with("mock-queue/messages", {:num_of_messages => 2, :visibility_timeout => 3}).returns(expected_url)
157
- service.expects(:generate_request).with(:get, expected_url, {:x_ms_version => "2009-09-19"}, nil).returns(mock_request)
158
-
159
- messages = service.get_messages("mock-queue", :num_of_messages => 2, :visibility_timeout => 3)
160
- messages.first()[:message_id].should == "message_id"
161
- messages.first()[:pop_receipt].should == "receipt"
162
- messages.first()[:message_text].should == "text"
163
- messages.first()[:insertion_time].nil?.should == false
164
- messages.first()[:expiration_time].nil?.should == false
165
- messages.first()[:time_next_visible].nil?.should == false
166
- end
167
-
168
- it "should raise exception when :num_of_messages is out of range (1 - 32)" do
169
- service = WAZ::Queues::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
170
- lambda{ service.get_messages("mock-queue", :num_of_messages => 0) }.should raise_error(WAZ::Queues::OptionOutOfRange)
171
- lambda{ service.get_messages("mock-queue", :num_of_messages => 33) }.should raise_error(WAZ::Queues::OptionOutOfRange)
172
- end
173
-
174
- it "should raise exception when :visibility_timeout is out of range (1 - 7200)" do
175
- service = WAZ::Queues::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
176
- lambda{ service.get_messages("mock-queue", :visibility_timeout => 0) }.should raise_error(WAZ::Queues::OptionOutOfRange)
177
- lambda{ service.get_messages("mock-queue", :visibility_timeout => 7201) }.should raise_error(WAZ::Queues::OptionOutOfRange)
178
- end
179
-
180
- it "should peek message from queue" do
181
- expected_url = "http://myaccount.queue.core.windows.net/mock-queue/messages"
182
- expected_response = <<-eos
183
- <?xml version="1.0" encoding="utf-8"?>
184
- <QueueMessagesList>
185
- <QueueMessage>
186
- <MessageId>message_id</MessageId>
187
- <InsertionTime>Mon, 22 Sep 2008 23:29:20 GMT</InsertionTime>
188
- <ExpirationTime>Mon, 29 Sep 2008 23:29:20 GMT</ExpirationTime>
189
- <MessageText>text</MessageText>
190
- <DequeueCount>5</DequeueCount>
191
- </QueueMessage>
192
- </QueueMessagesList>
193
- eos
194
-
195
- mock_request = RestClient::Request.new(:method => :get, :url => expected_url)
196
- mock_request.stubs(:execute).returns(expected_response)
197
- service = WAZ::Queues::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
198
-
199
- # setup mocha expectations
200
- service.expects(:generate_request_uri).with("mock-queue/messages", {:peek_only => true}).returns(expected_url)
201
- service.expects(:generate_request).with(:get, expected_url, {:x_ms_version => "2009-09-19"}, nil).returns(mock_request)
202
-
203
- messages = service.peek("mock-queue")
204
- messages.first()[:message_id].should == "message_id"
205
- messages.first()[:message_text].should == "text"
206
- messages.first()[:insertion_time].nil?.should == false
207
- messages.first()[:expiration_time].nil?.should == false
208
- messages.first()[:dequeue_count].should == 5
209
- end
210
-
211
- it "should peek messages from queue when :num_of_messages is specified" do
212
- expected_url = "http://myaccount.queue.core.windows.net/mock-queue/messages"
213
- expected_response = <<-eos
214
- <?xml version="1.0" encoding="utf-8"?>
215
- <QueueMessagesList>
216
- <QueueMessage>
217
- <MessageId>message_id</MessageId>
218
- <InsertionTime>Mon, 22 Sep 2008 23:29:20 GMT</InsertionTime>
219
- <ExpirationTime>Mon, 29 Sep 2008 23:29:20 GMT</ExpirationTime>
220
- <MessageText>text</MessageText>
221
- <DequeueCount>5</DequeueCount>
222
- </QueueMessage>
223
- </QueueMessagesList>
224
- eos
225
-
226
- mock_request = RestClient::Request.new(:method => :get, :url => expected_url)
227
- mock_request.stubs(:execute).returns(expected_response)
228
- service = WAZ::Queues::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
229
-
230
- # setup mocha expectations
231
- service.expects(:generate_request_uri).with("mock-queue/messages", {:peek_only => true, :num_of_messages => 32}).returns(expected_url)
232
- service.expects(:generate_request).with(:get, expected_url, {:x_ms_version => "2009-09-19"}, nil).returns(mock_request)
233
-
234
- messages = service.peek("mock-queue", {:num_of_messages => 32})
235
- messages.first()[:message_id].should == "message_id"
236
- messages.first()[:message_text].should == "text"
237
- messages.first()[:insertion_time].nil?.should == false
238
- messages.first()[:expiration_time].nil?.should == false
239
- messages.first()[:dequeue_count].should == 5
240
- end
241
-
242
- it "should delete message" do
243
- expected_url = "http://myaccount.queue.core.windows.net/mock-queue/messages/message_id?popreceipt=pop_receipt"
244
- mock_request = RestClient::Request.new(:method => :get, :url => expected_url)
245
- mock_request.stubs(:execute)
246
-
247
- service = WAZ::Queues::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
248
- # setup mocha expectations
249
- service.expects(:generate_request_uri).with("mock-queue/messages/message_id", { :pop_receipt => "pop_receipt" }).returns(expected_url)
250
- service.expects(:generate_request).with(:delete, expected_url, {}, nil).returns(mock_request)
251
-
252
- service.delete_message("mock-queue", "message_id", "pop_receipt")
253
- end
254
-
255
- it "should clear queue" do
256
- expected_url = "http://myaccount.queue.core.windows.net/mock-queue/messages"
257
- mock_request = RestClient::Request.new(:method => :get, :url => expected_url)
258
- mock_request.stubs(:execute)
259
-
260
- service = WAZ::Queues::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
261
- # setup mocha expectations
262
- service.expects(:generate_request_uri).with("mock-queue/messages", {}).returns(expected_url)
263
- service.expects(:generate_request).with(:delete, expected_url, {:x_ms_version => '2009-09-19'}, nil).returns(mock_request)
264
-
265
- service.clear_queue("mock-queue")
266
- end
267
-
268
- it "should list queues with metadata" do
269
- # setup mocks
270
- expected_url = "http://my_account.queue.core.windows.net/?comp=list&include=metadata"
271
- expected_response = <<-eos
272
- <?xml version="1.0" encoding="utf-8"?>
273
- <EnumerationResults AccountName="http://myaccount.queue.core.windows.net">
274
- <Queues>
275
- <Queue>
276
- <Name>mock-queue</Name>
277
- <Url>http://myaccount.queue.core.windows.net/mock-queue</Url>
278
- <Metadata>
279
- <x-ms-name>Custom Queue</x-ms-name>
280
- </Metadata>
281
- </Queue>
282
- </Queues>
283
- </EnumerationResults>
284
- eos
285
-
286
- mock_request = RestClient::Request.new(:method => :get, :url => expected_url)
287
- mock_request.expects(:execute).returns(expected_response)
288
-
289
- service = WAZ::Queues::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
290
- # setup mocha expectations
291
- service.expects(:generate_request_uri).with(nil, {:comp => 'list', :include => 'metadata'}).returns(expected_url)
292
- service.expects(:generate_request).with(:get, expected_url, {:x_ms_version => '2009-09-19'}, nil).returns(mock_request)
293
-
294
- queues = service.list_queues({:include => 'metadata'})
295
- queues.first()[:name].should == "mock-queue"
296
- queues.first()[:url].should == "http://myaccount.queue.core.windows.net/mock-queue"
297
- queues.first()[:metadata][:x_ms_name] = 'Custom Queue'
298
- 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 "Windows Azure Queues API service" do
7
+ it "should list queues" do
8
+ # setup mocks
9
+ expected_url = "http://my_account.queue.core.windows.net/?comp=list"
10
+ expected_response = <<-eos
11
+ <?xml version="1.0" encoding="utf-8"?>
12
+ <EnumerationResults AccountName="http://myaccount.queue.core.windows.net">
13
+ <Queues>
14
+ <Queue>
15
+ <Name>mock-queue</Name>
16
+ <Url>http://myaccount.queue.core.windows.net/mock-queue</Url>
17
+ </Queue>
18
+ </Queues>
19
+ </EnumerationResults>
20
+ eos
21
+
22
+ mock_request = RestClient::Request.new(:method => :get, :url => expected_url)
23
+ mock_request.expects(:execute).returns(expected_response)
24
+
25
+ service = WAZ::Queues::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
26
+ # setup mocha expectations
27
+ service.expects(:generate_request_uri).with(nil, :comp => 'list').returns(expected_url)
28
+ service.expects(:generate_request).with(:get, expected_url, {:x_ms_version => '2009-09-19'}, nil).returns(mock_request)
29
+
30
+ queues = service.list_queues()
31
+ queues.first()[:name].should == "mock-queue"
32
+ queues.first()[:url].should == "http://myaccount.queue.core.windows.net/mock-queue"
33
+ end
34
+
35
+ it "should create queue" do
36
+ expected_url = "http://myaccount.queue.core.windows.net/mock-queue"
37
+ mock_request = RestClient::Request.new(:method => :get, :url => expected_url)
38
+ mock_request.stubs(:execute)
39
+
40
+ service = WAZ::Queues::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
41
+ # setup mocha expectations
42
+ service.expects(:generate_request_uri).with("mock-queue", nil).returns(expected_url)
43
+ service.expects(:generate_request).with(:put, expected_url, {:x_ms_meta_priority => "high-importance", :x_ms_version => '2009-09-19'}, nil).returns(mock_request)
44
+
45
+ service.create_queue("mock-queue", {:x_ms_meta_priority => "high-importance"})
46
+ end
47
+
48
+ it "should delete queue" do
49
+ expected_url = "http://myaccount.queue.core.windows.net/mock-queue"
50
+ mock_response = mock()
51
+ mock_request = RestClient::Request.new(:method => :get, :url => expected_url)
52
+ mock_request.stubs(:execute).returns(mock_response)
53
+
54
+ service = WAZ::Queues::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
55
+ # setup mocha expectations
56
+ service.expects(:generate_request_uri).with("mock-queue", {}).returns(expected_url)
57
+ service.expects(:generate_request).with(:delete, expected_url, {:x_ms_version => '2009-09-19'}, nil).returns(mock_request)
58
+ service.delete_queue('mock-queue')
59
+ end
60
+
61
+ it "should get queue metadata" do
62
+ expected_url = "http://myaccount.queue.core.windows.net/mock-queue?comp=metadata"
63
+ mock_response = mock()
64
+ mock_response.stubs(:headers).returns({ :x_ms_request_id => "fake-id" })
65
+ mock_request = RestClient::Request.new(:method => :head, :url => expected_url)
66
+ mock_request.stubs(:execute).returns(mock_response)
67
+
68
+ service = WAZ::Queues::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
69
+ # setup mocha expectations
70
+ service.expects(:generate_request_uri).with("mock-queue", {:comp => 'metadata'}).returns(expected_url)
71
+ service.expects(:generate_request).with(:head, expected_url, {:x_ms_version => '2009-09-19'}, nil).returns(mock_request)
72
+ service.get_queue_metadata('mock-queue').should == mock_response.headers
73
+ end
74
+
75
+ it "should set queue metadata" do
76
+ expected_url = "http://myaccount.queue.core.windows.net/mock-queue"
77
+ mock_request = RestClient::Request.new(:method => :get, :url => expected_url)
78
+ mock_request.stubs(:execute)
79
+
80
+ service = WAZ::Queues::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
81
+ # setup mocha expectations
82
+ service.expects(:generate_request_uri).with("mock-queue", :comp => 'metadata').returns(expected_url)
83
+ service.expects(:generate_request).with(:put, expected_url, {:x_ms_version => '2009-09-19', :x_ms_meta_priority => "high-importance"}, nil).returns(mock_request)
84
+
85
+ service.set_queue_metadata("mock-queue", {:x_ms_meta_priority => "high-importance"})
86
+ end
87
+
88
+ it "should enqueue message" do
89
+ expected_url = "http://myaccount.queue.core.windows.net/mock-queue/messages?messagettl=604800"
90
+ mock_request = RestClient::Request.new(:method => :post, :url => expected_url)
91
+ mock_request.stubs(:execute)
92
+
93
+ service = WAZ::Queues::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
94
+ # setup mocha expectations
95
+ payload = "<?xml version=\"1.0\" encoding=\"utf-8\"?><QueueMessage><MessageText>this is the message payload</MessageText></QueueMessage>"
96
+ service.expects(:generate_request_uri).with("mock-queue/messages", { :messagettl => 604800 }).returns(expected_url)
97
+ service.expects(:generate_request).with(:post, expected_url, { 'Content-Type' => "application/xml", :x_ms_version => '2009-09-19'}, payload).returns(mock_request)
98
+
99
+ service.enqueue("mock-queue", "this is the message payload")
100
+ end
101
+
102
+ it "should get messages from queue" do
103
+ expected_url = "http://myaccount.queue.core.windows.net/mock-queue/messages"
104
+ expected_response = <<-eos
105
+ <?xml version="1.0" encoding="utf-8"?>
106
+ <QueueMessagesList>
107
+ <QueueMessage>
108
+ <MessageId>message_id</MessageId>
109
+ <InsertionTime>Mon, 22 Sep 2008 23:29:20 GMT</InsertionTime>
110
+ <ExpirationTime>Mon, 29 Sep 2008 23:29:20 GMT</ExpirationTime>
111
+ <PopReceipt>receipt</PopReceipt>
112
+ <TimeNextVisible>Tue, 23 Sep 2008 05:29:20 GMT</TimeNextVisible>
113
+ <MessageText>text</MessageText>
114
+ </QueueMessage>
115
+ </QueueMessagesList>
116
+ eos
117
+
118
+ mock_request = RestClient::Request.new(:method => :get, :url => expected_url)
119
+ mock_request.stubs(:execute).returns(expected_response)
120
+ service = WAZ::Queues::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
121
+
122
+ # setup mocha expectations
123
+ service.expects(:generate_request_uri).with("mock-queue/messages", {}).returns(expected_url)
124
+ service.expects(:generate_request).with(:get, expected_url, {:x_ms_version => "2009-09-19"}, nil).returns(mock_request)
125
+
126
+ messages = service.get_messages("mock-queue")
127
+ messages.first()[:message_id].should == "message_id"
128
+ messages.first()[:pop_receipt].should == "receipt"
129
+ messages.first()[:message_text].should == "text"
130
+ messages.first()[:insertion_time].nil?.should == false
131
+ messages.first()[:expiration_time].nil?.should == false
132
+ messages.first()[:time_next_visible].nil?.should == false
133
+ end
134
+
135
+ it "should get messages from queue specifiying additional parameters" do
136
+ expected_url = "http://myaccount.queue.core.windows.net/mock-queue/messages"
137
+ expected_response = <<-eos
138
+ <?xml version="1.0" encoding="utf-8"?>
139
+ <QueueMessagesList>
140
+ <QueueMessage>
141
+ <MessageId>message_id</MessageId>
142
+ <InsertionTime>Mon, 22 Sep 2008 23:29:20 GMT</InsertionTime>
143
+ <ExpirationTime>Mon, 29 Sep 2008 23:29:20 GMT</ExpirationTime>
144
+ <PopReceipt>receipt</PopReceipt>
145
+ <TimeNextVisible>Tue, 23 Sep 2008 05:29:20 GMT</TimeNextVisible>
146
+ <MessageText>text</MessageText>
147
+ </QueueMessage>
148
+ </QueueMessagesList>
149
+ eos
150
+
151
+ mock_request = RestClient::Request.new(:method => :get, :url => expected_url)
152
+ mock_request.stubs(:execute).returns(expected_response)
153
+ service = WAZ::Queues::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
154
+
155
+ # setup mocha expectations
156
+ service.expects(:generate_request_uri).with("mock-queue/messages", {:num_of_messages => 2, :visibility_timeout => 3}).returns(expected_url)
157
+ service.expects(:generate_request).with(:get, expected_url, {:x_ms_version => "2009-09-19"}, nil).returns(mock_request)
158
+
159
+ messages = service.get_messages("mock-queue", :num_of_messages => 2, :visibility_timeout => 3)
160
+ messages.first()[:message_id].should == "message_id"
161
+ messages.first()[:pop_receipt].should == "receipt"
162
+ messages.first()[:message_text].should == "text"
163
+ messages.first()[:insertion_time].nil?.should == false
164
+ messages.first()[:expiration_time].nil?.should == false
165
+ messages.first()[:time_next_visible].nil?.should == false
166
+ end
167
+
168
+ it "should raise exception when :num_of_messages is out of range (1 - 32)" do
169
+ service = WAZ::Queues::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
170
+ lambda{ service.get_messages("mock-queue", :num_of_messages => 0) }.should raise_error(WAZ::Queues::OptionOutOfRange)
171
+ lambda{ service.get_messages("mock-queue", :num_of_messages => 33) }.should raise_error(WAZ::Queues::OptionOutOfRange)
172
+ end
173
+
174
+ it "should raise exception when :visibility_timeout is out of range (1 - 7200)" do
175
+ service = WAZ::Queues::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
176
+ lambda{ service.get_messages("mock-queue", :visibility_timeout => 0) }.should raise_error(WAZ::Queues::OptionOutOfRange)
177
+ lambda{ service.get_messages("mock-queue", :visibility_timeout => 7201) }.should raise_error(WAZ::Queues::OptionOutOfRange)
178
+ end
179
+
180
+ it "should peek message from queue" do
181
+ expected_url = "http://myaccount.queue.core.windows.net/mock-queue/messages"
182
+ expected_response = <<-eos
183
+ <?xml version="1.0" encoding="utf-8"?>
184
+ <QueueMessagesList>
185
+ <QueueMessage>
186
+ <MessageId>message_id</MessageId>
187
+ <InsertionTime>Mon, 22 Sep 2008 23:29:20 GMT</InsertionTime>
188
+ <ExpirationTime>Mon, 29 Sep 2008 23:29:20 GMT</ExpirationTime>
189
+ <MessageText>text</MessageText>
190
+ <DequeueCount>5</DequeueCount>
191
+ </QueueMessage>
192
+ </QueueMessagesList>
193
+ eos
194
+
195
+ mock_request = RestClient::Request.new(:method => :get, :url => expected_url)
196
+ mock_request.stubs(:execute).returns(expected_response)
197
+ service = WAZ::Queues::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
198
+
199
+ # setup mocha expectations
200
+ service.expects(:generate_request_uri).with("mock-queue/messages", {:peek_only => true}).returns(expected_url)
201
+ service.expects(:generate_request).with(:get, expected_url, {:x_ms_version => "2009-09-19"}, nil).returns(mock_request)
202
+
203
+ messages = service.peek("mock-queue")
204
+ messages.first()[:message_id].should == "message_id"
205
+ messages.first()[:message_text].should == "text"
206
+ messages.first()[:insertion_time].nil?.should == false
207
+ messages.first()[:expiration_time].nil?.should == false
208
+ messages.first()[:dequeue_count].should == 5
209
+ end
210
+
211
+ it "should peek messages from queue when :num_of_messages is specified" do
212
+ expected_url = "http://myaccount.queue.core.windows.net/mock-queue/messages"
213
+ expected_response = <<-eos
214
+ <?xml version="1.0" encoding="utf-8"?>
215
+ <QueueMessagesList>
216
+ <QueueMessage>
217
+ <MessageId>message_id</MessageId>
218
+ <InsertionTime>Mon, 22 Sep 2008 23:29:20 GMT</InsertionTime>
219
+ <ExpirationTime>Mon, 29 Sep 2008 23:29:20 GMT</ExpirationTime>
220
+ <MessageText>text</MessageText>
221
+ <DequeueCount>5</DequeueCount>
222
+ </QueueMessage>
223
+ </QueueMessagesList>
224
+ eos
225
+
226
+ mock_request = RestClient::Request.new(:method => :get, :url => expected_url)
227
+ mock_request.stubs(:execute).returns(expected_response)
228
+ service = WAZ::Queues::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
229
+
230
+ # setup mocha expectations
231
+ service.expects(:generate_request_uri).with("mock-queue/messages", {:peek_only => true, :num_of_messages => 32}).returns(expected_url)
232
+ service.expects(:generate_request).with(:get, expected_url, {:x_ms_version => "2009-09-19"}, nil).returns(mock_request)
233
+
234
+ messages = service.peek("mock-queue", {:num_of_messages => 32})
235
+ messages.first()[:message_id].should == "message_id"
236
+ messages.first()[:message_text].should == "text"
237
+ messages.first()[:insertion_time].nil?.should == false
238
+ messages.first()[:expiration_time].nil?.should == false
239
+ messages.first()[:dequeue_count].should == 5
240
+ end
241
+
242
+ it "should delete message" do
243
+ expected_url = "http://myaccount.queue.core.windows.net/mock-queue/messages/message_id?popreceipt=pop_receipt"
244
+ mock_request = RestClient::Request.new(:method => :get, :url => expected_url)
245
+ mock_request.stubs(:execute)
246
+
247
+ service = WAZ::Queues::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
248
+ # setup mocha expectations
249
+ service.expects(:generate_request_uri).with("mock-queue/messages/message_id", { :pop_receipt => "pop_receipt" }).returns(expected_url)
250
+ service.expects(:generate_request).with(:delete, expected_url, {}, nil).returns(mock_request)
251
+
252
+ service.delete_message("mock-queue", "message_id", "pop_receipt")
253
+ end
254
+
255
+ it "should clear queue" do
256
+ expected_url = "http://myaccount.queue.core.windows.net/mock-queue/messages"
257
+ mock_request = RestClient::Request.new(:method => :get, :url => expected_url)
258
+ mock_request.stubs(:execute)
259
+
260
+ service = WAZ::Queues::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
261
+ # setup mocha expectations
262
+ service.expects(:generate_request_uri).with("mock-queue/messages", {}).returns(expected_url)
263
+ service.expects(:generate_request).with(:delete, expected_url, {:x_ms_version => '2009-09-19'}, nil).returns(mock_request)
264
+
265
+ service.clear_queue("mock-queue")
266
+ end
267
+
268
+ it "should list queues with metadata" do
269
+ # setup mocks
270
+ expected_url = "http://my_account.queue.core.windows.net/?comp=list&include=metadata"
271
+ expected_response = <<-eos
272
+ <?xml version="1.0" encoding="utf-8"?>
273
+ <EnumerationResults AccountName="http://myaccount.queue.core.windows.net">
274
+ <Queues>
275
+ <Queue>
276
+ <Name>mock-queue</Name>
277
+ <Url>http://myaccount.queue.core.windows.net/mock-queue</Url>
278
+ <Metadata>
279
+ <x-ms-name>Custom Queue</x-ms-name>
280
+ </Metadata>
281
+ </Queue>
282
+ </Queues>
283
+ </EnumerationResults>
284
+ eos
285
+
286
+ mock_request = RestClient::Request.new(:method => :get, :url => expected_url)
287
+ mock_request.expects(:execute).returns(expected_response)
288
+
289
+ service = WAZ::Queues::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
290
+ # setup mocha expectations
291
+ service.expects(:generate_request_uri).with(nil, {:comp => 'list', :include => 'metadata'}).returns(expected_url)
292
+ service.expects(:generate_request).with(:get, expected_url, {:x_ms_version => '2009-09-19'}, nil).returns(mock_request)
293
+
294
+ queues = service.list_queues({:include => 'metadata'})
295
+ queues.first()[:name].should == "mock-queue"
296
+ queues.first()[:url].should == "http://myaccount.queue.core.windows.net/mock-queue"
297
+ queues.first()[:metadata][:x_ms_name] = 'Custom Queue'
298
+ end
299
299
  end