redaranj-right_aws 1.10.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +231 -0
- data/Manifest.txt +37 -0
- data/README.txt +164 -0
- data/Rakefile +103 -0
- data/lib/acf/right_acf_interface.rb +413 -0
- data/lib/awsbase/benchmark_fix.rb +39 -0
- data/lib/awsbase/right_awsbase.rb +903 -0
- data/lib/awsbase/support.rb +115 -0
- data/lib/ec2/right_ec2.rb +1837 -0
- data/lib/right_aws.rb +72 -0
- data/lib/s3/right_s3.rb +1094 -0
- data/lib/s3/right_s3_interface.rb +1185 -0
- data/lib/sdb/active_sdb.rb +930 -0
- data/lib/sdb/right_sdb_interface.rb +672 -0
- data/lib/sqs/right_sqs.rb +388 -0
- data/lib/sqs/right_sqs_gen2.rb +343 -0
- data/lib/sqs/right_sqs_gen2_interface.rb +521 -0
- data/lib/sqs/right_sqs_interface.rb +594 -0
- data/test/acf/test_helper.rb +2 -0
- data/test/acf/test_right_acf.rb +146 -0
- data/test/ec2/test_helper.rb +2 -0
- data/test/ec2/test_right_ec2.rb +108 -0
- data/test/http_connection.rb +87 -0
- data/test/s3/test_helper.rb +2 -0
- data/test/s3/test_right_s3.rb +419 -0
- data/test/s3/test_right_s3_stubbed.rb +95 -0
- data/test/sdb/test_active_sdb.rb +299 -0
- data/test/sdb/test_helper.rb +3 -0
- data/test/sdb/test_right_sdb.rb +247 -0
- data/test/sqs/test_helper.rb +2 -0
- data/test/sqs/test_right_sqs.rb +291 -0
- data/test/sqs/test_right_sqs_gen2.rb +276 -0
- data/test/test_credentials.rb +37 -0
- data/test/ts_right_aws.rb +14 -0
- metadata +100 -0
@@ -0,0 +1,291 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TestSqs < Test::Unit::TestCase
|
4
|
+
|
5
|
+
GRANTEE_EMAIL_ADDRESS = 'madhur@amazon.com'
|
6
|
+
RIGHT_MESSAGE_TEXT = 'Right test message'
|
7
|
+
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@sqs = Rightscale::SqsInterface.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
|
11
|
+
@queue_name = 'right_sqs_test_awesome_queue'
|
12
|
+
# for classes
|
13
|
+
@s = Rightscale::Sqs.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Wait for the queue to appears in the queues list.
|
17
|
+
# Amazon needs some time to after the queue creation to place
|
18
|
+
# it to the accessible queues list. If we dont want to get
|
19
|
+
# the additional faults then wait a bit...
|
20
|
+
def wait_for_queue_url(queue_name)
|
21
|
+
queue_url = nil
|
22
|
+
until queue_url
|
23
|
+
queue_url = @sqs.queue_url_by_name(queue_name)
|
24
|
+
unless queue_url
|
25
|
+
print '-'
|
26
|
+
STDOUT.flush
|
27
|
+
sleep 1
|
28
|
+
end
|
29
|
+
end
|
30
|
+
queue_url
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
def assert_eventually_equal(value, timeout=30, failmsg="", &block)
|
37
|
+
start_time = Time.now.to_i
|
38
|
+
tries = 0
|
39
|
+
while(yield != value) do
|
40
|
+
tries += 1
|
41
|
+
print '-'
|
42
|
+
STDOUT.flush
|
43
|
+
s = Time.now.to_i - start_time
|
44
|
+
flunk("Timeout: #{failmsg}: did not equal \"#{value}\" after #{tries} tries in #{s}s.") if s > timeout
|
45
|
+
sleep(1)
|
46
|
+
setup if (tries % 10) == 0
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
#---------------------------
|
52
|
+
# Rightscale::SqsInterface
|
53
|
+
#---------------------------
|
54
|
+
|
55
|
+
def test_01_create_queue
|
56
|
+
queue_url = @sqs.create_queue @queue_name
|
57
|
+
assert queue_url[/http.*#{@queue_name}/], 'New queue creation fail'
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_02_list_queues
|
61
|
+
wait_for_queue_url(@queue_name)
|
62
|
+
queues = @sqs.list_queues('right_')
|
63
|
+
assert queues.size>0, 'Must more that 0 queues in list'
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_03_set_and_get_queue_attributes
|
67
|
+
queue_url = @sqs.queue_url_by_name(@queue_name)
|
68
|
+
assert queue_url[/http.*#{@queue_name}/], "#{@queue_name} must exist!"
|
69
|
+
assert @sqs.set_queue_attributes(queue_url, 'VisibilityTimeout', 111), 'Set_queue_attributes fail'
|
70
|
+
sleep 20 # Amazon needs some time to change attribute
|
71
|
+
assert_equal '111', @sqs.get_queue_attributes(queue_url)['VisibilityTimeout'], 'New VisibilityTimeout must be equal to 111'
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_04_set_and_get_visibility_timeout
|
75
|
+
queue_url = @sqs.queue_url_by_name(@queue_name)
|
76
|
+
assert @sqs.set_visibility_timeout(queue_url, 222), 'Set_visibility_timeout fail'
|
77
|
+
sleep 20 # Amazon needs some time to change attribute
|
78
|
+
#assert_equal 222, @sqs.get_visibility_timeout(queue_url), 'Get_visibility_timeout must return to 222'
|
79
|
+
assert_eventually_equal(222, 60, 'Get_visibility_timeout must return to 222') do
|
80
|
+
@sqs.get_visibility_timeout(queue_url)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_05_add_test_remove_grant
|
85
|
+
queue_url = @sqs.queue_url_by_name(@queue_name)
|
86
|
+
assert @sqs.add_grant(queue_url, GRANTEE_EMAIL_ADDRESS, 'FULLCONTROL'), 'Add grant fail'
|
87
|
+
grants_list = @sqs.list_grants(queue_url, GRANTEE_EMAIL_ADDRESS)
|
88
|
+
assert grants_list.size>0, 'List_grants must return at least 1 record for user #{GRANTEE_EMAIL_ADDRESS}'
|
89
|
+
assert @sqs.remove_grant(queue_url, GRANTEE_EMAIL_ADDRESS, 'FULLCONTROL'), 'Remove_grant fail'
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_06_send_message
|
93
|
+
queue_url = @sqs.queue_url_by_name(@queue_name)
|
94
|
+
# send 5 messages for the tests below
|
95
|
+
assert @sqs.send_message(queue_url, RIGHT_MESSAGE_TEXT)
|
96
|
+
assert @sqs.send_message(queue_url, RIGHT_MESSAGE_TEXT)
|
97
|
+
assert @sqs.send_message(queue_url, RIGHT_MESSAGE_TEXT)
|
98
|
+
assert @sqs.send_message(queue_url, RIGHT_MESSAGE_TEXT)
|
99
|
+
assert @sqs.send_message(queue_url, RIGHT_MESSAGE_TEXT)
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_07_get_queue_length
|
103
|
+
queue_url = @sqs.queue_url_by_name(@queue_name)
|
104
|
+
assert_equal 5, @sqs.get_queue_length(queue_url), 'Queue must have 5 messages'
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_08_receive_message
|
108
|
+
queue_url = @sqs.queue_url_by_name(@queue_name)
|
109
|
+
r_message = @sqs.receive_message(queue_url, 1)
|
110
|
+
assert_equal RIGHT_MESSAGE_TEXT, r_message[:body], 'Receive message get wron message text'
|
111
|
+
p_message = @sqs.peek_message(queue_url, r_message[:id])
|
112
|
+
assert_equal r_message[:body], p_message[:body], 'Received and Peeked messages must be equal'
|
113
|
+
assert @sqs.change_message_visibility(queue_url, r_message[:id], 0), 'Change_message_visibility fail'
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_09_delete_message
|
117
|
+
queue_url = @sqs.queue_url_by_name(@queue_name)
|
118
|
+
message = @sqs.receive_message(queue_url)
|
119
|
+
assert @sqs.delete_message(queue_url, message[:id]), 'Delete_message fail'
|
120
|
+
assert @sqs.pop_message(queue_url), 'Pop_message fail'
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_10_clear_and_delete_queue
|
124
|
+
queue_url = @sqs.queue_url_by_name(@queue_name)
|
125
|
+
assert_raise(Rightscale::AwsError) { @sqs.delete_queue(queue_url) }
|
126
|
+
## oops, force_clear_queue does not work any more - amazon expects for 60 secs timeout between
|
127
|
+
## queue deletion and recreation...
|
128
|
+
## assert @sqs.force_clear_queue(queue_url), 'Force_clear_queue fail'
|
129
|
+
assert @sqs.clear_queue(queue_url), 'Clear_queue fail'
|
130
|
+
assert @sqs.delete_queue(queue_url), 'Delete_queue fail'
|
131
|
+
end
|
132
|
+
|
133
|
+
#---------------------------
|
134
|
+
# Rightscale::Sqs classes
|
135
|
+
#---------------------------
|
136
|
+
|
137
|
+
def test_20_sqs_create_delete_queue
|
138
|
+
assert @s, 'Rightscale::Sqs must exist'
|
139
|
+
# get queues list
|
140
|
+
queues_size = @s.queues.size
|
141
|
+
# create new queue
|
142
|
+
queue = @s.queue("#{@queue_name}_20", true)
|
143
|
+
# check that it is created
|
144
|
+
assert queue.is_a?(Rightscale::Sqs::Queue)
|
145
|
+
wait_for_queue_url(@queue_name)
|
146
|
+
# check that amount of queues has increased
|
147
|
+
assert_eventually_equal(queues_size + 1, 60, "The number of queues did not increase by one") do
|
148
|
+
@s.queues.size
|
149
|
+
end
|
150
|
+
# delete queue
|
151
|
+
assert queue.delete
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_21_queue_create
|
155
|
+
# create new queue
|
156
|
+
queue = Rightscale::Sqs::Queue.create(@s, "#{@queue_name}_21", true)
|
157
|
+
# check that it is created
|
158
|
+
assert queue.is_a?(Rightscale::Sqs::Queue)
|
159
|
+
wait_for_queue_url(@queue_name)
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_22_queue_attributes
|
163
|
+
queue = Rightscale::Sqs::Queue.create(@s, "#{@queue_name}_21", false)
|
164
|
+
# get a list of attrinutes
|
165
|
+
attributes = queue.get_attribute
|
166
|
+
assert attributes.is_a?(Hash) && attributes.size>0
|
167
|
+
# get attribute value and increase it by 10
|
168
|
+
v = (queue.get_attribute('VisibilityTimeout').to_i + 10).to_s
|
169
|
+
# set attribute
|
170
|
+
assert queue.set_attribute('VisibilityTimeout', v)
|
171
|
+
# wait a bit
|
172
|
+
sleep 20
|
173
|
+
# check that attribute has changed
|
174
|
+
assert_equal v, queue.get_attribute('VisibilityTimeout')
|
175
|
+
# get queue visibility timeout
|
176
|
+
assert v.to_i, queue.visibility
|
177
|
+
# change it
|
178
|
+
queue.visibility += 10
|
179
|
+
# make sure that it is changed
|
180
|
+
assert v.to_i + 10, queue.visibility
|
181
|
+
end
|
182
|
+
|
183
|
+
def test_23_grantees
|
184
|
+
queue = Rightscale::Sqs::Queue.create(@s, "#{@queue_name}_21", false)
|
185
|
+
# get a list of grantees
|
186
|
+
grantees = queue.grantees
|
187
|
+
# well, queue must exist at least some seconds before we could add grantees to it....
|
188
|
+
# otherwise we get "Queue does not exists" message. Hence we use the queue
|
189
|
+
# has been created at previous step.
|
190
|
+
#
|
191
|
+
# create new grantee
|
192
|
+
grantee = Rightscale::Sqs::Grantee.new(queue, GRANTEE_EMAIL_ADDRESS)
|
193
|
+
assert grantee.perms.empty?
|
194
|
+
# grant perms
|
195
|
+
assert grantee.grant('FULLCONTROL')
|
196
|
+
assert grantee.grant('RECEIVEMESSAGE')
|
197
|
+
assert_equal 2, grantee.perms.size
|
198
|
+
# make sure that amount of grantees has increased
|
199
|
+
assert grantees.size < queue.grantees.size
|
200
|
+
# revoke perms
|
201
|
+
assert grantee.revoke('RECEIVEMESSAGE')
|
202
|
+
assert_equal 1, grantee.perms.size
|
203
|
+
# remove grantee
|
204
|
+
assert grantee.drop
|
205
|
+
# Don't test this - just for cleanup purposes
|
206
|
+
queue.delete
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_24_send_size
|
210
|
+
queue_url = @sqs.queue_url_by_name("#{@queue_name}_24")
|
211
|
+
@sqs.delete_queue(queue_url)
|
212
|
+
queue = Rightscale::Sqs::Queue.create(@s, "#{@queue_name}_24", true)
|
213
|
+
# send 5 messages
|
214
|
+
assert queue.push('a1')
|
215
|
+
assert queue.push('a2')
|
216
|
+
assert queue.push('a3')
|
217
|
+
assert queue.push('a4')
|
218
|
+
assert queue.push('a5')
|
219
|
+
# check queue size
|
220
|
+
assert_equal 5, queue.size
|
221
|
+
# send one more
|
222
|
+
assert queue.push('a6')
|
223
|
+
# check queue size again
|
224
|
+
assert_equal 6, queue.size
|
225
|
+
end
|
226
|
+
|
227
|
+
def test_25_message_receive_pop_peek_delete
|
228
|
+
queue = Rightscale::Sqs::Queue.create(@s, "#{@queue_name}_24", false)
|
229
|
+
# get queue size
|
230
|
+
size = queue.size
|
231
|
+
# get first message
|
232
|
+
m1 = queue.receive(10)
|
233
|
+
assert m1.is_a?(Rightscale::Sqs::Message)
|
234
|
+
# pop second message
|
235
|
+
m2 = queue.pop
|
236
|
+
assert m2.is_a?(Rightscale::Sqs::Message)
|
237
|
+
# make sure that queue size has decreased
|
238
|
+
assert_equal size-1, queue.size
|
239
|
+
# peek message 1
|
240
|
+
m1p = queue.peek(m1.id)
|
241
|
+
assert m1p.is_a?(Rightscale::Sqs::Message)
|
242
|
+
assert_equal m1.id, m1p.id
|
243
|
+
assert_equal m1.body, m1p.body
|
244
|
+
# change message visibility
|
245
|
+
assert m1.visibility = 30
|
246
|
+
# delete messsage
|
247
|
+
assert m1.delete
|
248
|
+
# make sure that queue size has decreased again
|
249
|
+
assert_equal size-2, queue.size
|
250
|
+
end
|
251
|
+
|
252
|
+
def test_26
|
253
|
+
queue = Rightscale::Sqs::Queue.create(@s, "#{@queue_name}_24", false)
|
254
|
+
# lock message
|
255
|
+
queue.receive(100)
|
256
|
+
# clear queue
|
257
|
+
assert queue.clear
|
258
|
+
# queue size is greater than zero
|
259
|
+
assert queue.size>0
|
260
|
+
queue.push('123456')
|
261
|
+
assert_raise(Rightscale::AwsError) { queue.delete }
|
262
|
+
assert queue.delete(true)
|
263
|
+
end
|
264
|
+
|
265
|
+
def test_27_set_amazon_problems
|
266
|
+
original_problems = Rightscale::SqsInterface.amazon_problems
|
267
|
+
assert(original_problems.length > 0)
|
268
|
+
Rightscale::SqsInterface.amazon_problems= original_problems << "A New Problem"
|
269
|
+
new_problems = Rightscale::SqsInterface.amazon_problems
|
270
|
+
assert_equal(new_problems, original_problems)
|
271
|
+
|
272
|
+
Rightscale::SqsInterface.amazon_problems= nil
|
273
|
+
assert_nil(Rightscale::SqsInterface.amazon_problems)
|
274
|
+
end
|
275
|
+
|
276
|
+
def test_28_check_threading_model
|
277
|
+
assert(!@sqs.multi_thread)
|
278
|
+
newsqs = Rightscale::SqsInterface.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key, {:multi_thread => true})
|
279
|
+
assert(newsqs.multi_thread)
|
280
|
+
end
|
281
|
+
|
282
|
+
def test_29_signature_version_0
|
283
|
+
sqs = Rightscale::SqsInterface.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key, :signature_version => '0')
|
284
|
+
assert_nothing_raised do
|
285
|
+
sqs.list_queues
|
286
|
+
end
|
287
|
+
# check that the request has correct signature version
|
288
|
+
assert sqs.last_request.path.include?('SignatureVersion=0')
|
289
|
+
end
|
290
|
+
|
291
|
+
end
|
@@ -0,0 +1,276 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TestSqsGen2 < Test::Unit::TestCase
|
4
|
+
|
5
|
+
GRANTEE_EMAIL_ADDRESS = 'fester@example.com'
|
6
|
+
RIGHT_MESSAGE_TEXT = 'Right test message'
|
7
|
+
|
8
|
+
|
9
|
+
def setup
|
10
|
+
$stdout.sync = true
|
11
|
+
@grantee_aws_id = '100000000001'
|
12
|
+
@sqs = Rightscale::SqsGen2Interface.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
|
13
|
+
@queue_name = 'right_sqs_test_gen2_queue'
|
14
|
+
# for classes
|
15
|
+
@s = Rightscale::SqsGen2.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Wait for the queue to appear in the queues list.
|
19
|
+
# Amazon needs some time to after the queue creation to place
|
20
|
+
# it to the accessible queues list. If we dont want to get
|
21
|
+
# the additional faults then wait a bit...
|
22
|
+
def wait_for_queue_url(queue_name)
|
23
|
+
queue_url = nil
|
24
|
+
do_sleep(180) do
|
25
|
+
queue_url = @sqs.queue_url_by_name(queue_name)
|
26
|
+
end
|
27
|
+
sleep 10
|
28
|
+
queue_url
|
29
|
+
end
|
30
|
+
|
31
|
+
def do_sleep(delay, &block)
|
32
|
+
puts "sleeping #{block ? 'up to ' : ''}#{delay} seconds:"
|
33
|
+
wake_up_at = Time.now+delay
|
34
|
+
while Time.now < wake_up_at do
|
35
|
+
sleep 1
|
36
|
+
print '.'
|
37
|
+
break if block && block.call
|
38
|
+
end
|
39
|
+
puts
|
40
|
+
end
|
41
|
+
|
42
|
+
#---------------------------
|
43
|
+
# Rightscale::SqsInterface
|
44
|
+
#---------------------------
|
45
|
+
|
46
|
+
def test_01_create_queue
|
47
|
+
queue_url = @sqs.create_queue @queue_name
|
48
|
+
assert queue_url[/http.*#{@queue_name}/], 'New queue creation failed'
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_02_list_queues
|
52
|
+
wait_for_queue_url(@queue_name)
|
53
|
+
queues = @sqs.list_queues('right_')
|
54
|
+
assert queues.size>0, 'Must more that 0 queues in list'
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_03_set_and_get_queue_attributes
|
58
|
+
queue_url = @sqs.queue_url_by_name(@queue_name)
|
59
|
+
assert queue_url[/https.*#{@queue_name}/], "#{@queue_name} must exist!"
|
60
|
+
assert @sqs.set_queue_attributes(queue_url, 'VisibilityTimeout', 111), 'Set_queue_attributes fail'
|
61
|
+
do_sleep 60 # Amazon needs some time to change attribute
|
62
|
+
assert_equal '111', @sqs.get_queue_attributes(queue_url)['VisibilityTimeout'], 'New VisibilityTimeout must be equal to 111'
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_04_get_queue_attributes_forms
|
66
|
+
queue_url = @sqs.queue_url_by_name(@queue_name)
|
67
|
+
all = nil
|
68
|
+
assert_nothing_raised do
|
69
|
+
all = @sqs.get_queue_attributes(queue_url, 'All')
|
70
|
+
end
|
71
|
+
assert_nothing_raised do
|
72
|
+
assert all, @sqs.get_queue_attributes(queue_url)
|
73
|
+
end
|
74
|
+
assert_nothing_raised do
|
75
|
+
attributes = @sqs.get_queue_attributes(queue_url, 'ApproximateNumberOfMessages', 'VisibilityTimeout')
|
76
|
+
assert_equal 2, attributes.size
|
77
|
+
end
|
78
|
+
assert_nothing_raised do
|
79
|
+
attributes = @sqs.get_queue_attributes(queue_url, ['ApproximateNumberOfMessages', 'VisibilityTimeout'])
|
80
|
+
assert_equal 2, attributes.size
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_05_add_permissions
|
85
|
+
queue_url = @sqs.queue_url_by_name(@queue_name)
|
86
|
+
assert @sqs.add_permissions(queue_url, 'test01', @grantee_aws_id => 'SendMessage')
|
87
|
+
assert @sqs.add_permissions(queue_url, 'test02', @grantee_aws_id => ['DeleteMessage','ReceiveMessage'])
|
88
|
+
do_sleep 60
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_06_test_permissions
|
92
|
+
queue_url = @sqs.queue_url_by_name(@queue_name)
|
93
|
+
permissions = @sqs.get_queue_attributes(queue_url, 'Policy')
|
94
|
+
assert !permissions.blank?
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_07_revoke_permissions
|
98
|
+
queue_url = @sqs.queue_url_by_name(@queue_name)
|
99
|
+
assert @sqs.remove_permissions(queue_url, 'test01')
|
100
|
+
assert @sqs.remove_permissions(queue_url, 'test02')
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_14_send_message
|
104
|
+
queue_url = @sqs.queue_url_by_name(@queue_name)
|
105
|
+
# send 5 messages for the tests below
|
106
|
+
assert @sqs.send_message(queue_url, RIGHT_MESSAGE_TEXT)
|
107
|
+
assert @sqs.send_message(queue_url, RIGHT_MESSAGE_TEXT)
|
108
|
+
assert @sqs.send_message(queue_url, RIGHT_MESSAGE_TEXT)
|
109
|
+
assert @sqs.send_message(queue_url, RIGHT_MESSAGE_TEXT)
|
110
|
+
assert @sqs.send_message(queue_url, RIGHT_MESSAGE_TEXT)
|
111
|
+
do_sleep 30
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_15_get_queue_length
|
115
|
+
queue_url = @sqs.queue_url_by_name(@queue_name)
|
116
|
+
assert_equal 5, @sqs.get_queue_length(queue_url), 'Queue must have 5 messages'
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_16_receive_message
|
120
|
+
queue_url = @sqs.queue_url_by_name(@queue_name)
|
121
|
+
r_message = @sqs.receive_message(queue_url, 1)[0]
|
122
|
+
assert r_message, "Receive returned no message(s), but this is not necessarily incorrect"
|
123
|
+
assert_equal RIGHT_MESSAGE_TEXT, r_message['Body'], 'Receive message got wrong message text'
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_17_delete_message
|
127
|
+
queue_url = @sqs.queue_url_by_name(@queue_name)
|
128
|
+
message = @sqs.receive_message(queue_url)[0]
|
129
|
+
assert @sqs.delete_message(queue_url, message['ReceiptHandle']), 'Delete_message fail'
|
130
|
+
assert @sqs.pop_message(queue_url), 'Pop_message fail'
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_18_clear_and_delete_queue
|
134
|
+
queue_url = @sqs.queue_url_by_name(@queue_name)
|
135
|
+
assert @sqs.delete_queue(queue_url)
|
136
|
+
end
|
137
|
+
|
138
|
+
#---------------------------
|
139
|
+
# Rightscale::Sqs classes
|
140
|
+
#---------------------------
|
141
|
+
|
142
|
+
def test_20_sqs_create_queue
|
143
|
+
assert @s, 'Rightscale::SqsGen2 must exist'
|
144
|
+
# get queues list
|
145
|
+
queues_size = @s.queues.size
|
146
|
+
# create new queue
|
147
|
+
queue = @s.queue("#{@queue_name}_20", true)
|
148
|
+
# check that it is created
|
149
|
+
assert queue.is_a?(Rightscale::SqsGen2::Queue)
|
150
|
+
wait_for_queue_url(queue.name)
|
151
|
+
# check that amount of queues has increased
|
152
|
+
assert_equal queues_size + 1, @s.queues.size
|
153
|
+
do_sleep 10
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_21_sqs_delete_queue
|
157
|
+
queue = @s.queue("#{@queue_name}_20", false)
|
158
|
+
assert queue.delete
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_22_queue_create
|
162
|
+
# create new queue
|
163
|
+
queue = Rightscale::SqsGen2::Queue.create(@s, "#{@queue_name}_21", true)
|
164
|
+
# check that it is created
|
165
|
+
assert queue.is_a?(Rightscale::SqsGen2::Queue)
|
166
|
+
wait_for_queue_url(@queue_name)
|
167
|
+
do_sleep 10
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_23_queue_attributes
|
171
|
+
queue = Rightscale::SqsGen2::Queue.create(@s, "#{@queue_name}_21", false)
|
172
|
+
# get a list of attrinutes
|
173
|
+
attributes = queue.get_attribute
|
174
|
+
assert attributes.is_a?(Hash) && attributes.size>0
|
175
|
+
# get attribute value and increase it by 10
|
176
|
+
v = (queue.get_attribute('VisibilityTimeout').to_i + 10).to_s
|
177
|
+
# set attribute
|
178
|
+
assert queue.set_attribute('VisibilityTimeout', v)
|
179
|
+
# wait a bit
|
180
|
+
do_sleep 30
|
181
|
+
# check that attribute has changed
|
182
|
+
assert_equal v, queue.get_attribute('VisibilityTimeout')
|
183
|
+
# get queue visibility timeout
|
184
|
+
assert_equal v, queue.visibility
|
185
|
+
# change it
|
186
|
+
queue.visibility = queue.visibility.to_i + 10
|
187
|
+
# make sure that it is changed
|
188
|
+
assert v.to_i + 10, queue.visibility
|
189
|
+
end
|
190
|
+
|
191
|
+
def test_24
|
192
|
+
queue = Rightscale::SqsGen2::Queue.create(@s, "#{@queue_name}_21", false)
|
193
|
+
assert queue.delete
|
194
|
+
end
|
195
|
+
|
196
|
+
def test_25_send_size
|
197
|
+
queue = Rightscale::SqsGen2::Queue.create(@s, "#{@queue_name}_24", true)
|
198
|
+
# send 5 messages
|
199
|
+
assert queue.push('a1')
|
200
|
+
assert queue.push('a2')
|
201
|
+
assert queue.push('a3')
|
202
|
+
assert queue.push('a4')
|
203
|
+
assert queue.push('a5')
|
204
|
+
#
|
205
|
+
do_sleep 15
|
206
|
+
# check queue size
|
207
|
+
assert_equal 5, queue.size
|
208
|
+
# send one more
|
209
|
+
assert queue.push('a6')
|
210
|
+
#
|
211
|
+
do_sleep 15
|
212
|
+
# check queue size again
|
213
|
+
assert_equal 6, queue.size
|
214
|
+
end
|
215
|
+
|
216
|
+
def test_26_message_receive_pop_delete
|
217
|
+
queue = Rightscale::SqsGen2::Queue.create(@s, "#{@queue_name}_24", false)
|
218
|
+
# get queue size
|
219
|
+
size = queue.size
|
220
|
+
# get first message
|
221
|
+
m1 = queue.receive(10)
|
222
|
+
assert m1.is_a?(Rightscale::SqsGen2::Message)
|
223
|
+
# pop second message
|
224
|
+
m2 = queue.pop
|
225
|
+
assert m2.is_a?(Rightscale::SqsGen2::Message)
|
226
|
+
#
|
227
|
+
do_sleep 15
|
228
|
+
# make sure that queue size has decreased
|
229
|
+
assert_equal size-1, queue.size
|
230
|
+
# delete messsage
|
231
|
+
assert m1.delete
|
232
|
+
#
|
233
|
+
do_sleep 15
|
234
|
+
# make sure that queue size has decreased again
|
235
|
+
assert_equal size-2, queue.size
|
236
|
+
end
|
237
|
+
|
238
|
+
def test_27
|
239
|
+
queue = Rightscale::SqsGen2::Queue.create(@s, "#{@queue_name}_24", false)
|
240
|
+
# lock message
|
241
|
+
queue.receive(100)
|
242
|
+
# clear queue
|
243
|
+
assert queue.clear
|
244
|
+
# queue size is greater than zero
|
245
|
+
assert queue.size>0
|
246
|
+
# delete queue
|
247
|
+
assert queue.delete
|
248
|
+
end
|
249
|
+
|
250
|
+
def test_28_set_amazon_problems
|
251
|
+
original_problems = Rightscale::SqsGen2Interface.amazon_problems
|
252
|
+
assert(original_problems.length > 0)
|
253
|
+
Rightscale::SqsGen2Interface.amazon_problems= original_problems << "A New Problem"
|
254
|
+
new_problems = Rightscale::SqsGen2Interface.amazon_problems
|
255
|
+
assert_equal(new_problems, original_problems)
|
256
|
+
|
257
|
+
Rightscale::SqsGen2Interface.amazon_problems= nil
|
258
|
+
assert_nil(Rightscale::SqsGen2Interface.amazon_problems)
|
259
|
+
end
|
260
|
+
|
261
|
+
def test_29_check_threading_model
|
262
|
+
assert(!@sqs.multi_thread)
|
263
|
+
newsqs = Rightscale::SqsGen2Interface.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key, {:multi_thread => true})
|
264
|
+
assert(newsqs.multi_thread)
|
265
|
+
end
|
266
|
+
|
267
|
+
def test_30_signature_version_0
|
268
|
+
sqs = Rightscale::SqsInterface.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key, :signature_version => '0')
|
269
|
+
assert_nothing_raised do
|
270
|
+
sqs.list_queues
|
271
|
+
end
|
272
|
+
# check that the request has correct signature version
|
273
|
+
assert sqs.last_request.path.include?('SignatureVersion=0')
|
274
|
+
end
|
275
|
+
|
276
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class TestCredentials
|
2
|
+
|
3
|
+
@@aws_access_key_id = nil
|
4
|
+
@@aws_secret_access_key = nil
|
5
|
+
@@account_number = nil
|
6
|
+
|
7
|
+
def self.aws_access_key_id
|
8
|
+
@@aws_access_key_id
|
9
|
+
end
|
10
|
+
def self.aws_access_key_id=(newval)
|
11
|
+
@@aws_access_key_id = newval
|
12
|
+
end
|
13
|
+
def self.account_number
|
14
|
+
@@account_number
|
15
|
+
end
|
16
|
+
def self.account_number=(newval)
|
17
|
+
@@account_number = newval
|
18
|
+
end
|
19
|
+
def self.aws_secret_access_key
|
20
|
+
@@aws_secret_access_key
|
21
|
+
end
|
22
|
+
def self.aws_secret_access_key=(newval)
|
23
|
+
@@aws_secret_access_key = newval
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.get_credentials
|
27
|
+
Dir.chdir do
|
28
|
+
begin
|
29
|
+
Dir.chdir('./.rightscale') do
|
30
|
+
require 'testcredentials'
|
31
|
+
end
|
32
|
+
rescue Exception => e
|
33
|
+
puts "Couldn't chdir to ~/.rightscale: #{e.message}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
$: << File.dirname(__FILE__)
|
3
|
+
require 'test_credentials'
|
4
|
+
TestCredentials.get_credentials
|
5
|
+
|
6
|
+
require 'http_connection'
|
7
|
+
require 'awsbase/test_right_awsbase.rb'
|
8
|
+
require 'ec2/test_right_ec2.rb'
|
9
|
+
require 's3/test_right_s3.rb'
|
10
|
+
require 's3/test_right_s3_stubbed.rb'
|
11
|
+
require 'sqs/test_right_sqs.rb'
|
12
|
+
require 'sqs/test_right_sqs_gen2.rb'
|
13
|
+
require 'sdb/test_right_sdb.rb'
|
14
|
+
require 'acf/test_right_acf.rb'
|