SQS 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README +3 -0
- data/lib/sqs.rb +294 -0
- data/lib/sqs/grant.rb +34 -0
- data/lib/sqs/message.rb +43 -0
- data/lib/sqs/queue.rb +179 -0
- data/test/all_tests.rb +6 -0
- data/test/unit/sqs_grant_test.rb +67 -0
- data/test/unit/sqs_message_test.rb +81 -0
- data/test/unit/sqs_queue_test.rb +312 -0
- data/test/unit/sqs_test.rb +341 -0
- data/test/unit/test_setup.rb +51 -0
- metadata +63 -0
data/test/all_tests.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
#!/usr/local/bin/ruby
|
2
|
+
dir = File.expand_path( File.dirname( __FILE__ ) )
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require "#{File.expand_path( File.dirname( __FILE__ ) )}/test_setup"
|
6
|
+
|
7
|
+
class SQS_GrantTest < Test::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
@queue_prefix = 'testGRANTEE'
|
10
|
+
@q = SQS.create_queue( @queue_prefix ) unless SQStest.skip_live_tests?
|
11
|
+
end
|
12
|
+
def teardown
|
13
|
+
SQS.list_queues( @queue_prefix ).each { |q| q.force_delete } unless SQStest.skip_live_tests?
|
14
|
+
print SQS.counter if SQStest.print_counter?
|
15
|
+
end
|
16
|
+
|
17
|
+
unless SQStest.skip_live_tests?
|
18
|
+
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
def test_initialize
|
24
|
+
g = SQS::Grant.new( :email => 'a@b.c', :id => '123456', :display_name => 'abc', :permission => 'zyx' )
|
25
|
+
assert_equal 'abc', g.display_name
|
26
|
+
assert_equal '123456', g.id
|
27
|
+
assert_equal 'a@b.c', g.email
|
28
|
+
assert_equal 'zyx', g.permission
|
29
|
+
|
30
|
+
g = SQS::Grant.new( 'iloveemail' )
|
31
|
+
assert_equal 'iloveemail', g.email
|
32
|
+
assert g.id.nil?
|
33
|
+
assert g.display_name.nil?
|
34
|
+
assert g.permission.nil?
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_permission
|
38
|
+
g = SQS::Grant.new
|
39
|
+
assert_equal nil, g.permission
|
40
|
+
|
41
|
+
g.permission = :full
|
42
|
+
assert_equal 'FULLCONTROL', g.permission
|
43
|
+
g.permission = :receive
|
44
|
+
assert_equal 'RECEIVEMESSAGE', g.permission
|
45
|
+
g.permission = :send
|
46
|
+
assert_equal 'SENDMESSAGE', g.permission
|
47
|
+
|
48
|
+
g.permission = 'fullcontrol'
|
49
|
+
assert_equal 'FULLCONTROL', g.permission
|
50
|
+
g.permission = 'receivemessage'
|
51
|
+
assert_equal 'RECEIVEMESSAGE', g.permission
|
52
|
+
g.permission = 'sendmessage'
|
53
|
+
assert_equal 'SENDMESSAGE', g.permission
|
54
|
+
|
55
|
+
g.permission = 'full'
|
56
|
+
assert_equal 'FULLCONTROL', g.permission
|
57
|
+
g.permission = 'receive'
|
58
|
+
assert_equal 'RECEIVEMESSAGE', g.permission
|
59
|
+
g.permission = 'send'
|
60
|
+
assert_equal 'SENDMESSAGE', g.permission
|
61
|
+
|
62
|
+
g.permission = 'somethingelse'
|
63
|
+
assert_equal 'SOMETHINGELSE', g.permission
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
|
@@ -0,0 +1,81 @@
|
|
1
|
+
#!/usr/local/bin/ruby
|
2
|
+
dir = File.expand_path( File::dirname( __FILE__ ) )
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require "#{File.expand_path( File.dirname( __FILE__ ) )}/test_setup"
|
6
|
+
|
7
|
+
|
8
|
+
class SQS_MessageTest < Test::Unit::TestCase
|
9
|
+
def setup
|
10
|
+
@queue_prefix = 'testMSG'
|
11
|
+
@q = SQS.create_queue( @queue_prefix ) unless SQStest.skip_live_tests?
|
12
|
+
end
|
13
|
+
def teardown
|
14
|
+
SQS.list_queues( @queue_prefix ).each { |q| q.force_delete } unless SQStest.skip_live_tests?
|
15
|
+
print SQS.counter if SQStest.print_counter?
|
16
|
+
end
|
17
|
+
|
18
|
+
unless SQStest.skip_live_tests?
|
19
|
+
def test_delete
|
20
|
+
m = @q.send_message( 'This is something special' )
|
21
|
+
assert m.is_a?( SQS::Message )
|
22
|
+
assert_equal @q, m.queue
|
23
|
+
assert m.delete
|
24
|
+
sleep 2
|
25
|
+
assert_raises RuntimeError do
|
26
|
+
m.peek
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_peek
|
31
|
+
m = @q.send_message( 'This is something else special' )
|
32
|
+
assert m.peek
|
33
|
+
assert_equal 'This is something else special', m.body
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_body
|
37
|
+
m = SQS::Message.new()
|
38
|
+
m.body = 'bob'
|
39
|
+
assert_equal 'bob', m.body
|
40
|
+
|
41
|
+
m = @q.send_message( 'This is something else really special' )
|
42
|
+
assert_equal 'This is something else really special', m.body
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_new
|
47
|
+
assert_nothing_raised RuntimeError do
|
48
|
+
SQS::Message.new
|
49
|
+
end
|
50
|
+
assert_nothing_raised RuntimeError do
|
51
|
+
SQS::Message.new :a => 'b'
|
52
|
+
end
|
53
|
+
assert_nothing_raised RuntimeError do
|
54
|
+
SQS::Message.new :a => 'b', :body => ''
|
55
|
+
end
|
56
|
+
|
57
|
+
assert_nothing_raised do
|
58
|
+
SQS::Message.new :a => 'b', :body => 'This is a test'
|
59
|
+
end
|
60
|
+
|
61
|
+
assert_nothing_raised do
|
62
|
+
SQS::Message.new 'This is a test'
|
63
|
+
end
|
64
|
+
|
65
|
+
m1 = SQS::Message.new :a => 'b', :body => 'This is a test'
|
66
|
+
assert m1.is_a?( SQS::Message )
|
67
|
+
|
68
|
+
m2 = SQS::Message.new 'This is a test'
|
69
|
+
assert m2.is_a?( SQS::Message )
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_id
|
73
|
+
m1 = SQS::Message.new 'Message 1'
|
74
|
+
m2 = SQS::Message.new :id => 'Message 2'
|
75
|
+
m3 = SQS::Message.new :id => 'Message 3', :something => 'else'
|
76
|
+
|
77
|
+
assert_equal 'Message 1', m1.id
|
78
|
+
assert_equal 'Message 2', m2.id
|
79
|
+
assert_equal 'Message 3', m3.id
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,312 @@
|
|
1
|
+
#!/usr/local/bin/ruby
|
2
|
+
dir = File.expand_path( File.dirname( __FILE__ ) )
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require "#{File.expand_path( File.dirname( __FILE__ ) )}/test_setup"
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
class SQS_QueueTest < Test::Unit::TestCase
|
11
|
+
def self.other_aws_account
|
12
|
+
SQStest.other_aws_account
|
13
|
+
end
|
14
|
+
|
15
|
+
def setup
|
16
|
+
@queue_prefix = 'testQUEUE'
|
17
|
+
@q = SQStest.skip_live_tests? ? SQS::Queue.new( 'http://nowhere.com/nothing' ) : SQS.create_queue( @queue_prefix )
|
18
|
+
end
|
19
|
+
def teardown
|
20
|
+
SQS.list_queues( @queue_prefix ).each { |q| q.force_delete } unless SQStest.skip_live_tests?
|
21
|
+
print SQS.counter if SQStest.print_counter?
|
22
|
+
end
|
23
|
+
|
24
|
+
unless SQStest.skip_live_tests?
|
25
|
+
def test_delete
|
26
|
+
assert @q.is_a?( SQS::Queue )
|
27
|
+
q2 = SQS.get_queue( @queue_prefix )
|
28
|
+
assert q2.is_a?( SQS::Queue )
|
29
|
+
assert_equal @q, q2
|
30
|
+
|
31
|
+
assert @q.delete
|
32
|
+
|
33
|
+
assert_raises RuntimeError do
|
34
|
+
q3 = SQS.get_queue( @queue_prefix )
|
35
|
+
end
|
36
|
+
|
37
|
+
assert_raises RuntimeError do
|
38
|
+
q2.delete
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_exist
|
43
|
+
assert @q.exist?
|
44
|
+
assert @q.exists?
|
45
|
+
q2 = SQS.get_queue( @queue_prefix )
|
46
|
+
assert q2.exists?
|
47
|
+
assert q2.exist?
|
48
|
+
|
49
|
+
assert @q.delete
|
50
|
+
sleep 2
|
51
|
+
|
52
|
+
assert !@q.exists?
|
53
|
+
assert !@q.exist?
|
54
|
+
assert !q2.exists?
|
55
|
+
assert !q2.exist?
|
56
|
+
|
57
|
+
q3 = SQS::Queue.new( 'http://borker.borked/borkee' )
|
58
|
+
assert !q3.exists?
|
59
|
+
assert !q3.exist?
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_send_message
|
63
|
+
m = @q.send_message( 'This is so mething special' )
|
64
|
+
assert m.is_a?( SQS::Message )
|
65
|
+
assert_equal @q, m.queue
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_receive_message
|
69
|
+
@q.send_message( 'I am receiving a message from beyond' )
|
70
|
+
sleep 2
|
71
|
+
m = @q.receive_message
|
72
|
+
|
73
|
+
assert m.is_a?( SQS::Message )
|
74
|
+
assert_equal @q, m.queue
|
75
|
+
assert_equal 'I am receiving a message from beyond', m.body
|
76
|
+
end
|
77
|
+
def test_receive_message_on_empty_queue
|
78
|
+
m = @q.receive_message
|
79
|
+
|
80
|
+
assert m.nil?
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_receive_messages
|
84
|
+
(1..10).to_a.each do |i|
|
85
|
+
@q.send_message( "I am receiving message #{i}" )
|
86
|
+
end
|
87
|
+
|
88
|
+
sleep 10
|
89
|
+
|
90
|
+
messages = @q.receive_messages :count => 2
|
91
|
+
assert messages.size == 1 || messages.size == 2, "Weird array size: #{messages.size}"
|
92
|
+
|
93
|
+
assert messages.is_a?( Array )
|
94
|
+
messages.each do |m|
|
95
|
+
assert m.is_a?( SQS::Message )
|
96
|
+
assert_equal @q, m.queue
|
97
|
+
assert_match /^I am receiving message \d+$/, m.body
|
98
|
+
end
|
99
|
+
|
100
|
+
messages = @q.receive_messages :count => 12
|
101
|
+
assert messages.is_a?( Array )
|
102
|
+
assert messages.size > 0 && messages.size < 12, "Weird array size: #{messages.size}"
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_force_delete
|
106
|
+
(1..10).to_a.each do |i|
|
107
|
+
@q.send_message( "I am receiving message ##{i}" )
|
108
|
+
end
|
109
|
+
|
110
|
+
sleep 5
|
111
|
+
|
112
|
+
assert_raises RuntimeError do
|
113
|
+
@q.delete
|
114
|
+
end
|
115
|
+
|
116
|
+
assert_nothing_raised do
|
117
|
+
@q.force_delete
|
118
|
+
end
|
119
|
+
|
120
|
+
sleep 5
|
121
|
+
|
122
|
+
assert_raises RuntimeError do
|
123
|
+
q = SQS.get_queue( @queue_prefix )
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
class DUMMY
|
128
|
+
def self.email
|
129
|
+
SQS_QueueTest::other_aws_account[:email]
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_add_grant
|
134
|
+
assert_respond_to @q, :add_grant
|
135
|
+
assert_equal 1, @q.list_grants.size
|
136
|
+
assert @q.add_grant( :email => SQStest.other_aws_account[:email], :permission => :full )
|
137
|
+
assert_equal 2, @q.list_grants.size
|
138
|
+
assert @q.add_grant( :email => SQStest.other_aws_account[:email], :permission => :send )
|
139
|
+
assert_equal 3, @q.list_grants.size
|
140
|
+
assert @q.add_grant( :email => SQStest.other_aws_account[:email], :permission => :receive )
|
141
|
+
assert_equal 4, @q.list_grants.size
|
142
|
+
|
143
|
+
assert_nothing_raised do
|
144
|
+
#DUMMY responds to :email (is not an address itself)
|
145
|
+
@q.add_grant( :email => DUMMY, :permission => :receive )
|
146
|
+
end
|
147
|
+
assert_equal 4, @q.list_grants.size
|
148
|
+
|
149
|
+
|
150
|
+
assert_raises RuntimeError do
|
151
|
+
assert @q.add_grant( :email => 'invalid@email.address', :permission => :receive )
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_remove_grant
|
156
|
+
assert_respond_to @q, :remove_grant
|
157
|
+
|
158
|
+
|
159
|
+
[:full, :send, :receive].each do |perm|
|
160
|
+
assert @q.add_grant( :email => SQStest.other_aws_account[:email], :permission => perm )
|
161
|
+
end
|
162
|
+
@q.list_grants.each do |g|
|
163
|
+
unless g.display_name == SQStest.my_aws_account[:display_name]
|
164
|
+
assert @q.remove_grant( :email => SQStest.other_aws_account[:email], :permission => g.permission )
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
[:full, :send, :receive].each do |perm|
|
169
|
+
assert @q.add_grant( :email => SQStest.other_aws_account[:email], :permission => perm )
|
170
|
+
end
|
171
|
+
@q.list_grants.each do |g|
|
172
|
+
unless g.display_name == SQStest.my_aws_account[:display_name]
|
173
|
+
#DUMMY responds to :email (is not an address itself)
|
174
|
+
assert @q.remove_grant( :email => DUMMY, :permission => g.permission )
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
[:full, :send, :receive].each do |perm|
|
179
|
+
assert @q.add_grant( :email => SQStest.other_aws_account[:email], :permission => perm )
|
180
|
+
end
|
181
|
+
@q.list_grants.each do |g|
|
182
|
+
unless g.display_name == SQStest.my_aws_account[:display_name]
|
183
|
+
assert @q.remove_grant( :id => g.id, :permission => g.permission )
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
[:full, :send, :receive].each do |perm|
|
188
|
+
assert @q.add_grant( :email => SQStest.other_aws_account[:email], :permission => perm )
|
189
|
+
end
|
190
|
+
@q.list_grants.each do |g|
|
191
|
+
unless g.display_name == SQStest.my_aws_account[:display_name]
|
192
|
+
# the grant responds to :id (is not an id itself)
|
193
|
+
assert @q.remove_grant( :id => g, :permission => g.permission )
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
def test_list_grants
|
199
|
+
assert_respond_to @q, :list_grants
|
200
|
+
grant = @q.list_grants
|
201
|
+
assert_equal 1, grant.size
|
202
|
+
grant = grant.first
|
203
|
+
assert_equal SQS.permissions[:full], grant.permission
|
204
|
+
assert_equal nil, grant.email
|
205
|
+
assert_equal SQStest.my_aws_account[:display_name], grant.display_name
|
206
|
+
|
207
|
+
@q.add_grant( :email => SQStest.other_aws_account[:email], :permission => :receive)
|
208
|
+
grants = @q.list_grants
|
209
|
+
assert_equal 2, grants.size
|
210
|
+
grants.each do |grant|
|
211
|
+
case grant.display_name
|
212
|
+
when SQStest.my_aws_account[:display_name]
|
213
|
+
assert_equal SQS.permissions[:full], grant.permission
|
214
|
+
when SQStest.other_aws_account[:display_name]
|
215
|
+
assert_equal SQS.permissions[:receive], grant.permission
|
216
|
+
else
|
217
|
+
assert false, "'#{grant.display_name}' is an unknown email address"
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
def test_each_grant
|
223
|
+
assert_respond_to @q, :each_grant
|
224
|
+
@q.add_grant( :email => SQStest.other_aws_account[:email], :permission => :receive)
|
225
|
+
@q.each_grant do |g|
|
226
|
+
assert_kind_of SQS::Grant, g
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
def test_get_visiblity_timeout
|
231
|
+
assert_respond_to @q, :visibility_timeout
|
232
|
+
assert_equal SQS::Queue.default_visibility_timeout, @q.visibility_timeout
|
233
|
+
assert_kind_of Integer, @q.visibility_timeout
|
234
|
+
|
235
|
+
q = SQS.create_queue :name => "#{@queue_prefix}getvisi", :DefaultVisibilityTimeout => 12345
|
236
|
+
assert_equal 12345, q.visibility_timeout
|
237
|
+
assert_kind_of Integer, q.visibility_timeout
|
238
|
+
end
|
239
|
+
|
240
|
+
def test_set_visiblity_timeout
|
241
|
+
assert_respond_to @q, :visibility_timeout=
|
242
|
+
assert( @q.visibility_timeout = 456 )
|
243
|
+
assert_equal 456, @q.visibility_timeout
|
244
|
+
|
245
|
+
assert_nothing_raised RuntimeError do
|
246
|
+
@q.visibility_timeout = nil
|
247
|
+
@q.visibility_timeout = 0
|
248
|
+
end
|
249
|
+
|
250
|
+
assert_raises RuntimeError do
|
251
|
+
@q.visibility_timeout = -1
|
252
|
+
end
|
253
|
+
assert_raises RuntimeError do
|
254
|
+
@q.visibility_timeout = 86401
|
255
|
+
end
|
256
|
+
|
257
|
+
assert_raises NoMethodError do
|
258
|
+
@q.visibility_timeout = Object
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
def test_default_visibility_timeout
|
264
|
+
assert_respond_to SQS::Queue, :default_visibility_timeout
|
265
|
+
assert_equal 30, SQS::Queue.default_visibility_timeout
|
266
|
+
end
|
267
|
+
|
268
|
+
|
269
|
+
|
270
|
+
def test_new
|
271
|
+
assert_nothing_raised do
|
272
|
+
q1 = SQS::Queue.new :url => 'http://www.slappy.com/', :a => 'a', 'b' => :b
|
273
|
+
end
|
274
|
+
q1 = SQS::Queue.new :url => 'http://www.slappy.com/', :a => 'a', 'b' => :b
|
275
|
+
assert_equal 'http://www.slappy.com/', q1.url
|
276
|
+
|
277
|
+
q2 = SQS::Queue.new 'http://www.slappy.com/'
|
278
|
+
assert_equal 'http://www.slappy.com/', q2.url
|
279
|
+
|
280
|
+
assert_raises NameError do
|
281
|
+
q.a
|
282
|
+
end
|
283
|
+
assert_raises NameError do
|
284
|
+
q.b
|
285
|
+
end
|
286
|
+
|
287
|
+
assert_raises RuntimeError do
|
288
|
+
q = SQS::Queue.new :url => 'http://www.slappy.com'
|
289
|
+
q = SQS::Queue.new :url => 'LKJSDFLKJ@#$)()'
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
def test_url
|
294
|
+
q = SQS::Queue.new :url => 'http://queue.amazonaws.com/A3ZVJ8HH1F466/test96570'
|
295
|
+
assert_equal 'http://queue.amazonaws.com/A3ZVJ8HH1F466/test96570', q.url
|
296
|
+
end
|
297
|
+
|
298
|
+
def test_name
|
299
|
+
q = SQS::Queue.new :url => 'http://queue.amazonaws.com/A3ZVJ8HH1F466/test96570'
|
300
|
+
assert_equal 'test96570', q.name
|
301
|
+
end
|
302
|
+
|
303
|
+
def test_equality_check
|
304
|
+
q1 = SQS::Queue.new :url => 'http://queue.amazonaws.com/A3ZVJ8HH1F466/test96570'
|
305
|
+
q2 = SQS::Queue.new :url => 'http://queue.amazonaws.com/A3ZVJ8HH1F466/test96570'
|
306
|
+
q3 = SQS::Queue.new :url => 'http://queue.amazonaws.com/A3ZVJ8HH1F466/est96570'
|
307
|
+
|
308
|
+
assert q1 == q2
|
309
|
+
assert q1 != q3
|
310
|
+
assert q2 != q3
|
311
|
+
end
|
312
|
+
end
|