aboisvert_aws 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. data/History.txt +329 -0
  2. data/Manifest.txt +61 -0
  3. data/README.txt +163 -0
  4. data/Rakefile +130 -0
  5. data/lib/acf/right_acf_interface.rb +549 -0
  6. data/lib/acf/right_acf_invalidations.rb +144 -0
  7. data/lib/acf/right_acf_origin_access_identities.rb +230 -0
  8. data/lib/acf/right_acf_streaming_interface.rb +229 -0
  9. data/lib/acw/right_acw_interface.rb +248 -0
  10. data/lib/as/right_as_interface.rb +698 -0
  11. data/lib/awsbase/benchmark_fix.rb +39 -0
  12. data/lib/awsbase/right_awsbase.rb +1343 -0
  13. data/lib/awsbase/support.rb +35 -0
  14. data/lib/awsbase/version.rb +9 -0
  15. data/lib/ec2/right_ec2.rb +541 -0
  16. data/lib/ec2/right_ec2_ebs.rb +481 -0
  17. data/lib/ec2/right_ec2_images.rb +444 -0
  18. data/lib/ec2/right_ec2_instances.rb +788 -0
  19. data/lib/ec2/right_ec2_monitoring.rb +70 -0
  20. data/lib/ec2/right_ec2_placement_groups.rb +108 -0
  21. data/lib/ec2/right_ec2_reserved_instances.rb +184 -0
  22. data/lib/ec2/right_ec2_security_groups.rb +491 -0
  23. data/lib/ec2/right_ec2_spot_instances.rb +422 -0
  24. data/lib/ec2/right_ec2_tags.rb +139 -0
  25. data/lib/ec2/right_ec2_vpc.rb +590 -0
  26. data/lib/ec2/right_ec2_vpc2.rb +381 -0
  27. data/lib/ec2/right_ec2_windows_mobility.rb +84 -0
  28. data/lib/elb/right_elb_interface.rb +573 -0
  29. data/lib/emr/right_emr_interface.rb +727 -0
  30. data/lib/iam/right_iam_access_keys.rb +71 -0
  31. data/lib/iam/right_iam_groups.rb +195 -0
  32. data/lib/iam/right_iam_interface.rb +341 -0
  33. data/lib/iam/right_iam_mfa_devices.rb +67 -0
  34. data/lib/iam/right_iam_users.rb +251 -0
  35. data/lib/rds/right_rds_interface.rb +1384 -0
  36. data/lib/right_aws.rb +86 -0
  37. data/lib/route_53/right_route_53_interface.rb +640 -0
  38. data/lib/s3/right_s3.rb +1138 -0
  39. data/lib/s3/right_s3_interface.rb +1278 -0
  40. data/lib/sdb/active_sdb.rb +1107 -0
  41. data/lib/sdb/right_sdb_interface.rb +762 -0
  42. data/lib/sns/right_sns_interface.rb +286 -0
  43. data/lib/sqs/right_sqs.rb +387 -0
  44. data/lib/sqs/right_sqs_gen2.rb +342 -0
  45. data/lib/sqs/right_sqs_gen2_interface.rb +523 -0
  46. data/lib/sqs/right_sqs_interface.rb +593 -0
  47. data/right_aws.gemspec +90 -0
  48. data/test/README.mdown +39 -0
  49. data/test/acf/test_helper.rb +2 -0
  50. data/test/acf/test_right_acf.rb +138 -0
  51. data/test/awsbase/test_helper.rb +2 -0
  52. data/test/awsbase/test_right_awsbase.rb +11 -0
  53. data/test/ec2/test_helper.rb +2 -0
  54. data/test/ec2/test_right_ec2.rb +107 -0
  55. data/test/elb/test_helper.rb +2 -0
  56. data/test/elb/test_right_elb.rb +43 -0
  57. data/test/http_connection.rb +87 -0
  58. data/test/rds/test_helper.rb +2 -0
  59. data/test/rds/test_right_rds.rb +120 -0
  60. data/test/route_53/fixtures/a_record.xml +18 -0
  61. data/test/route_53/fixtures/alias_record.xml +18 -0
  62. data/test/route_53/test_helper.rb +2 -0
  63. data/test/route_53/test_right_route_53.rb +141 -0
  64. data/test/s3/test_helper.rb +2 -0
  65. data/test/s3/test_right_s3.rb +528 -0
  66. data/test/s3/test_right_s3_stubbed.rb +97 -0
  67. data/test/sdb/test_active_sdb.rb +357 -0
  68. data/test/sdb/test_batch_put_attributes.rb +54 -0
  69. data/test/sdb/test_helper.rb +3 -0
  70. data/test/sdb/test_right_sdb.rb +253 -0
  71. data/test/sns/test_helper.rb +2 -0
  72. data/test/sns/test_right_sns.rb +153 -0
  73. data/test/sqs/test_helper.rb +2 -0
  74. data/test/sqs/test_right_sqs.rb +285 -0
  75. data/test/sqs/test_right_sqs_gen2.rb +264 -0
  76. data/test/test_credentials.rb +37 -0
  77. data/test/ts_right_aws.rb +15 -0
  78. metadata +257 -0
