SQS 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +20 -0
- data/lib/sqs.rb +102 -22
- data/lib/sqs/message.rb +8 -5
- data/lib/sqs/queue.rb +20 -4
- data/test/unit/sqs_message_test.rb +45 -4
- data/test/unit/sqs_queue_test.rb +155 -34
- data/test/unit/sqs_test.rb +195 -17
- metadata +2 -2
data/CHANGELOG
CHANGED
@@ -1,3 +1,22 @@
|
|
1
|
+
0.1.5
|
2
|
+
2007-07-18
|
3
|
+
* sqs_queue_test.rb is now dependent on the assert_statistically gem. You can still
|
4
|
+
run SQS without assert_statistically, but you will need assert_statistically to run
|
5
|
+
the tests.
|
6
|
+
* http://developer.amazonwebservices.com/connect/thread.jspa?threadID=15618&tstart=0
|
7
|
+
is now resolved and tested.
|
8
|
+
* Exceptions are now custom SQS:: classes, generated from the error code returned in
|
9
|
+
the web service XML. No more generic RuntimeErrors!
|
10
|
+
* http://developer.amazonwebservices.com/connect/thread.jspa?messageID=61724
|
11
|
+
is now resolved and tested.
|
12
|
+
* Changed SQS.reasons_not_to_retry to SQS.reasons_to_retry and it's now being used!
|
13
|
+
(See http://developer.amazonwebservices.com/connect/thread.jspa?messageID=56888�)
|
14
|
+
* The user can now SQS.add_reasons_to_retry and SQS.remove_reasons_to_retry
|
15
|
+
* The user can now set the number of times to retry, when a request fails and the
|
16
|
+
error code is included? in SQS.reasons_to_retry
|
17
|
+
* Add a random sleep between retries
|
18
|
+
* Ensure that retrying doesn't sleep on the final iteration of the loop
|
19
|
+
|
1
20
|
0.1.4
|
2
21
|
2007-06-12
|
3
22
|
* Upped the API version to 2007-05-01
|
@@ -21,6 +40,7 @@ message as it comes.
|
|
21
40
|
http://developer.amazonwebservices.com/connect/thread.jspa?threadID=15618&tstart=0
|
22
41
|
Is unresolved
|
23
42
|
|
43
|
+
|
24
44
|
0.1.3
|
25
45
|
2007-04-25
|
26
46
|
* Missed one "include REXML."
|
data/lib/sqs.rb
CHANGED
@@ -94,7 +94,7 @@ class SQS
|
|
94
94
|
return queue if queue.name == params[:name]
|
95
95
|
end
|
96
96
|
|
97
|
-
raise "Could not find the queue named '#{params[:name]}'"
|
97
|
+
raise SQS::UnavailableQueue, "Could not find the queue named '#{params[:name]}'"
|
98
98
|
rescue Exception => e
|
99
99
|
raise e
|
100
100
|
end
|
@@ -147,7 +147,12 @@ class SQS
|
|
147
147
|
end
|
148
148
|
|
149
149
|
def self.retry_attempts
|
150
|
-
|
150
|
+
@@retry_attempts
|
151
|
+
end
|
152
|
+
def self.retry_attempts=( new_value )
|
153
|
+
@@retry_attempts = new_value.to_i
|
154
|
+
rescue NoMethodError
|
155
|
+
raise ArgumentError.new( $!.message )
|
151
156
|
end
|
152
157
|
|
153
158
|
def self.params_for_query( t=nil )
|
@@ -171,15 +176,70 @@ class SQS
|
|
171
176
|
def self.increment_counter
|
172
177
|
@@counter += 1
|
173
178
|
end
|
179
|
+
|
180
|
+
def self.reasons_to_retry
|
181
|
+
@@reasons_to_retry.dup
|
182
|
+
end
|
183
|
+
def self.add_reasons_to_retry( *string_or_array )
|
184
|
+
@@reasons_to_retry += (
|
185
|
+
string_or_array[0].is_a?( String ) ?
|
186
|
+
string_or_array :
|
187
|
+
string_or_array[0]
|
188
|
+
)
|
189
|
+
@@reasons_to_retry.uniq!
|
190
|
+
rescue TypeError
|
191
|
+
raise ArgumentError.new( $!.message )
|
192
|
+
end
|
193
|
+
|
194
|
+
def self.remove_reasons_to_retry( *string_or_array )
|
195
|
+
@@reasons_to_retry -= (
|
196
|
+
string_or_array[0].is_a?( String ) ?
|
197
|
+
string_or_array :
|
198
|
+
string_or_array[0]
|
199
|
+
)
|
200
|
+
rescue TypeError
|
201
|
+
raise ArgumentError.new( $!.message )
|
202
|
+
end
|
203
|
+
class <<self
|
204
|
+
alias :add_reason_to_retry :add_reasons_to_retry
|
205
|
+
alias :remove_reason_to_retry :remove_reasons_to_retry
|
206
|
+
end
|
207
|
+
|
174
208
|
protected
|
209
|
+
@@retry_attempts = 10;
|
175
210
|
@@counter = 0;
|
176
211
|
@@secret_access_key = 'Replace this with your secret access key'
|
177
212
|
@@access_key_id = 'Replace this with your access key id'
|
178
213
|
@@url_for_query = 'http://queue.amazonaws.com/'
|
179
|
-
|
214
|
+
@@exception_classes = {}
|
215
|
+
@@reasons_to_retry = [ 'ServiceUnavailable' ]
|
216
|
+
|
217
|
+
def self.get_exception_class( s=nil )
|
218
|
+
raise ArgumentError, "Please specify an error code" if s.to_s.empty?
|
219
|
+
class_name = s.to_s.gsub( /[^a-z0-9]/i, '' )
|
220
|
+
class_name = "#{$1.capitalize}#{$2}" if class_name =~ /^(.)(.*)/
|
221
|
+
class_name = class_name.to_sym
|
222
|
+
@@exception_classes[class_name] ||= eval( "class #{class_name.to_s} < RuntimeError ; end ; #{class_name.to_s}" , binding, __FILE__, __LINE__ )
|
223
|
+
end
|
224
|
+
|
225
|
+
def self.get_exception( params=nil )
|
226
|
+
raise ArgumentError, "You must pass a Hash to SQS.get_exception" unless params.is_a?( Hash )
|
227
|
+
|
228
|
+
if params[:document].respond_to?( :error_code ) && params[:document].respond_to?( :error_message )
|
229
|
+
doc = params[:document]
|
230
|
+
error_code = params[:document].error_code
|
231
|
+
error_message = params[:document].error_message
|
232
|
+
else
|
233
|
+
raise ArgumentError, "Cannot determine error code and message"
|
234
|
+
end
|
235
|
+
if params[:url].respond_to?( :to_s )
|
236
|
+
url = params[:url].to_s
|
237
|
+
else
|
238
|
+
raise ArgumentError, "Cannot determine url"
|
239
|
+
end
|
240
|
+
attempts = params[:attempts].respond_to?( :to_i ) ? attempts = params[:attempts].to_i : 0
|
180
241
|
|
181
|
-
|
182
|
-
[ 'Success', 'InvalidParameterValue' ]
|
242
|
+
self.get_exception_class( error_code ).new( "#{error_message} #{attempts > 0 ? "(After #{attempts} attempt#{attempts == 1 ? '' : 's'}) " : ''}(The XML returned from #{url} was #{doc})" )
|
183
243
|
end
|
184
244
|
|
185
245
|
def self.call_web_service( params )
|
@@ -193,6 +253,7 @@ class SQS
|
|
193
253
|
retries = self.retry_attempts
|
194
254
|
end
|
195
255
|
|
256
|
+
|
196
257
|
if !params[:queue].nil?
|
197
258
|
if params[:queue].respond_to?( :url )
|
198
259
|
url = params[:queue].url
|
@@ -203,28 +264,41 @@ class SQS
|
|
203
264
|
else
|
204
265
|
url = "#{self.url_for_query}"
|
205
266
|
end
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
raise( "#{error_code}: #{error_message} (#{url}#{url_encoded_signature})" )
|
220
|
-
else
|
221
|
-
raise( "Unknown Error: #{doc} (#{url}#{url_encoded_signature})" )
|
267
|
+
|
268
|
+
remaining_attempts = retries + 1
|
269
|
+
while remaining_attempts > 0
|
270
|
+
url_to_use = url + "?#{self.prepare_parameters_for_query( params )}&Signature="
|
271
|
+
|
272
|
+
url_encoded_signature = url_encode( self.create_signature( params ) )
|
273
|
+
|
274
|
+
begin
|
275
|
+
response = Net::HTTP.get( URI.parse( url_to_use + url_encoded_signature ) )
|
276
|
+
self.increment_counter
|
277
|
+
doc = REXML::Document.new( response )
|
278
|
+
rescue
|
279
|
+
raise $!
|
222
280
|
end
|
281
|
+
|
282
|
+
remaining_attempts -= 1
|
283
|
+
|
284
|
+
break if remaining_attempts == 0 || !self.reasons_to_retry.include?( doc.error_code.to_s )
|
285
|
+
|
286
|
+
sleep( rand( 500 ) / 1000.0 ) #sleep for up to half a second
|
223
287
|
end
|
288
|
+
|
289
|
+
raise self.get_exception(
|
290
|
+
:document => doc,
|
291
|
+
:url => ( url_to_use + url_encoded_signature ),
|
292
|
+
:attempts => ( retries + 1 - remaining_attempts )
|
293
|
+
) unless doc.status == 'Success'
|
224
294
|
|
225
295
|
doc
|
226
296
|
rescue Exception => e
|
227
|
-
|
297
|
+
if e.is_a?( SocketError )
|
298
|
+
raise SocketError, "Do you have internet access? (#{e.message})"
|
299
|
+
else
|
300
|
+
raise e
|
301
|
+
end
|
228
302
|
end
|
229
303
|
end
|
230
304
|
|
@@ -262,6 +336,9 @@ module REXML
|
|
262
336
|
def node_text( xpath )
|
263
337
|
code = REXML::XPath.first( self, xpath )
|
264
338
|
code.to_s.empty? ? '' : code.text
|
339
|
+
rescue
|
340
|
+
# puts "XPath #{xpath} on #{self.to_s} resulted in #{$!.class.name}"
|
341
|
+
raise $!
|
265
342
|
end
|
266
343
|
|
267
344
|
def nodes( xpath )
|
@@ -287,6 +364,9 @@ module REXML
|
|
287
364
|
def node_text( xpath )
|
288
365
|
code = REXML::XPath.first( self, xpath )
|
289
366
|
code.to_s.empty? ? '' : code.text
|
367
|
+
rescue
|
368
|
+
# puts "XPath #{xpath} on #{self.to_s} resulted in #{$!.class.name}: #{$!.message}\n#{$!.backtrace.join("\n")}"
|
369
|
+
raise $!
|
290
370
|
end
|
291
371
|
|
292
372
|
def nodes( xpath )
|
data/lib/sqs/message.rb
CHANGED
@@ -11,8 +11,8 @@ class SQS::Message
|
|
11
11
|
|
12
12
|
|
13
13
|
def delete
|
14
|
-
raise "This #{self.class.to_s} cannot be deleted, because there is no associated SQS::Queue" unless self.queue.is_a?( SQS::Queue )
|
15
|
-
raise "Cannot delete a message with no id." if self.id.to_s.empty?
|
14
|
+
raise SQS::UnavailableQueue, "This #{self.class.to_s} cannot be deleted, because there is no associated SQS::Queue" unless self.queue.is_a?( SQS::Queue )
|
15
|
+
raise SQS::MissingId, "Cannot delete a message with no id." if self.id.to_s.empty?
|
16
16
|
|
17
17
|
doc = SQS.call_web_service( :Action => 'DeleteMessage', :queue => self.queue, :MessageId => self.id )
|
18
18
|
true
|
@@ -22,8 +22,8 @@ class SQS::Message
|
|
22
22
|
|
23
23
|
|
24
24
|
def peek
|
25
|
-
raise "This #{self.class.to_s} cannot be peeked, because there is no associated SQS::Queue" unless self.queue.is_a?( SQS::Queue )
|
26
|
-
raise "Cannot peek a message with no id." if self.id.to_s.empty?
|
25
|
+
raise SQS::UnavailableQueue, "This #{self.class.to_s} cannot be peeked, because there is no associated SQS::Queue" unless self.queue.is_a?( SQS::Queue )
|
26
|
+
raise SQS::MissingId, "Cannot peek a message with no id." if self.id.to_s.empty?
|
27
27
|
|
28
28
|
doc = SQS.call_web_service( :Action => 'PeekMessage', :queue => self.queue, :MessageId => self.id )
|
29
29
|
self.body = doc.message_body
|
@@ -40,4 +40,7 @@ class SQS::Message
|
|
40
40
|
self._body = b
|
41
41
|
end
|
42
42
|
|
43
|
-
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class SQS::UnavailableQueue < TypeError ; end
|
46
|
+
class SQS::MissingId < TypeError ; end
|
data/lib/sqs/queue.rb
CHANGED
@@ -19,7 +19,7 @@ class SQS::Queue
|
|
19
19
|
rescue URI::InvalidURIError, NoMethodError
|
20
20
|
bad_url = true
|
21
21
|
end
|
22
|
-
raise "'#{self.url}' does not seem to be a parseable URL. (Please provide all parts of the URL.)" if bad_url
|
22
|
+
raise URI::InvalidURIError, "'#{self.url}' does not seem to be a parseable URL. (Please provide all parts of the URL.)" if bad_url
|
23
23
|
end
|
24
24
|
|
25
25
|
def method_missing( symbol, *args )
|
@@ -164,7 +164,7 @@ class SQS::Queue
|
|
164
164
|
elsif !options[:email].nil?
|
165
165
|
params['Grantee.EmailAddress'.to_sym] = options[:email].respond_to?( :email ) ? options[:email].email : options[:email]
|
166
166
|
else
|
167
|
-
raise "You must specify either a grant id (:id) or a grantee email address (:email) when calling remove_grant."
|
167
|
+
raise ArgumentError, "You must specify either a grant id (:id) or a grantee email address (:email) when calling remove_grant."
|
168
168
|
end
|
169
169
|
|
170
170
|
doc = SQS.call_web_service( params )
|
@@ -173,8 +173,24 @@ class SQS::Queue
|
|
173
173
|
raise e
|
174
174
|
end
|
175
175
|
|
176
|
-
def list_grants
|
177
|
-
|
176
|
+
def list_grants( p=nil )
|
177
|
+
params = { :Action => 'ListGrants', :queue => self }
|
178
|
+
|
179
|
+
case p
|
180
|
+
when SQS::Grant
|
181
|
+
if p.email.to_s.empty?
|
182
|
+
params['Grantee.ID'.to_sym] = p.id
|
183
|
+
else
|
184
|
+
params['Grantee.EmailAddress'.to_sym] = p.email
|
185
|
+
end
|
186
|
+
when Hash
|
187
|
+
params['Grantee.EmailAddress'.to_sym] = p[:email] unless p[:email].to_s.empty?
|
188
|
+
params['Grantee.ID'.to_sym] = p[:id] unless p[:id].to_s.empty?
|
189
|
+
params[:Permission] = SQS.permissions[p[:permission]] unless p[:permission].to_s.empty?
|
190
|
+
end
|
191
|
+
|
192
|
+
|
193
|
+
doc = SQS.call_web_service( params )
|
178
194
|
grants = Array.new
|
179
195
|
doc.grant_lists.each do |list|
|
180
196
|
list.grantees.each do |g|
|
@@ -5,6 +5,14 @@ require 'test/unit'
|
|
5
5
|
require "#{File.expand_path( File.dirname( __FILE__ ) )}/test_setup"
|
6
6
|
|
7
7
|
|
8
|
+
class Test::Unit::TestCase
|
9
|
+
def multi_assert( o={}, &b )
|
10
|
+
echo "I'm in multi_assert"
|
11
|
+
return true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
|
8
16
|
class SQS_MessageTest < Test::Unit::TestCase
|
9
17
|
def setup
|
10
18
|
@queue_prefix = 'testMSG'
|
@@ -22,8 +30,22 @@ class SQS_MessageTest < Test::Unit::TestCase
|
|
22
30
|
assert_equal @q, m.queue
|
23
31
|
assert m.delete
|
24
32
|
sleep 2
|
25
|
-
|
33
|
+
begin
|
26
34
|
m.peek
|
35
|
+
rescue
|
36
|
+
assert_equal 'SQS::MessageNotFound', $!.class.name
|
37
|
+
else
|
38
|
+
flunk "Was supposed to raise an SQS::MessageNotFound"
|
39
|
+
end
|
40
|
+
|
41
|
+
m.id = nil
|
42
|
+
assert_raises SQS::MissingId do
|
43
|
+
m.delete
|
44
|
+
end
|
45
|
+
|
46
|
+
m.queue = nil
|
47
|
+
assert_raises SQS::UnavailableQueue do
|
48
|
+
m.delete
|
27
49
|
end
|
28
50
|
end
|
29
51
|
|
@@ -31,6 +53,17 @@ class SQS_MessageTest < Test::Unit::TestCase
|
|
31
53
|
m = @q.send_message( 'This is something else special' )
|
32
54
|
assert m.peek
|
33
55
|
assert_equal 'This is something else special', m.body
|
56
|
+
|
57
|
+
|
58
|
+
m.id = nil
|
59
|
+
assert_raises SQS::MissingId do
|
60
|
+
m.delete
|
61
|
+
end
|
62
|
+
|
63
|
+
m.queue = nil
|
64
|
+
assert_raises SQS::UnavailableQueue do
|
65
|
+
m.delete
|
66
|
+
end
|
34
67
|
end
|
35
68
|
|
36
69
|
def test_body
|
@@ -44,13 +77,13 @@ class SQS_MessageTest < Test::Unit::TestCase
|
|
44
77
|
end
|
45
78
|
|
46
79
|
def test_new
|
47
|
-
assert_nothing_raised
|
80
|
+
assert_nothing_raised do
|
48
81
|
SQS::Message.new
|
49
82
|
end
|
50
|
-
assert_nothing_raised
|
83
|
+
assert_nothing_raised do
|
51
84
|
SQS::Message.new :a => 'b'
|
52
85
|
end
|
53
|
-
assert_nothing_raised
|
86
|
+
assert_nothing_raised do
|
54
87
|
SQS::Message.new :a => 'b', :body => ''
|
55
88
|
end
|
56
89
|
|
@@ -78,4 +111,12 @@ class SQS_MessageTest < Test::Unit::TestCase
|
|
78
111
|
assert_equal 'Message 2', m2.id
|
79
112
|
assert_equal 'Message 3', m3.id
|
80
113
|
end
|
114
|
+
|
115
|
+
|
116
|
+
# def test_it_all
|
117
|
+
# puts methods.sort.join("\n")
|
118
|
+
# tenaciously_assert( :min => 1, :of => 10 ) do
|
119
|
+
#
|
120
|
+
# end
|
121
|
+
# end
|
81
122
|
end
|
data/test/unit/sqs_queue_test.rb
CHANGED
@@ -4,7 +4,8 @@ dir = File.expand_path( File.dirname( __FILE__ ) )
|
|
4
4
|
require 'test/unit'
|
5
5
|
require "#{File.expand_path( File.dirname( __FILE__ ) )}/test_setup"
|
6
6
|
|
7
|
-
|
7
|
+
require 'rubygems'
|
8
|
+
require 'assert_statistically'
|
8
9
|
|
9
10
|
|
10
11
|
class SQS_QueueTest < Test::Unit::TestCase
|
@@ -15,9 +16,26 @@ class SQS_QueueTest < Test::Unit::TestCase
|
|
15
16
|
def setup
|
16
17
|
@queue_prefix = 'test_queue_'
|
17
18
|
@q = SQStest.skip_live_tests? ? SQS::Queue.new( 'http://nowhere.com/nothing' ) : SQS.create_queue( @queue_prefix )
|
19
|
+
|
20
|
+
unless SQStest.skip_live_tests?
|
21
|
+
assert_statistically( :of => 3, :min => 1, :sleep => 0.25 ) do
|
22
|
+
begin
|
23
|
+
@q = SQS.get_queue( @queue_prefix )
|
24
|
+
rescue
|
25
|
+
false
|
26
|
+
else
|
27
|
+
true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
18
31
|
end
|
19
32
|
def teardown
|
20
|
-
|
33
|
+
unless SQStest.skip_live_tests?
|
34
|
+
SQS.list_queues( @queue_prefix ).each do |q|
|
35
|
+
q.delete!
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
21
39
|
print SQS.counter if SQStest.print_counter?
|
22
40
|
end
|
23
41
|
|
@@ -30,19 +48,31 @@ class SQS_QueueTest < Test::Unit::TestCase
|
|
30
48
|
|
31
49
|
assert @q.delete
|
32
50
|
|
33
|
-
|
51
|
+
begin
|
34
52
|
q3 = SQS.get_queue( @queue_prefix )
|
53
|
+
rescue
|
54
|
+
assert_equal 'SQS::UnavailableQueue', $!.class.name
|
55
|
+
else
|
56
|
+
flunk 'Was supposed to raise an SQS::UnavailableQueue'
|
35
57
|
end
|
36
58
|
|
37
|
-
|
59
|
+
begin
|
38
60
|
q2.delete
|
61
|
+
rescue
|
62
|
+
assert_equal 'SQS::AWSSimpleQueueServiceNonExistentQueue', $!.class.name
|
63
|
+
else
|
64
|
+
flunk 'Was supposed to raise an SQS::AWSSimpleQueueServiceNonExistentQueue'
|
39
65
|
end
|
40
66
|
|
41
67
|
q = SQS.create_queue :name => "#{@queue_prefix}test_delete"
|
42
68
|
q.send_message( 'A' )
|
43
69
|
q.send_message( 'B' )
|
44
|
-
|
70
|
+
begin
|
45
71
|
q.delete
|
72
|
+
rescue
|
73
|
+
assert_equal 'SQS::AWSSimpleQueueServiceNonEmptyQueue', $!.class.name
|
74
|
+
else
|
75
|
+
flunk 'Was supposed to raise an SQS::AWSSimpleQueueServiceNonEmptyQueue'
|
46
76
|
end
|
47
77
|
assert_nothing_raised do
|
48
78
|
q.delete( :force => true )
|
@@ -52,15 +82,23 @@ class SQS_QueueTest < Test::Unit::TestCase
|
|
52
82
|
def test_delete!
|
53
83
|
@q.send_message( 'A' )
|
54
84
|
@q.send_message( 'B' )
|
55
|
-
|
85
|
+
begin
|
56
86
|
@q.delete
|
87
|
+
rescue
|
88
|
+
assert_equal 'SQS::AWSSimpleQueueServiceNonEmptyQueue', $!.class.name
|
89
|
+
else
|
90
|
+
asssert false, "Was supposed to raise an SQS::AWSSimpleQueueServiceNonEmptyQueue"
|
57
91
|
end
|
58
92
|
assert_nothing_raised do
|
59
93
|
@q.delete!
|
60
94
|
end
|
61
|
-
|
62
|
-
|
95
|
+
|
96
|
+
begin
|
63
97
|
q = SQS.get_queue( @queue_prefix )
|
98
|
+
rescue
|
99
|
+
assert_equal 'SQS::UnavailableQueue', $!.class.name
|
100
|
+
else
|
101
|
+
flunk 'Was supposed to raise an SQS::UnavailableQueue'
|
64
102
|
end
|
65
103
|
end
|
66
104
|
|
@@ -71,8 +109,12 @@ class SQS_QueueTest < Test::Unit::TestCase
|
|
71
109
|
|
72
110
|
sleep 5
|
73
111
|
|
74
|
-
|
112
|
+
begin
|
75
113
|
@q.delete
|
114
|
+
rescue
|
115
|
+
assert_equal 'SQS::AWSSimpleQueueServiceNonEmptyQueue', $!.class.name
|
116
|
+
else
|
117
|
+
flunk 'Was supposed to raise an SQS::AWSSimpleQueueServiceNonEmptyQueue'
|
76
118
|
end
|
77
119
|
|
78
120
|
assert_nothing_raised do
|
@@ -81,8 +123,12 @@ class SQS_QueueTest < Test::Unit::TestCase
|
|
81
123
|
|
82
124
|
sleep 5
|
83
125
|
|
84
|
-
|
126
|
+
begin
|
85
127
|
q = SQS.get_queue( @queue_prefix )
|
128
|
+
rescue
|
129
|
+
assert_equal 'SQS::UnavailableQueue', $!.class.name
|
130
|
+
else
|
131
|
+
flunk 'Was supposed to raise an SQS::UnavailableQueue'
|
86
132
|
end
|
87
133
|
end
|
88
134
|
|
@@ -140,14 +186,19 @@ class SQS_QueueTest < Test::Unit::TestCase
|
|
140
186
|
assert_nothing_raised do
|
141
187
|
@q.get_queue_attributes( true )
|
142
188
|
end
|
143
|
-
|
189
|
+
assert_statistically( :of => 10, :min => 1, :sleep => 1 ) do
|
190
|
+
@q.get_queue_attributes( true )
|
191
|
+
400 == @q.attributes[:VisibilityTimeout]
|
192
|
+
end
|
144
193
|
assert_equal 0, @q.attributes[:ApproximateNumberOfMessages]
|
145
194
|
|
146
195
|
|
147
|
-
|
148
|
-
# This should ultimately raise an error, but does not as of 2007-06-12
|
149
|
-
# See http://developer.amazonwebservices.com/connect/thread.jspa?threadID=15618&tstart=0
|
196
|
+
begin
|
150
197
|
@q.set_queue_attributes( :SHOULDBEANERROR => 'crazy!' )
|
198
|
+
rescue
|
199
|
+
assert_equal 'SQS::InvalidAttributeName', $!.class.name
|
200
|
+
else
|
201
|
+
flunk 'Was supposed to raise an SQS::InvalidAttributeName'
|
151
202
|
end
|
152
203
|
end
|
153
204
|
|
@@ -185,26 +236,30 @@ class SQS_QueueTest < Test::Unit::TestCase
|
|
185
236
|
|
186
237
|
# Update happens in situ
|
187
238
|
assert_equal 500, @q.visibility_timeout
|
188
|
-
|
239
|
+
assert_statistically( :of => 10, :min => 1, :sleep => 1 ) do
|
240
|
+
@q.visibility_timeout( true ) == 500
|
241
|
+
end
|
189
242
|
end
|
190
243
|
|
191
244
|
def test_empty?
|
192
245
|
assert @q.empty?
|
193
246
|
|
194
247
|
@q.send_message( 'no longer empty' )
|
195
|
-
sleep
|
248
|
+
sleep 3
|
196
249
|
assert !@q.empty?
|
197
250
|
|
198
251
|
@q.send_message( 'no longer empty again' )
|
199
252
|
|
200
253
|
assert !@q.empty?
|
201
|
-
|
202
|
-
|
203
|
-
|
254
|
+
|
255
|
+
sleep 3
|
256
|
+
while m = @q.receive_message
|
204
257
|
m.delete
|
205
258
|
end
|
206
259
|
|
207
|
-
|
260
|
+
assert_statistically( :min => 1, :of => 3, :sleep => 1, :message => 'Attempt %d failed' ) do
|
261
|
+
@q.empty?
|
262
|
+
end
|
208
263
|
end
|
209
264
|
|
210
265
|
|
@@ -304,13 +359,23 @@ class SQS_QueueTest < Test::Unit::TestCase
|
|
304
359
|
|
305
360
|
def test_add_grant
|
306
361
|
assert_respond_to @q, :add_grant
|
362
|
+
|
307
363
|
assert_equal 1, @q.list_grants.size
|
364
|
+
|
308
365
|
assert @q.add_grant( :email => SQStest.other_aws_account[:email], :permission => :full )
|
309
|
-
|
366
|
+
assert_statistically( :of => 3, :min => 1, :sleep => 0.5 ) do
|
367
|
+
2 == @q.list_grants.size
|
368
|
+
end
|
369
|
+
|
310
370
|
assert @q.add_grant( :email => SQStest.other_aws_account[:email], :permission => :send )
|
311
|
-
|
371
|
+
assert_statistically( :of => 3, :min => 1, :sleep => 0.5 ) do
|
372
|
+
3 == @q.list_grants.size
|
373
|
+
end
|
374
|
+
|
312
375
|
assert @q.add_grant( :email => SQStest.other_aws_account[:email], :permission => :receive )
|
313
|
-
|
376
|
+
assert_statistically( :of => 3, :min => 1, :sleep => 0.5 ) do
|
377
|
+
4 == @q.list_grants.size
|
378
|
+
end
|
314
379
|
|
315
380
|
assert_nothing_raised do
|
316
381
|
#DUMMY responds to :email (is not an address itself)
|
@@ -318,15 +383,25 @@ class SQS_QueueTest < Test::Unit::TestCase
|
|
318
383
|
end
|
319
384
|
assert_equal 4, @q.list_grants.size
|
320
385
|
|
321
|
-
|
322
|
-
|
323
|
-
|
386
|
+
begin
|
387
|
+
@q.add_grant( :email => 'invalid@email.address', :permission => :receive )
|
388
|
+
rescue
|
389
|
+
assert_equal 'SQS::ServiceUnavailable', $!.class.name
|
390
|
+
else
|
391
|
+
flunk "Was supposed to raise an SQS::ServiceUnavailable"
|
324
392
|
end
|
325
393
|
end
|
326
394
|
|
327
395
|
def test_remove_grant
|
328
396
|
assert_respond_to @q, :remove_grant
|
329
397
|
|
398
|
+
[:full, :send, :receive].each do |perm|
|
399
|
+
assert_raises ArgumentError do
|
400
|
+
@q.remove_grant( :permission => perm )
|
401
|
+
end
|
402
|
+
end
|
403
|
+
|
404
|
+
|
330
405
|
|
331
406
|
[:full, :send, :receive].each do |perm|
|
332
407
|
assert @q.add_grant( :email => SQStest.other_aws_account[:email], :permission => perm )
|
@@ -377,8 +452,17 @@ class SQS_QueueTest < Test::Unit::TestCase
|
|
377
452
|
assert_equal SQStest.my_aws_account[:display_name], grant.display_name
|
378
453
|
|
379
454
|
@q.add_grant( :email => SQStest.other_aws_account[:email], :permission => :receive)
|
455
|
+
|
380
456
|
grants = @q.list_grants
|
381
|
-
|
457
|
+
if grants.size != 2
|
458
|
+
assert_statistically( :of => 4, :min => 1, :sleep => 0.5 ) do
|
459
|
+
grants = @q.list_grants
|
460
|
+
2 == grants.size
|
461
|
+
end
|
462
|
+
else
|
463
|
+
assert true
|
464
|
+
end
|
465
|
+
|
382
466
|
grants.each do |grant|
|
383
467
|
case grant.display_name
|
384
468
|
when SQStest.my_aws_account[:display_name]
|
@@ -386,9 +470,24 @@ class SQS_QueueTest < Test::Unit::TestCase
|
|
386
470
|
when SQStest.other_aws_account[:display_name]
|
387
471
|
assert_equal SQS.permissions[:receive], grant.permission
|
388
472
|
else
|
389
|
-
|
473
|
+
flunk "'#{grant.display_name}' is an unknown display name"
|
390
474
|
end
|
391
475
|
end
|
476
|
+
|
477
|
+
|
478
|
+
grants = @q.list_grants( :email => SQStest.other_aws_account[:email] )
|
479
|
+
assert_equal 1, grants.size
|
480
|
+
grants.each do |g|
|
481
|
+
assert_kind_of SQS::Grant, g
|
482
|
+
assert_equal SQStest.other_aws_account[:display_name], g.display_name
|
483
|
+
end
|
484
|
+
|
485
|
+
grants = @q.list_grants( :permission => :receive )
|
486
|
+
assert_equal 1, grants.size
|
487
|
+
grants.each do |g|
|
488
|
+
assert_kind_of SQS::Grant, g
|
489
|
+
assert_equal SQStest.other_aws_account[:display_name], g.display_name
|
490
|
+
end
|
392
491
|
end
|
393
492
|
|
394
493
|
|
@@ -416,6 +515,7 @@ class SQS_QueueTest < Test::Unit::TestCase
|
|
416
515
|
end
|
417
516
|
end
|
418
517
|
|
518
|
+
|
419
519
|
def test_get_visiblity_timeout
|
420
520
|
assert_equal SQS::Queue.default_visibility_timeout, @q.visibility_timeout
|
421
521
|
assert_kind_of Integer, @q.visibility_timeout
|
@@ -429,31 +529,52 @@ class SQS_QueueTest < Test::Unit::TestCase
|
|
429
529
|
assert( @q.visibility_timeout = 456 )
|
430
530
|
assert_equal 456, @q.visibility_timeout
|
431
531
|
|
432
|
-
|
532
|
+
begin
|
433
533
|
@q.visibility_timeout = nil
|
534
|
+
rescue
|
535
|
+
assert_equal 'SQS::EmptyValue', $!.class.name
|
536
|
+
else
|
537
|
+
flunk 'Was supposed to raise an SQS::EmptyValue'
|
434
538
|
end
|
435
539
|
|
436
540
|
assert_nothing_raised do
|
437
541
|
@q.visibility_timeout = 0
|
438
542
|
end
|
439
543
|
|
440
|
-
|
544
|
+
begin
|
441
545
|
@q.visibility_timeout = -1
|
546
|
+
rescue
|
547
|
+
assert_equal 'SQS::InvalidAttributeValue', $!.class.name
|
548
|
+
else
|
549
|
+
flunk 'Was supposed to raise an SQS::InvalidAttributeValue'
|
442
550
|
end
|
443
|
-
|
551
|
+
|
552
|
+
begin
|
444
553
|
@q.visibility_timeout = 86401
|
554
|
+
rescue
|
555
|
+
assert_equal 'SQS::InvalidAttributeValue', $!.class.name
|
556
|
+
else
|
557
|
+
flunk 'Was supposed to raise an SQS::InvalidAttributeValue'
|
445
558
|
end
|
446
559
|
|
447
|
-
|
560
|
+
begin
|
448
561
|
@q.visibility_timeout = Object
|
562
|
+
rescue
|
563
|
+
assert_equal 'SQS::InvalidAttributeValue', $!.class.name
|
564
|
+
else
|
565
|
+
flunk 'Was supposed to raise an SQS::InvalidAttributeValue'
|
449
566
|
end
|
450
567
|
end
|
451
568
|
|
452
569
|
|
453
570
|
def test_legal_names
|
454
571
|
assert !SQS.create_queue( '' )
|
455
|
-
|
572
|
+
begin
|
456
573
|
SQS.create_queue( '81characterslongxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' )
|
574
|
+
rescue
|
575
|
+
assert_equal 'SQS::InvalidParameterValue', $!.class.name
|
576
|
+
else
|
577
|
+
flunk 'Was supposed to raise an SQS::InvalidParameterValue'
|
457
578
|
end
|
458
579
|
assert q = SQS.create_queue( '80characterslongxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' )
|
459
580
|
q.delete
|
@@ -492,7 +613,7 @@ class SQS_QueueTest < Test::Unit::TestCase
|
|
492
613
|
q.b
|
493
614
|
end
|
494
615
|
|
495
|
-
assert_raises
|
616
|
+
assert_raises URI::InvalidURIError do
|
496
617
|
q = SQS::Queue.new :url => 'http://www.slappy.com'
|
497
618
|
q = SQS::Queue.new :url => 'LKJSDFLKJ@#$)()'
|
498
619
|
end
|
data/test/unit/sqs_test.rb
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
require 'test/unit'
|
4
4
|
require "#{File.expand_path( File.dirname( __FILE__ ) )}/test_setup"
|
5
|
-
include REXML
|
6
5
|
|
7
6
|
class DuckTypeParameter
|
8
7
|
def initialize( st )
|
@@ -20,6 +19,10 @@ class SQSTest < Test::Unit::TestCase
|
|
20
19
|
def setup
|
21
20
|
@queue_prefix = 'testSQS'
|
22
21
|
@q = SQS.create_queue( @queue_prefix ) unless SQStest.skip_live_tests?
|
22
|
+
|
23
|
+
SQS.add_reasons_to_retry 'ServiceUnavailable'
|
24
|
+
SQS.remove_reasons_to_retry( SQS.reasons_to_retry.reject { |r| r == 'ServiceUnavailable' } )
|
25
|
+
SQS.retry_attempts = 10
|
23
26
|
end
|
24
27
|
def teardown
|
25
28
|
SQS.list_queues( @queue_prefix ).each { |q| q.delete! } unless SQStest.skip_live_tests?
|
@@ -62,13 +65,17 @@ class SQSTest < Test::Unit::TestCase
|
|
62
65
|
assert q1.is_a?( SQS::Queue )
|
63
66
|
assert q2.is_a?( SQS::Queue )
|
64
67
|
assert_equal q1, q2
|
68
|
+
|
69
|
+
assert_raises SQS::UnavailableQueue do
|
70
|
+
SQS.get_queue( "SHOULD_NEVER_EXIST" )
|
71
|
+
end
|
65
72
|
end
|
66
73
|
|
67
74
|
def test_get_non_existent_queue
|
68
75
|
assert_respond_to SQS, :get_queue
|
69
76
|
|
70
77
|
queuename = "#{@queue_prefix}nonexist"
|
71
|
-
assert_raises
|
78
|
+
assert_raises SQS::UnavailableQueue do
|
72
79
|
q2 = SQS.get_queue( queuename )
|
73
80
|
end
|
74
81
|
end
|
@@ -84,8 +91,12 @@ class SQSTest < Test::Unit::TestCase
|
|
84
91
|
end
|
85
92
|
|
86
93
|
def test_call_web_service
|
87
|
-
|
94
|
+
begin
|
88
95
|
SQS.call_web_service( :Something => 'for nothing' )
|
96
|
+
rescue
|
97
|
+
assert_equal 'SQS::InvalidAction', $!.class.name
|
98
|
+
else
|
99
|
+
flunk "Was supposed to raise an SQS::InvalidAction"
|
89
100
|
end
|
90
101
|
|
91
102
|
x = nil
|
@@ -95,6 +106,61 @@ class SQSTest < Test::Unit::TestCase
|
|
95
106
|
assert_equal REXML::Document, x.class
|
96
107
|
end
|
97
108
|
end
|
109
|
+
|
110
|
+
|
111
|
+
def test_get_exception_class
|
112
|
+
assert_raises ArgumentError do
|
113
|
+
SQS.get_exception_class
|
114
|
+
end
|
115
|
+
assert_raises ArgumentError do
|
116
|
+
SQS.get_exception_class( nil )
|
117
|
+
end
|
118
|
+
|
119
|
+
assert_nothing_raised do
|
120
|
+
SQS.get_exception_class( 'Crazy' )
|
121
|
+
end
|
122
|
+
assert_equal Class, SQS.get_exception_class( 'Crazy' ).class
|
123
|
+
assert_equal 'SQS::Crazy', SQS.get_exception_class( 'Crazy' ).name
|
124
|
+
|
125
|
+
assert_equal Class, SQS.get_exception_class( 'good For Nothing' ).class
|
126
|
+
assert_equal 'SQS::GoodForNothing', SQS.get_exception_class( 'good For Nothing' ).name
|
127
|
+
|
128
|
+
assert_equal Class, SQS.get_exception_class( 'good.For.Nothing' ).class
|
129
|
+
assert_equal 'SQS::GoodForNothing', SQS.get_exception_class( 'good.For.Nothing' ).name
|
130
|
+
|
131
|
+
assert_equal Class, SQS.get_exception_class( '&(#Sunday)99' ).class
|
132
|
+
assert_equal 'SQS::Sunday99', SQS.get_exception_class( '&(#Sunday)99' ).name
|
133
|
+
end
|
134
|
+
def test_get_exception
|
135
|
+
assert_raises ArgumentError do
|
136
|
+
SQS.get_exception
|
137
|
+
end
|
138
|
+
assert_raises ArgumentError do
|
139
|
+
SQS.get_exception( 9 )
|
140
|
+
end
|
141
|
+
assert_raises ArgumentError do
|
142
|
+
SQS.get_exception( 'Thursday' )
|
143
|
+
end
|
144
|
+
assert_raises ArgumentError do
|
145
|
+
SQS.get_exception( {} )
|
146
|
+
end
|
147
|
+
|
148
|
+
e = SQS.get_exception( :url => "I'm a URL!", :document => REXML::Document.new( "<?xml version='1.0'?><Response><Errors><Error><Code>ServiceUnavailable</Code><Message>Service Queue is currently unavailable. Please try again later</Message></Error></Errors><RequestID>6847ea9e-af25-4fc7-9974-75b6bef82581</RequestID></Response>" ) )
|
149
|
+
assert_equal 'SQS::ServiceUnavailable', e.class.name
|
150
|
+
assert_match /^Service Queue is currently unavailable\. Please try again later \(The XML/, e.message
|
151
|
+
|
152
|
+
e = SQS.get_exception( :attempts => 0, :url => "I'm a URL!", :document => REXML::Document.new( "<?xml version='1.0'?><Response><Errors><Error><Code>ServiceUnavailable</Code><Message>Service Queue is currently unavailable. Please try again later</Message></Error></Errors><RequestID>6847ea9e-af25-4fc7-9974-75b6bef82581</RequestID></Response>" ) )
|
153
|
+
assert_equal 'SQS::ServiceUnavailable', e.class.name
|
154
|
+
assert_match /^Service Queue is currently unavailable\. Please try again later \(The XML/, e.message
|
155
|
+
|
156
|
+
e = SQS.get_exception( :attempts => 1, :url => "I'm a URL!", :document => REXML::Document.new( "<?xml version='1.0'?><Response><Errors><Error><Code>ServiceUnavailable</Code><Message>Service Queue is currently unavailable. Please try again later</Message></Error></Errors><RequestID>6847ea9e-af25-4fc7-9974-75b6bef82581</RequestID></Response>" ) )
|
157
|
+
assert_equal 'SQS::ServiceUnavailable', e.class.name
|
158
|
+
assert_match /^Service Queue is currently unavailable\. Please try again later \(After 1 attempt\) \(The XML/, e.message
|
159
|
+
|
160
|
+
e = SQS.get_exception( :attempts => 2, :url => "I'm a URL!", :document => REXML::Document.new( "<?xml version='1.0'?><Response><Errors><Error><Code>ServiceUnavailable</Code><Message>Service Queue is currently unavailable. Please try again later</Message></Error></Errors><RequestID>6847ea9e-af25-4fc7-9974-75b6bef82581</RequestID></Response>" ) )
|
161
|
+
assert_equal 'SQS::ServiceUnavailable', e.class.name
|
162
|
+
assert_match /^Service Queue is currently unavailable\. Please try again later \(After 2 attempts\) \(The XML/, e.message
|
163
|
+
end
|
98
164
|
|
99
165
|
def test_counter
|
100
166
|
initial_counter = SQS.counter
|
@@ -212,6 +278,109 @@ class SQSTest < Test::Unit::TestCase
|
|
212
278
|
assert 1 <= SQS.retry_attempts
|
213
279
|
end
|
214
280
|
|
281
|
+
def test_change_retry_attempts
|
282
|
+
assert_respond_to SQS, :retry_attempts=
|
283
|
+
|
284
|
+
assert_raises ArgumentError do
|
285
|
+
SQS.retry_attempts = Object
|
286
|
+
end
|
287
|
+
assert_equal 10, SQS.retry_attempts
|
288
|
+
|
289
|
+
assert_nothing_raised ArgumentError do
|
290
|
+
SQS.retry_attempts = nil
|
291
|
+
end
|
292
|
+
assert_equal 0, SQS.retry_attempts
|
293
|
+
|
294
|
+
assert_nothing_raised do
|
295
|
+
SQS.retry_attempts = 2
|
296
|
+
end
|
297
|
+
assert_equal 2, SQS.retry_attempts
|
298
|
+
end
|
299
|
+
|
300
|
+
|
301
|
+
def test_reasons_to_retry
|
302
|
+
assert_respond_to SQS, :reasons_to_retry
|
303
|
+
assert_kind_of Array, SQS.reasons_to_retry
|
304
|
+
assert_equal ['ServiceUnavailable'], SQS.reasons_to_retry
|
305
|
+
end
|
306
|
+
|
307
|
+
def test_add_reasons_to_retry
|
308
|
+
assert_respond_to SQS, :add_reasons_to_retry
|
309
|
+
assert_respond_to SQS, :add_reasons_to_retry
|
310
|
+
|
311
|
+
assert_raises ArgumentError do
|
312
|
+
SQS.add_reasons_to_retry
|
313
|
+
end
|
314
|
+
|
315
|
+
assert_raises ArgumentError do
|
316
|
+
SQS.add_reasons_to_retry( nil )
|
317
|
+
end
|
318
|
+
assert_equal ['ServiceUnavailable'], SQS.reasons_to_retry
|
319
|
+
|
320
|
+
assert_nothing_raised do
|
321
|
+
SQS.add_reasons_to_retry( 'ServiceUnavailable' )
|
322
|
+
end
|
323
|
+
assert_equal ['ServiceUnavailable'], SQS.reasons_to_retry
|
324
|
+
|
325
|
+
assert_nothing_raised do
|
326
|
+
SQS.add_reasons_to_retry( 'a' )
|
327
|
+
end
|
328
|
+
assert_equal ['ServiceUnavailable', 'a'], SQS.reasons_to_retry
|
329
|
+
|
330
|
+
|
331
|
+
assert_nothing_raised do
|
332
|
+
SQS.add_reasons_to_retry( 'b', 'c' )
|
333
|
+
end
|
334
|
+
assert_equal ['ServiceUnavailable', 'a', 'b', 'c' ], SQS.reasons_to_retry
|
335
|
+
|
336
|
+
assert_nothing_raised do
|
337
|
+
SQS.add_reasons_to_retry( ['d', 'e'] )
|
338
|
+
end
|
339
|
+
assert_equal ['ServiceUnavailable', 'a', 'b', 'c', 'd', 'e' ], SQS.reasons_to_retry
|
340
|
+
end
|
341
|
+
|
342
|
+
def test_remove_reasons_to_retry
|
343
|
+
assert_respond_to SQS, :remove_reasons_to_retry
|
344
|
+
assert_respond_to SQS, :remove_reason_to_retry
|
345
|
+
|
346
|
+
assert_nothing_raised do
|
347
|
+
SQS.add_reasons_to_retry( 'a', 'b', 'c', 'd', 'e' )
|
348
|
+
end
|
349
|
+
assert_equal ['ServiceUnavailable', 'a', 'b', 'c', 'd', 'e' ], SQS.reasons_to_retry
|
350
|
+
|
351
|
+
|
352
|
+
assert_raises ArgumentError do
|
353
|
+
SQS.remove_reasons_to_retry
|
354
|
+
end
|
355
|
+
|
356
|
+
assert_raises ArgumentError do
|
357
|
+
SQS.remove_reasons_to_retry( nil )
|
358
|
+
end
|
359
|
+
assert_equal ['ServiceUnavailable', 'a', 'b', 'c', 'd', 'e' ], SQS.reasons_to_retry
|
360
|
+
|
361
|
+
assert_nothing_raised do
|
362
|
+
SQS.remove_reasons_to_retry( 'ServiceUnavailable' )
|
363
|
+
end
|
364
|
+
assert_equal ['a', 'b', 'c', 'd', 'e' ], SQS.reasons_to_retry
|
365
|
+
|
366
|
+
assert_nothing_raised do
|
367
|
+
SQS.remove_reasons_to_retry( 'a' )
|
368
|
+
end
|
369
|
+
assert_equal ['b', 'c', 'd', 'e' ], SQS.reasons_to_retry
|
370
|
+
|
371
|
+
|
372
|
+
assert_nothing_raised do
|
373
|
+
SQS.remove_reasons_to_retry( 'b', 'c' )
|
374
|
+
end
|
375
|
+
assert_equal ['d', 'e' ], SQS.reasons_to_retry
|
376
|
+
|
377
|
+
assert_nothing_raised do
|
378
|
+
SQS.remove_reasons_to_retry( ['d', 'e'] )
|
379
|
+
end
|
380
|
+
assert SQS.reasons_to_retry.empty?
|
381
|
+
end
|
382
|
+
|
383
|
+
|
215
384
|
def test_iso8601
|
216
385
|
t = Time.now
|
217
386
|
assert_respond_to t, :to_iso8601
|
@@ -225,46 +394,46 @@ class SQSTest < Test::Unit::TestCase
|
|
225
394
|
end
|
226
395
|
|
227
396
|
def test_xpath
|
228
|
-
d = Document.new( "<?xml version='1.0'?><CreateQueueResponse xmlns='http://queue.amazonaws.com/doc/2006-04-01/'><QueueUrl>http://queue.amazonaws.com/A3ZVJ8HH1F466/nothing</QueueUrl><ResponseStatus><StatusCode>Success</StatusCode><RequestId>945de8b9-a820-4329-a56e-211053d89d0b</RequestId></ResponseStatus></CreateQueueResponse>" )
|
397
|
+
d = REXML::Document.new( "<?xml version='1.0'?><CreateQueueResponse xmlns='http://queue.amazonaws.com/doc/2006-04-01/'><QueueUrl>http://queue.amazonaws.com/A3ZVJ8HH1F466/nothing</QueueUrl><ResponseStatus><StatusCode>Success</StatusCode><RequestId>945de8b9-a820-4329-a56e-211053d89d0b</RequestId></ResponseStatus></CreateQueueResponse>" )
|
229
398
|
assert_equal 'Success', d.status
|
230
399
|
assert_equal 'http://queue.amazonaws.com/A3ZVJ8HH1F466/nothing', d.queue_url
|
231
400
|
|
232
401
|
|
233
|
-
d = Document.new( "<?xml version='1.0'?><Response><Errors><Error><Code>AuthFailure</Code><Message>AWS was not able to authenticate the request: access credentials are missing</Message></Error></Errors><RequestID>8f6707de-db6e-4bf7-909c-8dd6486bd42f</RequestID></Response>" )
|
402
|
+
d = REXML::Document.new( "<?xml version='1.0'?><Response><Errors><Error><Code>AuthFailure</Code><Message>AWS was not able to authenticate the request: access credentials are missing</Message></Error></Errors><RequestID>8f6707de-db6e-4bf7-909c-8dd6486bd42f</RequestID></Response>" )
|
234
403
|
assert_equal 'AuthFailure', d.error_code
|
235
404
|
assert_equal 'AWS was not able to authenticate the request: access credentials are missing', d.error_message
|
236
405
|
|
237
406
|
|
238
|
-
d = Document.new( "<?xml version='1.0'?><ListQueuesResponse xmlns='http://queue.amazonaws.com/doc/2006-04-01/'><QueueUrl>http://queue.amazonaws.com/A3ZVJ8HH1F466/nothing</QueueUrl><ResponseStatus><StatusCode>Success</StatusCode><RequestId>c2d4fe0b-f6f1-4874-9e6d-d081a1155b54</RequestId></ResponseStatus></ListQueuesResponse>" )
|
407
|
+
d = REXML::Document.new( "<?xml version='1.0'?><ListQueuesResponse xmlns='http://queue.amazonaws.com/doc/2006-04-01/'><QueueUrl>http://queue.amazonaws.com/A3ZVJ8HH1F466/nothing</QueueUrl><ResponseStatus><StatusCode>Success</StatusCode><RequestId>c2d4fe0b-f6f1-4874-9e6d-d081a1155b54</RequestId></ResponseStatus></ListQueuesResponse>" )
|
239
408
|
assert_equal 'Success', d.status
|
240
409
|
|
241
410
|
|
242
|
-
d = Document.new( "<?xml version='1.0'?><ListQueuesResponse xmlns='http://queue.amazonaws.com/doc/2006-04-01/'><QueueUrl>http://queue.amazonaws.com/A3ZVJ8HH1F466/nothingAgain</QueueUrl><QueueUrl>http://queue.amazonaws.com/A3ZVJ8HH1F466/nothing</QueueUrl><ResponseStatus><StatusCode>Success</StatusCode><RequestId>e27b54da-ff38-413b-b52f-82a6342cd151</RequestId></ResponseStatus></ListQueuesResponse>" )
|
411
|
+
d = REXML::Document.new( "<?xml version='1.0'?><ListQueuesResponse xmlns='http://queue.amazonaws.com/doc/2006-04-01/'><QueueUrl>http://queue.amazonaws.com/A3ZVJ8HH1F466/nothingAgain</QueueUrl><QueueUrl>http://queue.amazonaws.com/A3ZVJ8HH1F466/nothing</QueueUrl><ResponseStatus><StatusCode>Success</StatusCode><RequestId>e27b54da-ff38-413b-b52f-82a6342cd151</RequestId></ResponseStatus></ListQueuesResponse>" )
|
243
412
|
assert_equal 'Success', d.status
|
244
413
|
assert_equal 'e27b54da-ff38-413b-b52f-82a6342cd151', d.request_id
|
245
414
|
|
246
415
|
|
247
|
-
d = Document.new( "<?xml version='1.0'?><SendMessageResponse xmlns='http://queue.amazonaws.com/doc/2006-04-01/'><MessageId>171Q1105D8GTGS9FR4QB|9CBMKVD6TTQX44QJ1S30|PT6DRTB278S4MNY77NJ0</MessageId><ResponseStatus><StatusCode>Success</StatusCode><RequestId>ddbab3dc-3910-4c86-a139-27e37cabeac4</RequestId></ResponseStatus></SendMessageResponse>" )
|
416
|
+
d = REXML::Document.new( "<?xml version='1.0'?><SendMessageResponse xmlns='http://queue.amazonaws.com/doc/2006-04-01/'><MessageId>171Q1105D8GTGS9FR4QB|9CBMKVD6TTQX44QJ1S30|PT6DRTB278S4MNY77NJ0</MessageId><ResponseStatus><StatusCode>Success</StatusCode><RequestId>ddbab3dc-3910-4c86-a139-27e37cabeac4</RequestId></ResponseStatus></SendMessageResponse>" )
|
248
417
|
assert_equal '171Q1105D8GTGS9FR4QB|9CBMKVD6TTQX44QJ1S30|PT6DRTB278S4MNY77NJ0', d.message_id( :send )
|
249
418
|
assert_equal 'Success', d.status
|
250
419
|
assert_equal 'ddbab3dc-3910-4c86-a139-27e37cabeac4', d.request_id
|
251
420
|
|
252
421
|
|
253
|
-
d = Document.new( "<?xml version='1.0'?><PeekMessageResponse xmlns='http://queue.amazonaws.com/doc/2006-04-01/'><Message><MessageId>1WB69MM74V13FFJRTA65|3H4AA8J7EJKM0DQZR7E1|9CBMKVD6TTQX44QJ1S30</MessageId><MessageBody>what it is</MessageBody></Message><ResponseStatus><StatusCode>Success</StatusCode><RequestId>c23c96f4-6479-48d3-b1e4-158ebfe0cc17</RequestId></ResponseStatus></PeekMessageResponse>" )
|
422
|
+
d = REXML::Document.new( "<?xml version='1.0'?><PeekMessageResponse xmlns='http://queue.amazonaws.com/doc/2006-04-01/'><Message><MessageId>1WB69MM74V13FFJRTA65|3H4AA8J7EJKM0DQZR7E1|9CBMKVD6TTQX44QJ1S30</MessageId><MessageBody>what it is</MessageBody></Message><ResponseStatus><StatusCode>Success</StatusCode><RequestId>c23c96f4-6479-48d3-b1e4-158ebfe0cc17</RequestId></ResponseStatus></PeekMessageResponse>" )
|
254
423
|
assert_equal 'what it is', d.message_body
|
255
424
|
assert_equal '1WB69MM74V13FFJRTA65|3H4AA8J7EJKM0DQZR7E1|9CBMKVD6TTQX44QJ1S30', d.message_id( :peek )
|
256
425
|
assert_equal 'Success', d.status
|
257
426
|
assert_equal 'c23c96f4-6479-48d3-b1e4-158ebfe0cc17', d.request_id
|
258
427
|
|
259
428
|
|
260
|
-
d = Document.new( "<?xml version='1.0'?><ReceiveMessageResponse xmlns='http://queue.amazonaws.com/doc/2006-04-01/'><Message><MessageId>0C2GG4PAQACB5REHPA7W|3H4AA8J7EJKM0DQZR7E1|9CBMKVD6TTQX44QJ1S30</MessageId><MessageBody>you are silly person</MessageBody></Message><ResponseStatus><StatusCode>Success</StatusCode><RequestId>a901d3ec-24b6-4125-9345-36f01cd82021</RequestId></ResponseStatus></ReceiveMessageResponse>" )
|
429
|
+
d = REXML::Document.new( "<?xml version='1.0'?><ReceiveMessageResponse xmlns='http://queue.amazonaws.com/doc/2006-04-01/'><Message><MessageId>0C2GG4PAQACB5REHPA7W|3H4AA8J7EJKM0DQZR7E1|9CBMKVD6TTQX44QJ1S30</MessageId><MessageBody>you are silly person</MessageBody></Message><ResponseStatus><StatusCode>Success</StatusCode><RequestId>a901d3ec-24b6-4125-9345-36f01cd82021</RequestId></ResponseStatus></ReceiveMessageResponse>" )
|
261
430
|
assert_equal 'you are silly person', d.message_body( :receive )
|
262
431
|
assert_equal '0C2GG4PAQACB5REHPA7W|3H4AA8J7EJKM0DQZR7E1|9CBMKVD6TTQX44QJ1S30', d.message_id( :receive )
|
263
432
|
assert_equal 'Success', d.status
|
264
433
|
assert_equal 'a901d3ec-24b6-4125-9345-36f01cd82021', d.request_id
|
265
434
|
|
266
435
|
|
267
|
-
d = Document.new( "<?xml version='1.0'?><ReceiveMessageResponse xmlns='http://queue.amazonaws.com/doc/2006-04-01/'><Message><MessageId>0C2GG4PAQACB5REHPA7W|3H4AA8J7EJKM0DQZR7E1|9CBMKVD6TTQX44QJ1S30</MessageId><MessageBody>you are silly person</MessageBody></Message><Message><MessageId>12ZJQSDVXE728WJBXACC|3H4AA8J7EJKM0DQZR7E1|9CBMKVD6TTQX44QJ1S30</MessageId><MessageBody>whatever</MessageBody></Message><Message><MessageId>15YJSSXZ2R5XB0T1PXMY|3H4AA8J7EJKM0DQZR7E1|PT6DRTB278S4MNY77NJ0</MessageId><MessageBody>whatever</MessageBody></Message><Message><MessageId>0BRPBSW05BB9Z6HXWV4J|3H4AA8J7EJKM0DQZR7E1|9CBMKVD6TTQX44QJ1S30</MessageId><MessageBody>whatever</MessageBody></Message><ResponseStatus><StatusCode>Success</StatusCode><RequestId>ebf56590-665f-4077-8820-953c6663d220</RequestId></ResponseStatus></ReceiveMessageResponse>" )
|
436
|
+
d = REXML::Document.new( "<?xml version='1.0'?><ReceiveMessageResponse xmlns='http://queue.amazonaws.com/doc/2006-04-01/'><Message><MessageId>0C2GG4PAQACB5REHPA7W|3H4AA8J7EJKM0DQZR7E1|9CBMKVD6TTQX44QJ1S30</MessageId><MessageBody>you are silly person</MessageBody></Message><Message><MessageId>12ZJQSDVXE728WJBXACC|3H4AA8J7EJKM0DQZR7E1|9CBMKVD6TTQX44QJ1S30</MessageId><MessageBody>whatever</MessageBody></Message><Message><MessageId>15YJSSXZ2R5XB0T1PXMY|3H4AA8J7EJKM0DQZR7E1|PT6DRTB278S4MNY77NJ0</MessageId><MessageBody>whatever</MessageBody></Message><Message><MessageId>0BRPBSW05BB9Z6HXWV4J|3H4AA8J7EJKM0DQZR7E1|9CBMKVD6TTQX44QJ1S30</MessageId><MessageBody>whatever</MessageBody></Message><ResponseStatus><StatusCode>Success</StatusCode><RequestId>ebf56590-665f-4077-8820-953c6663d220</RequestId></ResponseStatus></ReceiveMessageResponse>" )
|
268
437
|
assert d.messages.is_a?( Array )
|
269
438
|
d.messages.each do |m|
|
270
439
|
assert m.respond_to?( :message_id )
|
@@ -273,17 +442,17 @@ class SQSTest < Test::Unit::TestCase
|
|
273
442
|
assert_equal 'Success', d.status
|
274
443
|
assert_equal 'ebf56590-665f-4077-8820-953c6663d220', d.request_id
|
275
444
|
|
276
|
-
d = Document.new( "<?xml version='1.0'?><GetVisibilityTimeoutResponse xmlns='http://queue.amazonaws.com/doc/2006-04-01/'><VisibilityTimeout>30</VisibilityTimeout><ResponseStatus><StatusCode>Success</StatusCode><RequestId>410fa43f-56f8-4e48-8c37-fa2f488f84aa</RequestId></ResponseStatus></GetVisibilityTimeoutResponse>" )
|
445
|
+
d = REXML::Document.new( "<?xml version='1.0'?><GetVisibilityTimeoutResponse xmlns='http://queue.amazonaws.com/doc/2006-04-01/'><VisibilityTimeout>30</VisibilityTimeout><ResponseStatus><StatusCode>Success</StatusCode><RequestId>410fa43f-56f8-4e48-8c37-fa2f488f84aa</RequestId></ResponseStatus></GetVisibilityTimeoutResponse>" )
|
277
446
|
assert_equal 30, d.visibility_timeout
|
278
447
|
assert_equal 'Success', d.status
|
279
448
|
assert_equal '410fa43f-56f8-4e48-8c37-fa2f488f84aa', d.request_id
|
280
449
|
|
281
|
-
d = Document.new( "<?xml version='1.0'?><SetVisibilityTimeoutResponse xmlns='http://queue.amazonaws.com/doc/2006-04-01/'><ResponseStatus><StatusCode>Success</StatusCode><RequestId>26d8f4b9-a95a-4ead-85e0-a3c6ee642d64</RequestId></ResponseStatus></SetVisibilityTimeoutResponse>" )
|
450
|
+
d = REXML::Document.new( "<?xml version='1.0'?><SetVisibilityTimeoutResponse xmlns='http://queue.amazonaws.com/doc/2006-04-01/'><ResponseStatus><StatusCode>Success</StatusCode><RequestId>26d8f4b9-a95a-4ead-85e0-a3c6ee642d64</RequestId></ResponseStatus></SetVisibilityTimeoutResponse>" )
|
282
451
|
assert_equal 'Success', d.status
|
283
452
|
assert_equal '26d8f4b9-a95a-4ead-85e0-a3c6ee642d64', d.request_id
|
284
453
|
|
285
454
|
|
286
|
-
d = Document.new( "<?xml version='1.0'?><ListGrantsResponse xmlns='http://access.amazonaws.com/doc/2006-01-01/'><GrantList><Grantee xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:type='CanonicalUser'><ID>2a3fad33685601e436445b8d283589b9d5ccd89a50da8fa91c664f2531ea5c71</ID><DisplayName>wzph</DisplayName></Grantee><Permission>FULLCONTROL</Permission></GrantList><ResponseStatus><StatusCode>Success</StatusCode></ResponseStatus></ListGrantsResponse>" )
|
455
|
+
d = REXML::Document.new( "<?xml version='1.0'?><ListGrantsResponse xmlns='http://access.amazonaws.com/doc/2006-01-01/'><GrantList><Grantee xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:type='CanonicalUser'><ID>2a3fad33685601e436445b8d283589b9d5ccd89a50da8fa91c664f2531ea5c71</ID><DisplayName>wzph</DisplayName></Grantee><Permission>FULLCONTROL</Permission></GrantList><ResponseStatus><StatusCode>Success</StatusCode></ResponseStatus></ListGrantsResponse>" )
|
287
456
|
assert d.grant_lists.is_a?( Array )
|
288
457
|
assert_equal 1, d.grant_lists.size
|
289
458
|
d.grant_lists.each do |list|
|
@@ -297,7 +466,7 @@ class SQSTest < Test::Unit::TestCase
|
|
297
466
|
end
|
298
467
|
assert_equal 'Success', d.status
|
299
468
|
|
300
|
-
d = Document.new( "<?xml version='1.0'?><ListGrantsResponse xmlns='http://access.amazonaws.com/doc/2006-01-01/'><GrantList><Grantee xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:type='CanonicalUser'><ID>fde39a46472f20295511ed16510c2ff352e5d0cc0060e1aa3edfa77cbc6412bf</ID><DisplayName>lance3515</DisplayName></Grantee><Permission>RECEIVEMESSAGE</Permission></GrantList><GrantList><Grantee xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:type='CanonicalUser'><ID>2a3fad33685601e436445b8d283589b9d5ccd89a50da8fa91c664f2531ea5c71</ID><DisplayName>wzph</DisplayName></Grantee><Permission>FULLCONTROL</Permission></GrantList><ResponseStatus><StatusCode>Success</StatusCode></ResponseStatus></ListGrantsResponse>" )
|
469
|
+
d = REXML::Document.new( "<?xml version='1.0'?><ListGrantsResponse xmlns='http://access.amazonaws.com/doc/2006-01-01/'><GrantList><Grantee xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:type='CanonicalUser'><ID>fde39a46472f20295511ed16510c2ff352e5d0cc0060e1aa3edfa77cbc6412bf</ID><DisplayName>lance3515</DisplayName></Grantee><Permission>RECEIVEMESSAGE</Permission></GrantList><GrantList><Grantee xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:type='CanonicalUser'><ID>2a3fad33685601e436445b8d283589b9d5ccd89a50da8fa91c664f2531ea5c71</ID><DisplayName>wzph</DisplayName></Grantee><Permission>FULLCONTROL</Permission></GrantList><ResponseStatus><StatusCode>Success</StatusCode></ResponseStatus></ListGrantsResponse>" )
|
301
470
|
assert d.grant_lists.is_a?( Array )
|
302
471
|
assert_equal 2, d.grant_lists.size
|
303
472
|
d.grant_lists.each do |list|
|
@@ -312,10 +481,10 @@ class SQSTest < Test::Unit::TestCase
|
|
312
481
|
assert_equal 'Success', d.status
|
313
482
|
|
314
483
|
|
315
|
-
d = Document.new( "<?xml version='1.0'?><AddGrantResponse xmlns='http://access.amazonaws.com/doc/2006-01-01/'><ResponseStatus><StatusCode>Success</StatusCode></ResponseStatus></AddGrantResponse>" )
|
484
|
+
d = REXML::Document.new( "<?xml version='1.0'?><AddGrantResponse xmlns='http://access.amazonaws.com/doc/2006-01-01/'><ResponseStatus><StatusCode>Success</StatusCode></ResponseStatus></AddGrantResponse>" )
|
316
485
|
assert_equal 'Success', d.status
|
317
486
|
|
318
|
-
d = Document.new( "<?xml version='1.0'?><GetQueueAttributesResponse xmlns='http://queue.amazonaws.com/doc/2007-05-01/'><AttributedValue><Attribute>VisibilityTimeout</Attribute><Value>30</Value></AttributedValue><AttributedValue><Attribute>ApproximateNumberOfMessages</Attribute><Value>0</Value></AttributedValue><ResponseStatus><StatusCode>Success</StatusCode><RequestId>00ae54e4-0dc9-4835-bc2e-36304ff40506</RequestId></ResponseStatus></GetQueueAttributesResponse>" )
|
487
|
+
d = REXML::Document.new( "<?xml version='1.0'?><GetQueueAttributesResponse xmlns='http://queue.amazonaws.com/doc/2007-05-01/'><AttributedValue><Attribute>VisibilityTimeout</Attribute><Value>30</Value></AttributedValue><AttributedValue><Attribute>ApproximateNumberOfMessages</Attribute><Value>0</Value></AttributedValue><ResponseStatus><StatusCode>Success</StatusCode><RequestId>00ae54e4-0dc9-4835-bc2e-36304ff40506</RequestId></ResponseStatus></GetQueueAttributesResponse>" )
|
319
488
|
assert d.attributed_values.is_a?( Array )
|
320
489
|
assert_equal 2, d.attributed_values.size
|
321
490
|
# d.attributed_values.each do |att|
|
@@ -323,6 +492,15 @@ class SQSTest < Test::Unit::TestCase
|
|
323
492
|
# end
|
324
493
|
assert_equal 'Success', d.status
|
325
494
|
|
495
|
+
|
496
|
+
|
497
|
+
d = REXML::Document.new( "<?xml version='1.0'?><ListQueuesResponse xmlns='http://queue.amazonaws.com/doc/2007-05-01/'><QueueUrl>http://queue.amazonaws.com/A3ZVJ8HH1F466/testSQS</QueueUrl><ResponseStatus><StatusCode>Success</StatusCode><RequestId>fd2d47e4-2cac-4047-94f2-e220d995835b</RequestId></ResponseStatus></ListQueuesResponse>" )
|
498
|
+
assert_nothing_raised do
|
499
|
+
d.status
|
500
|
+
end
|
501
|
+
assert_equal 'Success', d.status
|
502
|
+
assert_equal '', d.error_code
|
503
|
+
|
326
504
|
end
|
327
505
|
|
328
506
|
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: SQS
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.1.
|
7
|
-
date: 2007-
|
6
|
+
version: 0.1.5
|
7
|
+
date: 2007-07-18 00:00:00 -07:00
|
8
8
|
summary: A Ruby interface to Amazon's Simple Queue Service
|
9
9
|
require_paths:
|
10
10
|
- lib
|