SQS 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +23 -0
- data/lib/sqs.rb +11 -3
- data/lib/sqs/queue.rb +67 -36
- data/test/unit/sqs_grant_test.rb +1 -1
- data/test/unit/sqs_message_test.rb +1 -1
- data/test/unit/sqs_queue_test.rb +187 -29
- data/test/unit/sqs_test.rb +22 -2
- metadata +2 -2
data/CHANGELOG
CHANGED
@@ -1,3 +1,26 @@
|
|
1
|
+
0.1.4
|
2
|
+
2007-06-12
|
3
|
+
* Upped the API version to 2007-05-01
|
4
|
+
* Queue#force_delete is deprecated. Please use Queue#delete!. Queue#force_delete
|
5
|
+
is not guaranteed to be available after SQS v0.1.4
|
6
|
+
* Added Queue#get_queue_attributes and Queue#set_queue_attributes, and syntactic sugar
|
7
|
+
Queue#approximate_number_of_messages, Queue#visibility_timeout, and Queue#visibility_timeout=
|
8
|
+
Note that these three sugar methods aren't really methods, but are handled in Queue#method_missing
|
9
|
+
Note that these changes do not change the invocation of visibility_timeout or visibility_timeout=
|
10
|
+
* Added Queue#empty?, which calls self.peek, not self.approximate_number_of_messages, which should
|
11
|
+
mean that the result is accurate.
|
12
|
+
* Looks like Amazon fixed
|
13
|
+
http://developer.amazonwebservices.com/connect/thread.jspa?threadID=15364&tstart=0
|
14
|
+
* Added a small test for SQS.call_web_service
|
15
|
+
* Added a test to check for valid queue names
|
16
|
+
* Test messages up to 6000 bytes in length--this will require further work, since it's erroring out on my machine, before I even get to the supported 8K message size.
|
17
|
+
* Added Queue#each_message
|
18
|
+
NOTE that Queue#each_message is an infinite loop! You must either break out of it, or delete each
|
19
|
+
message as it comes.
|
20
|
+
* NOTE
|
21
|
+
http://developer.amazonwebservices.com/connect/thread.jspa?threadID=15618&tstart=0
|
22
|
+
Is unresolved
|
23
|
+
|
1
24
|
0.1.3
|
2
25
|
2007-04-25
|
3
26
|
* Missed one "include REXML."
|
data/lib/sqs.rb
CHANGED
@@ -135,7 +135,7 @@ class SQS
|
|
135
135
|
|
136
136
|
|
137
137
|
def self.api_version
|
138
|
-
'
|
138
|
+
'2007-05-01'
|
139
139
|
end
|
140
140
|
|
141
141
|
def self.signature_version
|
@@ -193,8 +193,12 @@ class SQS
|
|
193
193
|
retries = self.retry_attempts
|
194
194
|
end
|
195
195
|
|
196
|
-
if !params[:queue].nil?
|
197
|
-
|
196
|
+
if !params[:queue].nil?
|
197
|
+
if params[:queue].respond_to?( :url )
|
198
|
+
url = params[:queue].url
|
199
|
+
else
|
200
|
+
url = params[:queue].to_s
|
201
|
+
end
|
198
202
|
params.delete( :queue )
|
199
203
|
else
|
200
204
|
url = "#{self.url_for_query}"
|
@@ -248,6 +252,7 @@ module REXML
|
|
248
252
|
def message_body( type=:peek ) ; self.node_text( "/#{type.to_s.capitalize}MessageResponse/Message/MessageBody" ) ; end
|
249
253
|
|
250
254
|
def messages( type=:receive ) ; self.nodes( "/#{type.to_s.capitalize}MessageResponse#{ type == :send ? '' : '/Message'}" ) ; end
|
255
|
+
def attributed_values( type=:get ) ; self.nodes( "/#{type.to_s.capitalize}QueueAttributesResponse#{ type == :send ? '' : '/AttributedValue'}" ) ; end
|
251
256
|
|
252
257
|
def visibility_timeout( type=:get ) ; self.node_text( "/#{type.to_s.capitalize}VisibilityTimeoutResponse/VisibilityTimeout" ).to_i ; end
|
253
258
|
|
@@ -269,6 +274,9 @@ module REXML
|
|
269
274
|
def message_id ; self.node_text( "MessageId" ) ; end
|
270
275
|
def message_body ; self.node_text( "MessageBody" ) ; end
|
271
276
|
|
277
|
+
def attribute ; self.node_text( "Attribute" ) ; end
|
278
|
+
def value ; self.node_text( "Value" ) ; end
|
279
|
+
|
272
280
|
def id( type=:message ) ; self.node_text( type == :grantee ? "ID" : "Id" ) ; end
|
273
281
|
def display_name ; self.node_text( "DisplayName" ) ; end
|
274
282
|
def permission ; self.node_text( "Permission" ) ; end
|
data/lib/sqs/queue.rb
CHANGED
@@ -5,15 +5,14 @@ require 'rexml/document'
|
|
5
5
|
|
6
6
|
class SQS::Queue
|
7
7
|
private
|
8
|
-
@attributes = {}
|
9
8
|
@@acceptable_schemes = ['https', 'http']
|
10
9
|
|
11
10
|
public
|
12
|
-
attr_accessor :url
|
11
|
+
attr_accessor :url, :attributes
|
13
12
|
def initialize( options={} )
|
14
13
|
self.url = options.is_a?( Hash ) ? options[:url] : options
|
15
14
|
bad_url = false
|
16
|
-
|
15
|
+
self.attributes = {}
|
17
16
|
begin
|
18
17
|
u = URI.parse( self.url )
|
19
18
|
bad_url = !@@acceptable_schemes.include?( u.scheme ) || u.host.to_s.empty? || u.path.to_s.empty?
|
@@ -23,6 +22,22 @@ class SQS::Queue
|
|
23
22
|
raise "'#{self.url}' does not seem to be a parseable URL. (Please provide all parts of the URL.)" if bad_url
|
24
23
|
end
|
25
24
|
|
25
|
+
def method_missing( symbol, *args )
|
26
|
+
#method_missing intercepts .attribute and .attribute= calls
|
27
|
+
method_name = symbol.to_s
|
28
|
+
|
29
|
+
if method_name =~ /(.*)=$/
|
30
|
+
attribute_name = $1.capitalize.gsub( /_([^_])/ ) { |m| $1.capitalize }.to_sym
|
31
|
+
raise NoMethodError, "#{self.class.name}.#{method_name} takes one parameter" unless args.size == 1
|
32
|
+
self.set_queue_attributes( attribute_name => args[0] )
|
33
|
+
else
|
34
|
+
attribute_name = method_name.capitalize.gsub( /_([^_])/ ) { |m| $1.capitalize }.to_sym
|
35
|
+
self.get_queue_attributes( true ) if args[0] || @attributes.empty?
|
36
|
+
raise NoMethodError, "This #{self.class.name} does not respond to #{method_name}" unless @attributes[attribute_name]
|
37
|
+
@attributes[attribute_name]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
26
41
|
def ==( other_queue )
|
27
42
|
self.url == other_queue.url
|
28
43
|
rescue
|
@@ -33,28 +48,37 @@ class SQS::Queue
|
|
33
48
|
"#{self.class.to_s} '#{self.name}' (#{self.url})"
|
34
49
|
end
|
35
50
|
|
36
|
-
def delete
|
37
|
-
|
51
|
+
def delete( options=nil )
|
52
|
+
force = options.is_a?( Hash ) && options[:force]
|
53
|
+
doc = SQS.call_web_service( :Action => 'DeleteQueue', :ForceDeletion => force, :queue => self )
|
38
54
|
true
|
39
55
|
rescue Exception => e
|
40
56
|
raise e
|
41
57
|
end
|
42
58
|
|
59
|
+
def delete!
|
60
|
+
delete( :force => true )
|
61
|
+
end
|
43
62
|
def force_delete
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
63
|
+
warn "Queue#force_delete is deprecated. Please use Queue#delete!."
|
64
|
+
delete!
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
def send_message( m )
|
69
|
+
doc = SQS.call_web_service( :Action => 'SendMessage', :queue => self, :MessageBody => m.to_s )
|
70
|
+
m = SQS::Message.new( :id => doc.message_id, :queue => self )
|
71
|
+
rescue Exception => e
|
72
|
+
raise e
|
73
|
+
end
|
74
|
+
|
75
|
+
def get_queue_attributes( force=false )
|
76
|
+
if force || @attributes.empty?
|
77
|
+
params = { :Action => 'GetQueueAttributes', :queue => self, :Attribute => 'All' }
|
78
|
+
doc = SQS.call_web_service( params )
|
79
|
+
|
80
|
+
doc.attributed_values.each do |v|
|
81
|
+
@attributes[ v.attribute.to_sym ] = (v.value == v.value.to_i.to_s ? v.value.to_i : v.value )
|
58
82
|
end
|
59
83
|
end
|
60
84
|
true
|
@@ -62,14 +86,25 @@ class SQS::Queue
|
|
62
86
|
raise e
|
63
87
|
end
|
64
88
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
89
|
+
def set_queue_attributes( atts={} )
|
90
|
+
@attributes = {} unless @attributes
|
91
|
+
params = { :Action => 'SetQueueAttributes', :queue => self.url }
|
92
|
+
atts.each do |k,v|
|
93
|
+
params[:Attribute] = k
|
94
|
+
params[:Value] = v
|
95
|
+
doc = SQS.call_web_service( params )
|
96
|
+
@attributes[k] = v
|
97
|
+
end
|
98
|
+
true
|
69
99
|
rescue Exception => e
|
70
100
|
raise e
|
71
101
|
end
|
72
102
|
|
103
|
+
def empty?
|
104
|
+
self.peek_message.nil?
|
105
|
+
end
|
106
|
+
|
107
|
+
|
73
108
|
def peek_message
|
74
109
|
# returns the first element of what peek_messages returns
|
75
110
|
m = self.peek_messages( :count => 1 ).first
|
@@ -103,19 +138,6 @@ class SQS::Queue
|
|
103
138
|
raise e
|
104
139
|
end
|
105
140
|
|
106
|
-
def visibility_timeout=( timeout )
|
107
|
-
doc = SQS.call_web_service( :Action => 'SetVisibilityTimeout', :queue => self, :VisibilityTimeout => timeout.to_i )
|
108
|
-
true
|
109
|
-
rescue Exception => e
|
110
|
-
raise e
|
111
|
-
end
|
112
|
-
def visibility_timeout
|
113
|
-
doc = SQS.call_web_service( :Action => 'GetVisibilityTimeout', :queue => self )
|
114
|
-
doc.visibility_timeout.to_i
|
115
|
-
rescue Exception => e
|
116
|
-
raise e
|
117
|
-
end
|
118
|
-
|
119
141
|
|
120
142
|
|
121
143
|
def add_grant( options={} )
|
@@ -170,6 +192,15 @@ class SQS::Queue
|
|
170
192
|
end
|
171
193
|
end
|
172
194
|
|
195
|
+
def each_message( &block )
|
196
|
+
# This is an infinite loop.
|
197
|
+
# You must either break out of it
|
198
|
+
# Or delete each message!
|
199
|
+
while m = self.peek_message
|
200
|
+
block.call( m )
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
173
204
|
def name
|
174
205
|
# return everything after the last slash
|
175
206
|
self.url =~ /([^\/]*)$/ ? $1 : ''
|
data/test/unit/sqs_grant_test.rb
CHANGED
@@ -10,7 +10,7 @@ class SQS_GrantTest < Test::Unit::TestCase
|
|
10
10
|
@q = SQS.create_queue( @queue_prefix ) unless SQStest.skip_live_tests?
|
11
11
|
end
|
12
12
|
def teardown
|
13
|
-
SQS.list_queues( @queue_prefix ).each { |q| q.
|
13
|
+
SQS.list_queues( @queue_prefix ).each { |q| q.delete! } unless SQStest.skip_live_tests?
|
14
14
|
print SQS.counter if SQStest.print_counter?
|
15
15
|
end
|
16
16
|
|
@@ -11,7 +11,7 @@ class SQS_MessageTest < Test::Unit::TestCase
|
|
11
11
|
@q = SQS.create_queue( @queue_prefix ) unless SQStest.skip_live_tests?
|
12
12
|
end
|
13
13
|
def teardown
|
14
|
-
SQS.list_queues( @queue_prefix ).each { |q| q.
|
14
|
+
SQS.list_queues( @queue_prefix ).each { |q| q.delete! } unless SQStest.skip_live_tests?
|
15
15
|
print SQS.counter if SQStest.print_counter?
|
16
16
|
end
|
17
17
|
|
data/test/unit/sqs_queue_test.rb
CHANGED
@@ -13,11 +13,11 @@ class SQS_QueueTest < Test::Unit::TestCase
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def setup
|
16
|
-
@queue_prefix = '
|
16
|
+
@queue_prefix = 'test_queue_'
|
17
17
|
@q = SQStest.skip_live_tests? ? SQS::Queue.new( 'http://nowhere.com/nothing' ) : SQS.create_queue( @queue_prefix )
|
18
18
|
end
|
19
19
|
def teardown
|
20
|
-
SQS.list_queues( @queue_prefix ).each { |q| q.
|
20
|
+
SQS.list_queues( @queue_prefix ).each { |q| q.delete! } unless SQStest.skip_live_tests?
|
21
21
|
print SQS.counter if SQStest.print_counter?
|
22
22
|
end
|
23
23
|
|
@@ -37,6 +37,53 @@ class SQS_QueueTest < Test::Unit::TestCase
|
|
37
37
|
assert_raises RuntimeError do
|
38
38
|
q2.delete
|
39
39
|
end
|
40
|
+
|
41
|
+
q = SQS.create_queue :name => "#{@queue_prefix}test_delete"
|
42
|
+
q.send_message( 'A' )
|
43
|
+
q.send_message( 'B' )
|
44
|
+
assert_raises RuntimeError do
|
45
|
+
q.delete
|
46
|
+
end
|
47
|
+
assert_nothing_raised do
|
48
|
+
q.delete( :force => true )
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_delete!
|
53
|
+
@q.send_message( 'A' )
|
54
|
+
@q.send_message( 'B' )
|
55
|
+
assert_raises RuntimeError do
|
56
|
+
@q.delete
|
57
|
+
end
|
58
|
+
assert_nothing_raised do
|
59
|
+
@q.delete!
|
60
|
+
end
|
61
|
+
|
62
|
+
assert_raises RuntimeError do
|
63
|
+
q = SQS.get_queue( @queue_prefix )
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_force_delete
|
68
|
+
(1..10).to_a.each do |i|
|
69
|
+
@q.send_message( "I am receiving message ##{i}" )
|
70
|
+
end
|
71
|
+
|
72
|
+
sleep 5
|
73
|
+
|
74
|
+
assert_raises RuntimeError do
|
75
|
+
@q.delete
|
76
|
+
end
|
77
|
+
|
78
|
+
assert_nothing_raised do
|
79
|
+
@q.force_delete
|
80
|
+
end
|
81
|
+
|
82
|
+
sleep 5
|
83
|
+
|
84
|
+
assert_raises RuntimeError do
|
85
|
+
q = SQS.get_queue( @queue_prefix )
|
86
|
+
end
|
40
87
|
end
|
41
88
|
|
42
89
|
def test_exist
|
@@ -64,6 +111,102 @@ class SQS_QueueTest < Test::Unit::TestCase
|
|
64
111
|
assert m.is_a?( SQS::Message )
|
65
112
|
assert_equal @q, m.queue
|
66
113
|
end
|
114
|
+
|
115
|
+
def test_send_big_message
|
116
|
+
message = ''
|
117
|
+
6000.times do
|
118
|
+
message << 'x'
|
119
|
+
end
|
120
|
+
assert @q.send_message( message )
|
121
|
+
#Note that this is as big as I can reliably get right now
|
122
|
+
#Need to do some debugging, because I keep getting EOFErrors
|
123
|
+
#when I submit a message of size 7867 (roughly) or above
|
124
|
+
#
|
125
|
+
#Also, the Amazon API allows you to post a body to a URL
|
126
|
+
# with query parameters in it, to send a message up to 256K
|
127
|
+
# in length. Something to consider.
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_get_and_set_queue_attributes
|
131
|
+
assert @q.attributes.empty?
|
132
|
+
assert @q.get_queue_attributes
|
133
|
+
assert !@q.attributes.empty?
|
134
|
+
assert_equal 0, @q.attributes[:ApproximateNumberOfMessages]
|
135
|
+
assert_equal 30, @q.attributes[:VisibilityTimeout]
|
136
|
+
|
137
|
+
assert @q.set_queue_attributes( :VisibilityTimeout => 400 )
|
138
|
+
assert_equal 400, @q.attributes[:VisibilityTimeout]
|
139
|
+
assert_equal 0, @q.attributes[:ApproximateNumberOfMessages]
|
140
|
+
assert_nothing_raised do
|
141
|
+
@q.get_queue_attributes( true )
|
142
|
+
end
|
143
|
+
assert_equal 400, @q.attributes[:VisibilityTimeout]
|
144
|
+
assert_equal 0, @q.attributes[:ApproximateNumberOfMessages]
|
145
|
+
|
146
|
+
|
147
|
+
assert_nothing_raised do
|
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
|
150
|
+
@q.set_queue_attributes( :SHOULDBEANERROR => 'crazy!' )
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
|
155
|
+
def test_no_such_method
|
156
|
+
assert_raises NoMethodError do
|
157
|
+
@q.no_such_method
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_approximate_number_of_messages
|
162
|
+
assert_nothing_raised do
|
163
|
+
@q.approximate_number_of_messages
|
164
|
+
end
|
165
|
+
assert_equal 0, @q.approximate_number_of_messages
|
166
|
+
|
167
|
+
1.upto( 25 ) do |i|
|
168
|
+
@q.send_message( "sending message #{i}" )
|
169
|
+
end
|
170
|
+
|
171
|
+
assert_equal 0, @q.approximate_number_of_messages
|
172
|
+
assert_in_delta 25, @q.approximate_number_of_messages( true ), 3
|
173
|
+
end
|
174
|
+
|
175
|
+
|
176
|
+
def test_visibility_timeout
|
177
|
+
assert_nothing_raised do
|
178
|
+
@q.visibility_timeout
|
179
|
+
end
|
180
|
+
assert_equal 30, @q.visibility_timeout
|
181
|
+
|
182
|
+
assert_nothing_raised do
|
183
|
+
@q.visibility_timeout = 500
|
184
|
+
end
|
185
|
+
|
186
|
+
# Update happens in situ
|
187
|
+
assert_equal 500, @q.visibility_timeout
|
188
|
+
assert_equal 500, @q.visibility_timeout( true )
|
189
|
+
end
|
190
|
+
|
191
|
+
def test_empty?
|
192
|
+
assert @q.empty?
|
193
|
+
|
194
|
+
@q.send_message( 'no longer empty' )
|
195
|
+
sleep 2
|
196
|
+
assert !@q.empty?
|
197
|
+
|
198
|
+
@q.send_message( 'no longer empty again' )
|
199
|
+
|
200
|
+
assert !@q.empty?
|
201
|
+
|
202
|
+
messages = @q.receive_messages
|
203
|
+
messages.each do |m|
|
204
|
+
m.delete
|
205
|
+
end
|
206
|
+
|
207
|
+
assert @q.empty?
|
208
|
+
end
|
209
|
+
|
67
210
|
|
68
211
|
def test_peek_message
|
69
212
|
@q.send_message( 'I am receiving a message from beyond' )
|
@@ -152,27 +295,6 @@ class SQS_QueueTest < Test::Unit::TestCase
|
|
152
295
|
assert messages.size > 0 && messages.size < 12, "Weird array size: #{messages.size}"
|
153
296
|
end
|
154
297
|
|
155
|
-
def test_force_delete
|
156
|
-
(1..10).to_a.each do |i|
|
157
|
-
@q.send_message( "I am receiving message ##{i}" )
|
158
|
-
end
|
159
|
-
|
160
|
-
sleep 5
|
161
|
-
|
162
|
-
assert_raises RuntimeError do
|
163
|
-
@q.delete
|
164
|
-
end
|
165
|
-
|
166
|
-
assert_nothing_raised do
|
167
|
-
@q.force_delete
|
168
|
-
end
|
169
|
-
|
170
|
-
sleep 5
|
171
|
-
|
172
|
-
assert_raises RuntimeError do
|
173
|
-
q = SQS.get_queue( @queue_prefix )
|
174
|
-
end
|
175
|
-
end
|
176
298
|
|
177
299
|
class DUMMY
|
178
300
|
def self.email
|
@@ -269,6 +391,23 @@ class SQS_QueueTest < Test::Unit::TestCase
|
|
269
391
|
end
|
270
392
|
end
|
271
393
|
|
394
|
+
|
395
|
+
def test_each_message
|
396
|
+
assert_respond_to @q, :each_message
|
397
|
+
1.upto( 10 ) do |i|
|
398
|
+
@q.send_message( "message #{i}" )
|
399
|
+
end
|
400
|
+
|
401
|
+
i = 0
|
402
|
+
@q.each_message do |m|
|
403
|
+
i += 1
|
404
|
+
assert_equal SQS::Message, m.class
|
405
|
+
m.delete
|
406
|
+
end
|
407
|
+
assert_equal 10, i
|
408
|
+
end
|
409
|
+
|
410
|
+
|
272
411
|
def test_each_grant
|
273
412
|
assert_respond_to @q, :each_grant
|
274
413
|
@q.add_grant( :email => SQStest.other_aws_account[:email], :permission => :receive)
|
@@ -278,7 +417,6 @@ class SQS_QueueTest < Test::Unit::TestCase
|
|
278
417
|
end
|
279
418
|
|
280
419
|
def test_get_visiblity_timeout
|
281
|
-
assert_respond_to @q, :visibility_timeout
|
282
420
|
assert_equal SQS::Queue.default_visibility_timeout, @q.visibility_timeout
|
283
421
|
assert_kind_of Integer, @q.visibility_timeout
|
284
422
|
|
@@ -288,12 +426,14 @@ class SQS_QueueTest < Test::Unit::TestCase
|
|
288
426
|
end
|
289
427
|
|
290
428
|
def test_set_visiblity_timeout
|
291
|
-
assert_respond_to @q, :visibility_timeout=
|
292
429
|
assert( @q.visibility_timeout = 456 )
|
293
430
|
assert_equal 456, @q.visibility_timeout
|
294
431
|
|
295
|
-
|
432
|
+
assert_raises RuntimeError do
|
296
433
|
@q.visibility_timeout = nil
|
434
|
+
end
|
435
|
+
|
436
|
+
assert_nothing_raised do
|
297
437
|
@q.visibility_timeout = 0
|
298
438
|
end
|
299
439
|
|
@@ -304,10 +444,26 @@ class SQS_QueueTest < Test::Unit::TestCase
|
|
304
444
|
@q.visibility_timeout = 86401
|
305
445
|
end
|
306
446
|
|
307
|
-
assert_raises
|
447
|
+
assert_raises RuntimeError do
|
308
448
|
@q.visibility_timeout = Object
|
309
449
|
end
|
310
450
|
end
|
451
|
+
|
452
|
+
|
453
|
+
def test_legal_names
|
454
|
+
assert !SQS.create_queue( '' )
|
455
|
+
assert_raises RuntimeError do
|
456
|
+
SQS.create_queue( '81characterslongxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' )
|
457
|
+
end
|
458
|
+
assert q = SQS.create_queue( '80characterslongxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' )
|
459
|
+
q.delete
|
460
|
+
|
461
|
+
acceptable_names = [ '-', '_', '0', 's' ]
|
462
|
+
acceptable_names.each do |name|
|
463
|
+
assert q = SQS.create_queue( name )
|
464
|
+
q.delete
|
465
|
+
end
|
466
|
+
end
|
311
467
|
end
|
312
468
|
|
313
469
|
def test_default_visibility_timeout
|
@@ -319,13 +475,15 @@ class SQS_QueueTest < Test::Unit::TestCase
|
|
319
475
|
|
320
476
|
def test_new
|
321
477
|
assert_nothing_raised do
|
322
|
-
q1 = SQS::Queue.new :url => 'http://www.slappy.com/', :a => 'a', 'b' => :b
|
478
|
+
q1 = SQS::Queue.new( :url => 'http://www.slappy.com/', :a => 'a', 'b' => :b )
|
323
479
|
end
|
324
|
-
q1 = SQS::Queue.new :url => 'http://www.slappy.com/', :a => 'a', 'b' => :b
|
480
|
+
q1 = SQS::Queue.new( :url => 'http://www.slappy.com/', :a => 'a', 'b' => :b )
|
325
481
|
assert_equal 'http://www.slappy.com/', q1.url
|
482
|
+
assert_equal( {}, q1.attributes )
|
326
483
|
|
327
484
|
q2 = SQS::Queue.new 'http://www.slappy.com/'
|
328
485
|
assert_equal 'http://www.slappy.com/', q2.url
|
486
|
+
assert_equal( {}, q2.attributes )
|
329
487
|
|
330
488
|
assert_raises NameError do
|
331
489
|
q.a
|
data/test/unit/sqs_test.rb
CHANGED
@@ -22,7 +22,7 @@ class SQSTest < Test::Unit::TestCase
|
|
22
22
|
@q = SQS.create_queue( @queue_prefix ) unless SQStest.skip_live_tests?
|
23
23
|
end
|
24
24
|
def teardown
|
25
|
-
SQS.list_queues( @queue_prefix ).each { |q| q.
|
25
|
+
SQS.list_queues( @queue_prefix ).each { |q| q.delete! } unless SQStest.skip_live_tests?
|
26
26
|
print SQS.counter if SQStest.print_counter?
|
27
27
|
end
|
28
28
|
|
@@ -83,6 +83,17 @@ class SQSTest < Test::Unit::TestCase
|
|
83
83
|
assert_kind_of( SQS::Queue, q )
|
84
84
|
end
|
85
85
|
|
86
|
+
def test_call_web_service
|
87
|
+
assert_raises RuntimeError do
|
88
|
+
SQS.call_web_service( :Something => 'for nothing' )
|
89
|
+
end
|
90
|
+
|
91
|
+
x = nil
|
92
|
+
assert_nothing_raised do
|
93
|
+
x = SQS.call_web_service( :Action => 'ListQueues' )
|
94
|
+
end
|
95
|
+
assert_equal REXML::Document, x.class
|
96
|
+
end
|
86
97
|
end
|
87
98
|
|
88
99
|
def test_counter
|
@@ -146,7 +157,7 @@ class SQSTest < Test::Unit::TestCase
|
|
146
157
|
|
147
158
|
def test_api_version
|
148
159
|
assert_respond_to SQS, :api_version
|
149
|
-
assert_equal '
|
160
|
+
assert_equal '2007-05-01', SQS.api_version
|
150
161
|
end
|
151
162
|
|
152
163
|
|
@@ -303,9 +314,18 @@ class SQSTest < Test::Unit::TestCase
|
|
303
314
|
|
304
315
|
d = Document.new( "<?xml version='1.0'?><AddGrantResponse xmlns='http://access.amazonaws.com/doc/2006-01-01/'><ResponseStatus><StatusCode>Success</StatusCode></ResponseStatus></AddGrantResponse>" )
|
305
316
|
assert_equal 'Success', d.status
|
317
|
+
|
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>" )
|
319
|
+
assert d.attributed_values.is_a?( Array )
|
320
|
+
assert_equal 2, d.attributed_values.size
|
321
|
+
# d.attributed_values.each do |att|
|
322
|
+
# puts att
|
323
|
+
# end
|
324
|
+
assert_equal 'Success', d.status
|
306
325
|
|
307
326
|
end
|
308
327
|
|
328
|
+
|
309
329
|
def test_permissions
|
310
330
|
assert_equal 'RECEIVEMESSAGE', SQS.permissions[:receive]
|
311
331
|
assert_equal 'SENDMESSAGE', SQS.permissions[:send]
|
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.4
|
7
|
+
date: 2007-06-12 00:00:00 -07:00
|
8
8
|
summary: A Ruby interface to Amazon's Simple Queue Service
|
9
9
|
require_paths:
|
10
10
|
- lib
|