right_aws 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +3 -0
- data/Manifest.txt +21 -0
- data/README.txt +96 -0
- data/Rakefile +25 -0
- data/lib/awsbase/benchmark_fix.rb +39 -0
- data/lib/awsbase/right_awsbase.rb +231 -0
- data/lib/ec2/right_ec2.rb +1034 -0
- data/lib/right_aws.rb +63 -0
- data/lib/s3/right_s3.rb +879 -0
- data/lib/s3/right_s3_interface.rb +900 -0
- data/lib/sqs/right_sqs.rb +369 -0
- data/lib/sqs/right_sqs_interface.rb +655 -0
- data/test/awsbase/test_helper.rb +2 -0
- data/test/awsbase/test_right_awsbase.rb +12 -0
- data/test/ec2/test_helper.rb +2 -0
- data/test/ec2/test_right_ec2.rb +67 -0
- data/test/s3/test_helper.rb +2 -0
- data/test/s3/test_right_s3.rb +217 -0
- data/test/sqs/test_helper.rb +2 -0
- data/test/sqs/test_right_sqs.rb +226 -0
- data/test/test_credentials.rb +37 -0
- data/test/ts_right_aws.rb +9 -0
- metadata +102 -0
@@ -0,0 +1,67 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
require 'pp'
|
3
|
+
|
4
|
+
class TestEc2 < Test::Unit::TestCase
|
5
|
+
|
6
|
+
# Some of RightEc2 instance methods concerning instance launching and image registration
|
7
|
+
# are not tested here due to their potentially risk.
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@ec2 = Rightscale::Ec2.new(TestCredentials.aws_access_key_id,
|
11
|
+
TestCredentials.aws_secret_access_key)
|
12
|
+
@key = 'right_ec2_awesome_test_key'
|
13
|
+
@group = 'right_ec2_awesome_test_security_group'
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_01_create_describe_key_pairs
|
17
|
+
new_key = @ec2.create_key_pair(@key)
|
18
|
+
assert new_key[:aws_material][/BEGIN RSA PRIVATE KEY/], "New key material is absent"
|
19
|
+
keys = @ec2.describe_key_pairs
|
20
|
+
assert keys.map{|key| key[:aws_key_name] }.include?(@key), "#{@key} must exist"
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_02_create_security_group
|
24
|
+
assert @ec2.create_security_group(@group,'My awesone test group'), 'Create_security_group fail'
|
25
|
+
group = @ec2.describe_security_groups([@group])[0]
|
26
|
+
assert_equal @group, group[:aws_group_name], 'Group must be created but does not exist'
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_03_perms_add
|
30
|
+
assert @ec2.authorize_security_group_named_ingress(@group, TestCredentials.account_number, 'default')
|
31
|
+
assert @ec2.authorize_security_group_IP_ingress(@group, 80,80,'udp','192.168.1.0/8')
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_04_check_new_perms_exist
|
35
|
+
assert_equal 2, @ec2.describe_security_groups([@group])[0][:aws_perms].size
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_05_perms_remove
|
39
|
+
assert @ec2.revoke_security_group_IP_ingress(@group, 80,80,'udp','192.168.1.0/8')
|
40
|
+
assert @ec2.revoke_security_group_named_ingress(@group,
|
41
|
+
TestCredentials.account_number, 'default')
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_06_describe_images
|
45
|
+
images = @ec2.describe_images
|
46
|
+
assert images.size>0, 'Amazon must have at least some public images'
|
47
|
+
# unknown image
|
48
|
+
assert_raise(Rightscale::AwsError){ @ec2.describe_images(['ami-ABCDEFGH'])}
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_07_describe_instanses
|
52
|
+
assert @ec2.describe_instances
|
53
|
+
# unknown image
|
54
|
+
assert_raise(Rightscale::AwsError){ @ec2.describe_instances(['i-ABCDEFGH'])}
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_08_delete_security_group
|
58
|
+
assert @ec2.delete_security_group(@group), 'Delete_security_group fail'
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_09_delete_key_pair
|
62
|
+
assert @ec2.delete_key_pair(@key), 'Delete_key_pair fail'
|
63
|
+
# key must be deleted already
|
64
|
+
assert_raise(Rightscale::AwsError) { @ec2.delete_key_pair(@key) }
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,217 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TestS3 < Test::Unit::TestCase
|
4
|
+
|
5
|
+
RIGHT_OBJECT_TEXT = 'Right test message'
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@s3 = Rightscale::S3Interface.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
|
9
|
+
@bucket = 'right_s3_awesome_test_bucket'
|
10
|
+
@key1 = 'test/woohoo1'
|
11
|
+
@key2 = 'test1/key/woohoo2'
|
12
|
+
@s = Rightscale::S3.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
|
13
|
+
end
|
14
|
+
|
15
|
+
#---------------------------
|
16
|
+
# Rightscale::S3Interface
|
17
|
+
#---------------------------
|
18
|
+
|
19
|
+
def test_01_create_bucket
|
20
|
+
assert @s3.create_bucket(@bucket), 'Create_bucket fail'
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_02_list_all_my_buckets
|
24
|
+
assert @s3.list_all_my_buckets.map{|bucket| bucket[:name]}.include?(@bucket), "#{@bucket} must exist in bucket list"
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_03_list_empty_bucket
|
28
|
+
assert_equal 0, @s3.list_bucket(@bucket).size, "#{@queue_name} must exist!"
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_04_put
|
32
|
+
assert @s3.put(@bucket, @key1, RIGHT_OBJECT_TEXT, 'x-amz-meta-family'=>'Woohoo1!'), 'Put bucket fail'
|
33
|
+
assert @s3.put(@bucket, @key2, RIGHT_OBJECT_TEXT, 'x-amz-meta-family'=>'Woohoo2!'), 'Put bucket fail'
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_05_get_and_get_object
|
37
|
+
assert_raise(Rightscale::AwsError) { @s3.get(@bucket, 'undefined/key') }
|
38
|
+
data1 = @s3.get(@bucket, @key1)
|
39
|
+
assert_equal RIGHT_OBJECT_TEXT, data1[:object], "Object text must be equal to '#{RIGHT_OBJECT_TEXT}'"
|
40
|
+
assert_equal RIGHT_OBJECT_TEXT, @s3.get_object(@bucket, @key1), "Get_object text must return '#{RIGHT_OBJECT_TEXT}'"
|
41
|
+
assert_equal 'Woohoo1!', data1[:headers]['x-amz-meta-family'], "x-amz-meta-family header must be equal to 'Woohoo1!'"
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_06_head
|
45
|
+
assert_equal 'Woohoo1!', @s3.head(@bucket,@key1)['x-amz-meta-family'], "x-amz-meta-family header must be equal to 'Woohoo1!'"
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_07_delete_folder
|
49
|
+
assert_equal 1, @s3.delete_folder(@bucket, 'test').size, "Only one key(#{@key1}) must be deleted!"
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_08_delete_bucket
|
53
|
+
assert_raise(Rightscale::AwsError) { @s3.delete_bucket(@bucket) }
|
54
|
+
assert @s3.clear_bucket(@bucket), 'Clear_bucket fail'
|
55
|
+
assert_equal 0, @s3.list_bucket(@bucket).size, 'Bucket must be empty'
|
56
|
+
assert @s3.delete_bucket(@bucket)
|
57
|
+
assert !@s3.list_all_my_buckets.map{|bucket| bucket[:name]}.include?(@bucket), "#{@bucket} must not exist"
|
58
|
+
end
|
59
|
+
|
60
|
+
#---------------------------
|
61
|
+
# Rightscale::S3 classes
|
62
|
+
#---------------------------
|
63
|
+
|
64
|
+
def test_20_s3
|
65
|
+
# create bucket
|
66
|
+
bucket = @s.bucket(@bucket, true)
|
67
|
+
assert bucket
|
68
|
+
# check that the bucket exists
|
69
|
+
assert @s.buckets.map{|b| b.name}.include?(@bucket)
|
70
|
+
# delete bucket
|
71
|
+
assert bucket.clear
|
72
|
+
assert bucket.delete
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_21_bucket_create_put_get_key
|
76
|
+
bucket = Rightscale::S3::Bucket.create(@s, @bucket, true)
|
77
|
+
# check that the bucket exists
|
78
|
+
assert @s.buckets.map{|b| b.name}.include?(@bucket)
|
79
|
+
assert bucket.keys.empty?
|
80
|
+
# put data
|
81
|
+
assert bucket.put(@key1, RIGHT_OBJECT_TEXT, {'family'=>'123456'})
|
82
|
+
# get data and compare
|
83
|
+
assert_equal RIGHT_OBJECT_TEXT, bucket.get(@key1)
|
84
|
+
# get key object
|
85
|
+
key = bucket.key(@key1, true)
|
86
|
+
assert_equal Rightscale::S3::Key, key.class
|
87
|
+
assert key.exists?
|
88
|
+
assert_equal '123456', key.meta_headers['family']
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_22_keys
|
92
|
+
bucket = Rightscale::S3::Bucket.create(@s, @bucket, false)
|
93
|
+
# create first key
|
94
|
+
key1 = Rightscale::S3::Key.create(bucket, @key1)
|
95
|
+
key1.refresh
|
96
|
+
assert key1.exists?
|
97
|
+
assert_equal '123456', key1.meta_headers['family']
|
98
|
+
# create second key
|
99
|
+
key2 = Rightscale::S3::Key.create(bucket, @key2)
|
100
|
+
assert !key2.refresh
|
101
|
+
assert !key2.exists?
|
102
|
+
assert_raise(Rightscale::AwsError) { key2.head }
|
103
|
+
# store key
|
104
|
+
key2.meta_headers = {'family'=>'111222333'}
|
105
|
+
assert key2.put(RIGHT_OBJECT_TEXT)
|
106
|
+
# make sure that the key exists
|
107
|
+
assert key2.refresh
|
108
|
+
assert key2.exists?
|
109
|
+
assert key2.head
|
110
|
+
# get its data
|
111
|
+
assert_equal RIGHT_OBJECT_TEXT, key2.get
|
112
|
+
# drop key
|
113
|
+
assert key2.delete
|
114
|
+
assert !key2.exists?
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_23_clear_delete
|
118
|
+
bucket = Rightscale::S3::Bucket.create(@s, @bucket, false)
|
119
|
+
# add another key
|
120
|
+
bucket.put(@key2, RIGHT_OBJECT_TEXT)
|
121
|
+
# delete 'folder'
|
122
|
+
assert_equal 1, bucket.delete_folder(@key1).size
|
123
|
+
# delete
|
124
|
+
assert_raise(Rightscale::AwsError) { bucket.delete }
|
125
|
+
bucket.delete(true)
|
126
|
+
end
|
127
|
+
|
128
|
+
# Grantees
|
129
|
+
|
130
|
+
def test_30_create_bucket
|
131
|
+
bucket = @s.bucket(@bucket, true, 'public-read')
|
132
|
+
assert bucket
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_31_list_grantees
|
136
|
+
bucket = Rightscale::S3::Bucket.create(@s, @bucket, false)
|
137
|
+
# get grantees list
|
138
|
+
grantees = bucket.grantees
|
139
|
+
# check that the grantees count equal to 2 (root, AllUsers)
|
140
|
+
assert_equal 2, grantees.size
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_32_grant_revoke_drop
|
144
|
+
bucket = Rightscale::S3::Bucket.create(@s, @bucket, false)
|
145
|
+
grantees = bucket.grantees
|
146
|
+
# Take one of grantees
|
147
|
+
grantee = grantees[0]
|
148
|
+
# Add grant as String
|
149
|
+
assert grantee.grant('WRITE')
|
150
|
+
# Add grants as Array
|
151
|
+
assert grantee.grant(['READ_ACP', 'WRITE_ACP'])
|
152
|
+
# Check perms count
|
153
|
+
assert_equal 4, grantee.perms.size
|
154
|
+
# revoke 'WRITE_ACP'
|
155
|
+
assert grantee.revoke('WRITE_ACP')
|
156
|
+
# Check manual perm removal method
|
157
|
+
grantee.perms -= ['READ_ACP']
|
158
|
+
grantee.apply
|
159
|
+
assert_equal 2, grantee.perms.size
|
160
|
+
# check 'Drop' method
|
161
|
+
assert grantee.drop
|
162
|
+
assert_equal 1, bucket.grantees.size
|
163
|
+
# Delete bucket
|
164
|
+
bucket.delete(true)
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_33_key_grantees
|
168
|
+
# Create bucket
|
169
|
+
bucket = @s.bucket(@bucket, true)
|
170
|
+
# Create key
|
171
|
+
key = bucket.key(@key1)
|
172
|
+
assert key.put(RIGHT_OBJECT_TEXT, 'public-read')
|
173
|
+
# Get grantees list (must be == 2)
|
174
|
+
grantees = key.grantees
|
175
|
+
assert grantees
|
176
|
+
assert_equal 2, grantees.size
|
177
|
+
# Take one of grantees and give him 'Write' perms
|
178
|
+
grantee = grantees[0]
|
179
|
+
assert grantee.grant('WRITE')
|
180
|
+
# Drop grantee
|
181
|
+
assert grantee.drop
|
182
|
+
# Drop bucket
|
183
|
+
bucket.delete(true)
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_34_bucket_create_put_with_perms
|
187
|
+
bucket = Rightscale::S3::Bucket.create(@s, @bucket, true)
|
188
|
+
# check that the bucket exists
|
189
|
+
assert @s.buckets.map{|b| b.name}.include?(@bucket)
|
190
|
+
assert bucket.keys.empty?
|
191
|
+
# put data (with canned ACL)
|
192
|
+
assert bucket.put(@key1, RIGHT_OBJECT_TEXT, {'family'=>'123456'}, "public-read")
|
193
|
+
# get data and compare
|
194
|
+
assert_equal RIGHT_OBJECT_TEXT, bucket.get(@key1)
|
195
|
+
# get key object
|
196
|
+
key = bucket.key(@key1, true)
|
197
|
+
assert_equal Rightscale::S3::Key, key.class
|
198
|
+
assert key.exists?
|
199
|
+
assert_equal '123456', key.meta_headers['family']
|
200
|
+
end
|
201
|
+
|
202
|
+
def test_35_key_put_with_perms
|
203
|
+
bucket = Rightscale::S3::Bucket.create(@s, @bucket, false)
|
204
|
+
# create first key
|
205
|
+
key1 = Rightscale::S3::Key.create(bucket, @key1)
|
206
|
+
key1.refresh
|
207
|
+
assert key1.exists?
|
208
|
+
assert key1.put(RIGHT_OBJECT_TEXT, "public-read")
|
209
|
+
# get its data
|
210
|
+
assert_equal RIGHT_OBJECT_TEXT, key1.get
|
211
|
+
# drop key
|
212
|
+
assert key1.delete
|
213
|
+
assert !key1.exists?
|
214
|
+
end
|
215
|
+
|
216
|
+
|
217
|
+
end
|
@@ -0,0 +1,226 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TestSqs < Test::Unit::TestCase
|
4
|
+
|
5
|
+
GRANTEE_EMAIL_ADDRESS = 'fester@example.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
|
+
#---------------------------
|
17
|
+
# Rightscale::SqsInterface
|
18
|
+
#---------------------------
|
19
|
+
|
20
|
+
def test_01_create_queue
|
21
|
+
queue_url = @sqs.create_queue @queue_name
|
22
|
+
assert queue_url[/http.*#{@queue_name}/], 'New queue creation fail'
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_02_list_queues
|
26
|
+
queues = @sqs.list_queues('right_')
|
27
|
+
assert queues.size>0, 'Must more that 0 queues in list'
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_03_set_and_get_queue_attributes
|
31
|
+
queue_url = @sqs.queue_url_by_name(@queue_name)
|
32
|
+
assert queue_url[/http.*#{@queue_name}/], "#{@queue_name} must exist!"
|
33
|
+
assert @sqs.set_queue_attributes(queue_url, 'VisibilityTimeout', 111), 'Set_queue_attributes fail'
|
34
|
+
sleep 5 # Amazon needs some time to change attribute
|
35
|
+
assert_equal '111', @sqs.get_queue_attributes(queue_url)['VisibilityTimeout'], 'New VisibilityTimeout must be equal to 111'
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_04_set_and_get_visibility_timeout
|
39
|
+
queue_url = @sqs.queue_url_by_name(@queue_name)
|
40
|
+
assert @sqs.set_visibility_timeout(queue_url, 222), 'Set_visibility_timeout fail'
|
41
|
+
assert_equal 222, @sqs.get_visibility_timeout(queue_url), 'Get_visibility_timeout must return to 222'
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_05_add_test_remove_grant
|
45
|
+
queue_url = @sqs.queue_url_by_name(@queue_name)
|
46
|
+
assert @sqs.add_grant(queue_url, GRANTEE_EMAIL_ADDRESS, 'FULLCONTROL'), 'Add grant fail'
|
47
|
+
grants_list = @sqs.list_grants(queue_url, GRANTEE_EMAIL_ADDRESS)
|
48
|
+
assert grants_list.size>0, 'List_grants must return at least 1 record for user #{GRANTEE_EMAIL_ADDRESS}'
|
49
|
+
assert @sqs.remove_grant(queue_url, GRANTEE_EMAIL_ADDRESS, 'FULLCONTROL'), 'Remove_grant fail'
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_06_send_message
|
53
|
+
queue_url = @sqs.queue_url_by_name(@queue_name)
|
54
|
+
# send 5 messages for the tests below
|
55
|
+
assert @sqs.send_message(queue_url, RIGHT_MESSAGE_TEXT)
|
56
|
+
assert @sqs.send_message(queue_url, RIGHT_MESSAGE_TEXT)
|
57
|
+
assert @sqs.send_message(queue_url, RIGHT_MESSAGE_TEXT)
|
58
|
+
assert @sqs.send_message(queue_url, RIGHT_MESSAGE_TEXT)
|
59
|
+
assert @sqs.send_message(queue_url, RIGHT_MESSAGE_TEXT)
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_07_get_queue_length
|
63
|
+
queue_url = @sqs.queue_url_by_name(@queue_name)
|
64
|
+
assert_equal 5, @sqs.get_queue_length(queue_url), 'Queue must have 5 messages'
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_08_receive_message
|
68
|
+
queue_url = @sqs.queue_url_by_name(@queue_name)
|
69
|
+
r_message = @sqs.receive_message(queue_url, 1)
|
70
|
+
assert_equal RIGHT_MESSAGE_TEXT, r_message[:body], 'Receive message get wron message text'
|
71
|
+
p_message = @sqs.peek_message(queue_url, r_message[:id])
|
72
|
+
assert_equal r_message[:body], p_message[:body], 'Received and Peeked messages must be equal'
|
73
|
+
assert @sqs.change_message_visibility(queue_url, r_message[:id], 0), 'Change_message_visibility fail'
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_09_delete_message
|
77
|
+
queue_url = @sqs.queue_url_by_name(@queue_name)
|
78
|
+
message = @sqs.receive_message(queue_url)
|
79
|
+
assert @sqs.delete_message(queue_url, message[:id]), 'Delete_message fail'
|
80
|
+
assert @sqs.pop_message(queue_url), 'Pop_message fail'
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_10_clear_and_delete_queue
|
84
|
+
queue_url = @sqs.queue_url_by_name(@queue_name)
|
85
|
+
assert_raise(Rightscale::AwsError) { @sqs.delete_queue(queue_url) }
|
86
|
+
assert @sqs.force_clear_queue(queue_url), 'Force_clear_queue fail'
|
87
|
+
assert @sqs.delete_queue(queue_url), 'Delete_queue fail'
|
88
|
+
end
|
89
|
+
|
90
|
+
#---------------------------
|
91
|
+
# Rightscale::Sqs classes
|
92
|
+
#---------------------------
|
93
|
+
|
94
|
+
def test_20_sqs_create_delete_queue
|
95
|
+
assert @s, 'Rightscale::Sqs must exist'
|
96
|
+
# get queues list
|
97
|
+
queues = @s.queues
|
98
|
+
# create new queue
|
99
|
+
queue = @s.queue("#{@queue_name}_20", true)
|
100
|
+
# check that it is created
|
101
|
+
assert queue.is_a?(Rightscale::Sqs::Queue)
|
102
|
+
# check that amount of queues has increased
|
103
|
+
assert_equal queues.size+1, @s.queues.size
|
104
|
+
# delete queue
|
105
|
+
assert queue.delete
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_21_queue_create
|
109
|
+
# create new queue
|
110
|
+
queue = Rightscale::Sqs::Queue.create(@s, "#{@queue_name}_21", true)
|
111
|
+
# check that it is created
|
112
|
+
assert queue.is_a?(Rightscale::Sqs::Queue)
|
113
|
+
# Don't test this - just for cleanup purposes
|
114
|
+
queue.delete
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_22_queue_attributes
|
118
|
+
queue = Rightscale::Sqs::Queue.create(@s, "#{@queue_name}_22", false)
|
119
|
+
# get a list of attrinutes
|
120
|
+
attributes = queue.get_attribute
|
121
|
+
assert attributes.is_a?(Hash) && attributes.size>0
|
122
|
+
# get attribute value and increase it by 10
|
123
|
+
v = (queue.get_attribute('VisibilityTimeout').to_i + 10).to_s
|
124
|
+
# set attribute
|
125
|
+
assert queue.set_attribute('VisibilityTimeout', v)
|
126
|
+
# wait a bit
|
127
|
+
sleep 5
|
128
|
+
# check that attribute has changed
|
129
|
+
assert_equal v, queue.get_attribute('VisibilityTimeout')
|
130
|
+
# get queue visibility timeout
|
131
|
+
assert v.to_i, queue.visibility
|
132
|
+
# change it
|
133
|
+
queue.visibility += 10
|
134
|
+
# make sure that it is changed
|
135
|
+
assert v.to_i + 10, queue.visibility
|
136
|
+
# Don't test this - just for cleanup purposes
|
137
|
+
queue.delete
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_23_grantees
|
141
|
+
queue = Rightscale::Sqs::Queue.create(@s, "#{@queue_name}_23", false)
|
142
|
+
# get a list of grantees
|
143
|
+
grantees = queue.grantees
|
144
|
+
# create new grantee
|
145
|
+
grantee = Rightscale::Sqs::Grantee.new(queue, GRANTEE_EMAIL_ADDRESS)
|
146
|
+
assert grantee.perms.empty?
|
147
|
+
# grant perms
|
148
|
+
assert grantee.grant('FULLCONTROL')
|
149
|
+
assert grantee.grant('RECEIVEMESSAGE')
|
150
|
+
assert_equal 2, grantee.perms.size
|
151
|
+
# make sure that amount of grantees has increased
|
152
|
+
assert grantees.size < queue.grantees.size
|
153
|
+
# revoke perms
|
154
|
+
assert grantee.revoke('RECEIVEMESSAGE')
|
155
|
+
assert_equal 1, grantee.perms.size
|
156
|
+
# remove grantee
|
157
|
+
assert grantee.drop
|
158
|
+
# Don't test this - just for cleanup purposes
|
159
|
+
queue.delete
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_24_send_size
|
163
|
+
queue = Rightscale::Sqs::Queue.create(@s, "#{@queue_name}_24", false)
|
164
|
+
# send 5 messages
|
165
|
+
assert queue.push('a1')
|
166
|
+
assert queue.push('a2')
|
167
|
+
assert queue.push('a3')
|
168
|
+
assert queue.push('a4')
|
169
|
+
assert queue.push('a5')
|
170
|
+
# check queue size
|
171
|
+
assert_equal 5, queue.size
|
172
|
+
# send one more
|
173
|
+
assert queue.push('a6')
|
174
|
+
# check queue size again
|
175
|
+
assert_equal 6, queue.size
|
176
|
+
# Don't test this - just for cleanup purposes
|
177
|
+
queue.clear
|
178
|
+
queue.delete
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_25_message_receive_pop_peek_delete
|
182
|
+
queue = Rightscale::Sqs::Queue.create(@s, "#{@queue_name}_25", false)
|
183
|
+
# get queue size
|
184
|
+
size = queue.size
|
185
|
+
# get first message
|
186
|
+
m1 = queue.receive(10)
|
187
|
+
assert m1.is_a?(Rightscale::Sqs::Message)
|
188
|
+
# pop second message
|
189
|
+
m2 = queue.pop
|
190
|
+
assert m2.is_a?(Rightscale::Sqs::Message)
|
191
|
+
# make sure that queue size has decreased
|
192
|
+
assert_equal size-1, queue.size
|
193
|
+
# peek message 1
|
194
|
+
m1p = queue.peek(m1.id)
|
195
|
+
assert m1p.is_a?(Rightscale::Sqs::Message)
|
196
|
+
assert_equal m1.id, m1p.id
|
197
|
+
assert_equal m1.body, m1p.body
|
198
|
+
# change message visibility
|
199
|
+
assert m1.visibility = 30
|
200
|
+
# delete messsage
|
201
|
+
assert m1.delete
|
202
|
+
# make sure that queue size has decreased again
|
203
|
+
assert_equal size-2, queue.size
|
204
|
+
# Don't test this - just for cleanup purposes
|
205
|
+
queue.delete
|
206
|
+
end
|
207
|
+
|
208
|
+
def test_26
|
209
|
+
queue = Rightscale::Sqs::Queue.create(@s, "#{@queue_name}_26", false)
|
210
|
+
# lock message
|
211
|
+
queue.receive(100)
|
212
|
+
# clear queue
|
213
|
+
assert queue.clear
|
214
|
+
# queue size is greater than zero
|
215
|
+
assert queue.size>0
|
216
|
+
# force clear queue
|
217
|
+
assert queue.clear(true)
|
218
|
+
# queue size must be equal to zero
|
219
|
+
assert queue.size==0
|
220
|
+
# push new message
|
221
|
+
queue.push('123456')
|
222
|
+
assert_raise(Rightscale::AwsError) { queue.delete }
|
223
|
+
assert queue.delete(true)
|
224
|
+
end
|
225
|
+
|
226
|
+
end
|