@@ -0,0 +1,2 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../../lib/right_aws'
@@ -0,0 +1,285 @@
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_29_signature_version_0
277
+ sqs = Rightscale::SqsInterface.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key, :signature_version => '0')
278
+ assert_nothing_raised do
279
+ sqs.list_queues
280
+ end
281
+ # check that the request has correct signature version
282
+ assert sqs.last_request.path.include?('SignatureVersion=0')
283
+ end
284
+
285
+ end
@@ -0,0 +1,264 @@
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
+ @queue2_name = @queue_name + '_2'
15
+ @queue3_name = @queue_name + '_3'
16
+ @queue4_name = @queue_name + '_4'
17
+ # for classes
18
+ @s = Rightscale::SqsGen2.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
19
+ end
20
+
21
+ # Wait for the queue to appear in the queues list.
22
+ # Amazon needs some time to after the queue creation to place
23
+ # it to the accessible queues list. If we dont want to get
24
+ # the additional faults then wait a bit...
25
+ def wait_for_queue_url(queue_name)
26
+ queue_url = nil
27
+ do_sleep(180) do
28
+ queue_url = @sqs.queue_url_by_name(queue_name)
29
+ end
30
+ sleep 30
31
+ queue_url
32
+ end
33
+
34
+ def do_sleep(delay, &block)
35
+ puts "sleeping #{block ? 'up to ' : ''}#{delay} seconds:"
36
+ wake_up_at = Time.now+delay
37
+ while Time.now < wake_up_at do
38
+ sleep 1
39
+ print '.'
40
+ break if block && block.call
41
+ end
42
+ puts
43
+ end
44
+
45
+ #---------------------------
46
+ # Rightscale::SqsInterface
47
+ #---------------------------
48
+
49
+ def test_01_create_queue
50
+ queue_url = @sqs.create_queue @queue_name
51
+ assert queue_url[/http.*#{@queue_name}/], 'New queue creation failed'
52
+ end
53
+
54
+ def test_02_list_queues
55
+ wait_for_queue_url(@queue_name)
56
+ queues = @sqs.list_queues('right_')
57
+ assert queues.size>0, 'Must more that 0 queues in list'
58
+ end
59
+
60
+ def test_03_set_and_get_queue_attributes
61
+ queue_url = @sqs.queue_url_by_name(@queue_name)
62
+ assert queue_url[/https.*#{@queue_name}/], "#{@queue_name} must exist!"
63
+ assert @sqs.set_queue_attributes(queue_url, 'VisibilityTimeout', 111), 'Set_queue_attributes fail'
64
+ do_sleep 60 # Amazon needs some time to change attribute
65
+ assert_equal '111', @sqs.get_queue_attributes(queue_url)['VisibilityTimeout'], 'New VisibilityTimeout must be equal to 111'
66
+ end
67
+
68
+ def test_04_get_queue_attributes_forms
69
+ queue_url = @sqs.queue_url_by_name(@queue_name)
70
+ all = nil
71
+ assert_nothing_raised do
72
+ all = @sqs.get_queue_attributes(queue_url, 'All')
73
+ end
74
+ assert_nothing_raised do
75
+ assert all, @sqs.get_queue_attributes(queue_url)
76
+ end
77
+ assert_nothing_raised do
78
+ attributes = @sqs.get_queue_attributes(queue_url, 'ApproximateNumberOfMessages', 'VisibilityTimeout')
79
+ assert_equal 2, attributes.size
80
+ end
81
+ assert_nothing_raised do
82
+ attributes = @sqs.get_queue_attributes(queue_url, ['ApproximateNumberOfMessages', 'VisibilityTimeout'])
83
+ assert_equal 2, attributes.size
84
+ end
85
+ end
86
+
87
+ def test_05_add_permissions
88
+ queue_url = @sqs.queue_url_by_name(@queue_name)
89
+ assert @sqs.add_permissions(queue_url, 'test01', @grantee_aws_id, 'SendMessage')
90
+ assert @sqs.add_permissions(queue_url, 'test02', @grantee_aws_id, ['DeleteMessage','ReceiveMessage'])
91
+ do_sleep 60
92
+ end
93
+
94
+ def test_06_test_permissions
95
+ queue_url = @sqs.queue_url_by_name(@queue_name)
96
+ permissions = @sqs.get_queue_attributes(queue_url, 'Policy')
97
+ assert !permissions.right_blank?
98
+ end
99
+
100
+ def test_07_revoke_permissions
101
+ queue_url = @sqs.queue_url_by_name(@queue_name)
102
+ assert @sqs.remove_permissions(queue_url, 'test01')
103
+ assert @sqs.remove_permissions(queue_url, 'test02')
104
+ end
105
+
106
+ def test_14_send_message
107
+ queue_url = @sqs.queue_url_by_name(@queue_name)
108
+ # send 5 messages for the tests below
109
+ assert @sqs.send_message(queue_url, RIGHT_MESSAGE_TEXT)
110
+ assert @sqs.send_message(queue_url, RIGHT_MESSAGE_TEXT)
111
+ assert @sqs.send_message(queue_url, RIGHT_MESSAGE_TEXT)
112
+ assert @sqs.send_message(queue_url, RIGHT_MESSAGE_TEXT)
113
+ assert @sqs.send_message(queue_url, RIGHT_MESSAGE_TEXT)
114
+ do_sleep 60
115
+ end
116
+
117
+ def test_15_get_queue_length
118
+ queue_url = @sqs.queue_url_by_name(@queue_name)
119
+ assert_equal 5, @sqs.get_queue_length(queue_url), 'Queue must have 5 messages'
120
+ end
121
+
122
+ def test_16_receive_message
123
+ queue_url = @sqs.queue_url_by_name(@queue_name)
124
+ r_message = @sqs.receive_message(queue_url, 1)[0]
125
+ assert r_message, "Receive returned no message(s), but this is not necessarily incorrect"
126
+ assert_equal RIGHT_MESSAGE_TEXT, r_message['Body'], 'Receive message got wrong message text'
127
+ end
128
+
129
+ def test_17_delete_message
130
+ queue_url = @sqs.queue_url_by_name(@queue_name)
131
+ message = @sqs.receive_message(queue_url)[0]
132
+ assert @sqs.delete_message(queue_url, message['ReceiptHandle']), 'Delete_message fail'
133
+ assert @sqs.pop_message(queue_url), 'Pop_message fail'
134
+ end
135
+
136
+ def test_18_clear_and_delete_queue
137
+ queue_url = @sqs.queue_url_by_name(@queue_name)
138
+ assert @sqs.delete_queue(queue_url)
139
+ end
140
+
141
+ #---------------------------
142
+ # Rightscale::Sqs classes
143
+ #---------------------------
144
+
145
+ def test_20_sqs_create_queue
146
+ assert @s, 'Rightscale::SqsGen2 must exist'
147
+ # get queues list
148
+ queues_size = @s.queues.size
149
+ # create new queue
150
+ queue = @s.queue(@queue2_name, true)
151
+ # check that it is created
152
+ assert queue.is_a?(Rightscale::SqsGen2::Queue)
153
+ wait_for_queue_url(queue.name)
154
+ # check that amount of queues has increased
155
+ assert_equal queues_size + 1, @s.queues.size
156
+ do_sleep 10
157
+ end
158
+
159
+ def test_21_sqs_delete_queue
160
+ queue = @s.queue(@queue2_name, false)
161
+ assert queue.delete
162
+ end
163
+
164
+ def test_22_queue_create
165
+ # create new queue
166
+ queue = Rightscale::SqsGen2::Queue.create(@s, @queue3_name, true)
167
+ # check that it is created
168
+ assert queue.is_a?(Rightscale::SqsGen2::Queue)
169
+ wait_for_queue_url("#{@queue_name}_21")
170
+ do_sleep 10
171
+ end
172
+
173
+ def test_23_queue_attributes
174
+ queue = Rightscale::SqsGen2::Queue.create(@s, @queue3_name, false)
175
+ # get a list of attrinutes
176
+ attributes = queue.get_attribute
177
+ assert attributes.is_a?(Hash) && attributes.size>0
178
+ # get attribute value and increase it by 10
179
+ v = (queue.get_attribute('VisibilityTimeout').to_i + 10).to_s
180
+ # set attribute
181
+ assert queue.set_attribute('VisibilityTimeout', v)
182
+ # wait a bit
183
+ do_sleep 60
184
+ # check that attribute has changed
185
+ assert_equal v, queue.get_attribute('VisibilityTimeout')
186
+ # get queue visibility timeout
187
+ assert_equal v, queue.visibility
188
+ # change it
189
+ queue.visibility = queue.visibility.to_i + 10
190
+ # make sure that it is changed
191
+ assert v.to_i + 10, queue.visibility
192
+ end
193
+
194
+ def test_24
195
+ queue = Rightscale::SqsGen2::Queue.create(@s, @queue3_name, false)
196
+ assert queue.delete
197
+ end
198
+
199
+ def test_25_send_size
200
+ queue = Rightscale::SqsGen2::Queue.create(@s, @queue4_name, true)
201
+ # send 5 messages
202
+ assert queue.push('a1')
203
+ assert queue.push('a2')
204
+ assert queue.push('a3')
205
+ assert queue.push('a4')
206
+ assert queue.push('a5')
207
+ #
208
+ do_sleep(300){ queue.size == 5 }
209
+ # check queue size
210
+ assert_equal 5, queue.size
211
+ # send one more
212
+ assert queue.push('a6')
213
+ #
214
+ do_sleep(300){ queue.size == 6 }
215
+ # check queue size again
216
+ assert_equal 6, queue.size
217
+ end
218
+
219
+ def test_26_message_receive_pop_delete
220
+ queue = Rightscale::SqsGen2::Queue.create(@s, @queue4_name, false)
221
+ # get queue size
222
+ size = queue.size
223
+ # get first message
224
+ m1 = queue.receive(10)
225
+ assert m1.is_a?(Rightscale::SqsGen2::Message)
226
+ # pop second message
227
+ m2 = queue.pop
228
+ assert m2.is_a?(Rightscale::SqsGen2::Message)
229
+ #
230
+ do_sleep 30
231
+ # make sure that queue size has decreased
232
+ assert_equal size-1, queue.size
233
+ # delete messsage
234
+ assert m1.delete
235
+ #
236
+ do_sleep 15
237
+ # make sure that queue size has decreased again
238
+ assert_equal size-2, queue.size
239
+ end
240
+
241
+ def test_27
242
+ queue = Rightscale::SqsGen2::Queue.create(@s, @queue4_name, false)
243
+ # lock message
244
+ queue.receive(100)
245
+ # clear queue
246
+ assert queue.clear
247
+ # queue size is greater than zero
248
+ assert queue.size>0
249
+ # delete queue
250
+ assert queue.delete
251
+ end
252
+
253
+ def test_28_set_amazon_problems
254
+ original_problems = Rightscale::SqsGen2Interface.amazon_problems
255
+ assert(original_problems.length > 0)
256
+ Rightscale::SqsGen2Interface.amazon_problems= original_problems << "A New Problem"
257
+ new_problems = Rightscale::SqsGen2Interface.amazon_problems
258
+ assert_equal(new_problems, original_problems)
259
+
260
+ Rightscale::SqsGen2Interface.amazon_problems= nil
261
+ assert_nil(Rightscale::SqsGen2Interface.amazon_problems)
262
+ end
263
+
264
+ end