hackerdude-aws 2.3.25
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +187 -0
- data/lib/acf/right_acf_interface.rb +383 -0
- data/lib/alexa/alexa.rb +239 -0
- data/lib/aws.rb +30 -0
- data/lib/awsbase/aws_response_array.rb +30 -0
- data/lib/awsbase/benchmark_fix.rb +39 -0
- data/lib/awsbase/right_awsbase.rb +1239 -0
- data/lib/awsbase/support.rb +149 -0
- data/lib/ec2/right_ec2.rb +1874 -0
- data/lib/ec2/right_mon_interface.rb +233 -0
- data/lib/elb/elb_interface.rb +359 -0
- data/lib/rds/rds.rb +216 -0
- data/lib/right_aws.rb +57 -0
- data/lib/s3/right_s3.rb +1110 -0
- data/lib/s3/right_s3_interface.rb +1235 -0
- data/lib/sdb/active_sdb.rb +990 -0
- data/lib/sdb/right_sdb_interface.rb +816 -0
- data/lib/sqs/right_sqs.rb +287 -0
- data/lib/sqs/right_sqs_interface.rb +445 -0
- data/test/acf/test_acf.rb +148 -0
- data/test/acf/test_helper.rb +2 -0
- data/test/alexa/test_alexa.rb +53 -0
- data/test/alexa/test_helper.rb +2 -0
- data/test/ec2/test_ec2.rb +205 -0
- data/test/ec2/test_helper.rb +2 -0
- data/test/ec2/test_mon.rb +17 -0
- data/test/elb/test_elb.rb +51 -0
- data/test/http_connection.rb +87 -0
- data/test/rds/test_rds.rb +181 -0
- data/test/s3/test_helper.rb +3 -0
- data/test/s3/test_s3.rb +425 -0
- data/test/s3/test_s3_stubbed.rb +97 -0
- data/test/sdb/test_active_sdb.rb +338 -0
- data/test/sdb/test_helper.rb +3 -0
- data/test/sdb/test_sdb.rb +207 -0
- data/test/sqs/test_helper.rb +2 -0
- data/test/sqs/test_sqs.rb +206 -0
- data/test/test_credentials.rb +54 -0
- data/test/ts_right_aws.rb +13 -0
- metadata +182 -0
@@ -0,0 +1,97 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
require File.dirname(__FILE__) + '/../test_credentials.rb'
|
3
|
+
|
4
|
+
class TestS3Stubbed < Test::Unit::TestCase
|
5
|
+
|
6
|
+
RIGHT_OBJECT_TEXT = 'Right test message'
|
7
|
+
|
8
|
+
def setup
|
9
|
+
TestCredentials.get_credentials
|
10
|
+
@s3 = Aws::S3Interface.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
|
11
|
+
@bucket = 'right_s3_awesome_test_bucket'
|
12
|
+
@key1 = 'test/woohoo1'
|
13
|
+
@key2 = 'test1/key/woohoo2'
|
14
|
+
@s = Aws::S3.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
|
15
|
+
Rightscale::HttpConnection.reset
|
16
|
+
end
|
17
|
+
|
18
|
+
# Non-remote tests: these use the stub version of Rightscale::HTTPConnection
|
19
|
+
def test_101_create_bucket
|
20
|
+
Rightscale::HttpConnection.push(409, 'The named bucket you tried to create already exists')
|
21
|
+
Rightscale::HttpConnection.push(500, 'We encountered an internal error. Please try again.')
|
22
|
+
Rightscale::HttpConnection.push(500, 'We encountered an internal error. Please try again.')
|
23
|
+
assert_raise Aws::AwsError do
|
24
|
+
@s3.create_bucket(@bucket)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_102_list_all_my_buckets_failure
|
29
|
+
Rightscale::HttpConnection.push(401, 'Unauthorized')
|
30
|
+
assert_raise Aws::AwsError do
|
31
|
+
@s3.list_all_my_buckets
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_103_list_empty_bucket
|
36
|
+
Rightscale::HttpConnection.push(403, 'Access Denied')
|
37
|
+
assert_raise Aws::AwsError do
|
38
|
+
@s3.list_bucket(@bucket)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_104_put
|
43
|
+
Rightscale::HttpConnection.push(400, 'Your proposed upload exceeds the maximum allowed object size.')
|
44
|
+
Rightscale::HttpConnection.push(400, 'The Content-MD5 you specified was an invalid.')
|
45
|
+
Rightscale::HttpConnection.push(409, 'Please try again')
|
46
|
+
assert_raise Aws::AwsError do
|
47
|
+
assert @s3.put(@bucket, @key1, RIGHT_OBJECT_TEXT, 'x-amz-meta-family'=>'Woohoo1!'), 'Put bucket fail'
|
48
|
+
end
|
49
|
+
assert_raise Aws::AwsError do
|
50
|
+
assert @s3.put(@bucket, @key2, RIGHT_OBJECT_TEXT, 'x-amz-meta-family'=>'Woohoo2!'), 'Put bucket fail'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_105_get_and_get_object
|
55
|
+
Rightscale::HttpConnection.push(404, 'not found')
|
56
|
+
assert_raise(Rightscale::AwsError) { @s3.get(@bucket, 'undefined/key') }
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_106_head
|
60
|
+
Rightscale::HttpConnection.push(404, 'Good Luck!')
|
61
|
+
assert_raise Aws::AwsError do
|
62
|
+
@s3.head(@bucket,@key1)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
def test_109_delete_bucket
|
68
|
+
Rightscale::HttpConnection.push(403, 'Good Luck!')
|
69
|
+
assert_raise(Rightscale::AwsError) { @s3.delete_bucket(@bucket) }
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_115_copy_key
|
73
|
+
|
74
|
+
Rightscale::HttpConnection.push(500, 'not found')
|
75
|
+
#--- test COPY
|
76
|
+
# copy a key
|
77
|
+
assert_raise Aws::AwsError do
|
78
|
+
@s3.copy(@bucket, @key1, @bucket, @key1_copy)
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_116_move_key
|
84
|
+
# move a key
|
85
|
+
Rightscale::HttpConnection.push(413, 'not found')
|
86
|
+
assert @s3.move(@bucket, @key1, @bucket, @key1_new_name)
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_117_rename_key
|
91
|
+
# rename a key
|
92
|
+
Rightscale::HttpConnection.push(500, 'not found')
|
93
|
+
assert @s3.rename(@bucket, @key2, @key2_new_name)
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
@@ -0,0 +1,338 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
require File.dirname(__FILE__) + '/../test_credentials.rb'
|
3
|
+
|
4
|
+
class TestSdb < Test::Unit::TestCase
|
5
|
+
|
6
|
+
DOMAIN_NAME = 'right_sdb_awesome_test_domain'
|
7
|
+
DASH_DOMAIN_NAME = 'right_sdb-awesome_test_domain'
|
8
|
+
|
9
|
+
class Client < Aws::ActiveSdb::Base
|
10
|
+
set_domain_name DOMAIN_NAME
|
11
|
+
end
|
12
|
+
class DashClient < RightAws::ActiveSdb::Base
|
13
|
+
set_domain_name DASH_DOMAIN_NAME
|
14
|
+
end
|
15
|
+
|
16
|
+
def setup
|
17
|
+
TestCredentials.get_credentials
|
18
|
+
STDOUT.sync = true
|
19
|
+
@clients = [
|
20
|
+
{ 'name' => 'Bush', 'country' => 'USA', 'gender' => 'male', 'expiration' => '2009', 'post' => 'president' },
|
21
|
+
{ 'name' => 'Putin', 'country' => 'Russia', 'gender' => 'male', 'expiration' => '2008', 'post' => 'president' },
|
22
|
+
{ 'name' => 'Medvedev', 'country' => 'Russia', 'gender' => 'male', 'expiration' => '2012', 'post' => 'president' },
|
23
|
+
{ 'name' => 'Mary', 'country' => 'USA', 'gender' => 'female', 'hobby' => ['patchwork', 'bundle jumping'] },
|
24
|
+
{ 'name' => 'Sandy', 'country' => 'Russia', 'gender' => 'female', 'hobby' => ['flowers', 'cats', 'cooking'] },
|
25
|
+
{ 'name' => 'Mary', 'country' => 'Russia', 'gender' => 'female', 'hobby' => ['flowers', 'cats', 'cooking'] } ]
|
26
|
+
Aws::ActiveSdb.establish_connection(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
|
27
|
+
end
|
28
|
+
|
29
|
+
SDB_DELAY = 3
|
30
|
+
|
31
|
+
def wait(delay, msg='')
|
32
|
+
print " waiting #{delay} seconds: #{msg}"
|
33
|
+
while delay>0 do
|
34
|
+
delay -= 1
|
35
|
+
print '.'
|
36
|
+
sleep 1
|
37
|
+
end
|
38
|
+
puts
|
39
|
+
end
|
40
|
+
|
41
|
+
#---------------------------
|
42
|
+
# Aws::SdbInterface
|
43
|
+
#---------------------------
|
44
|
+
|
45
|
+
def test_00_delete_domain
|
46
|
+
assert Aws::ActiveSdb.delete_domain(DOMAIN_NAME)
|
47
|
+
wait SDB_DELAY, 'test 00: after domain deletion'
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_01_create_domain
|
51
|
+
# check that domain does not exist
|
52
|
+
assert !Aws::ActiveSdb.domains.include?(DOMAIN_NAME)
|
53
|
+
# create domain
|
54
|
+
assert Client.create_domain
|
55
|
+
wait SDB_DELAY, 'test 01: after domain creation'
|
56
|
+
# check that we have received new domain from Amazin
|
57
|
+
assert Aws::ActiveSdb.domains.include?(DOMAIN_NAME)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_02_create_items
|
61
|
+
# check that DB is empty
|
62
|
+
clients = Client.find(:all)
|
63
|
+
assert clients.blank?
|
64
|
+
# put some clients there
|
65
|
+
@clients.each do |client|
|
66
|
+
Client.create client
|
67
|
+
end
|
68
|
+
wait SDB_DELAY, 'test 02: after clients creation'
|
69
|
+
# check that DB has all the clients we just putted
|
70
|
+
clients = Client.find(:all)
|
71
|
+
assert_equal @clients.size, clients.size
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_03_create_and_save_new_item
|
75
|
+
# get the db
|
76
|
+
old_clients = Client.find(:all)
|
77
|
+
# create new client
|
78
|
+
new_client = Client.new('country' => 'unknown', 'dummy' => 'yes')
|
79
|
+
wait SDB_DELAY, 'test 03: after in-memory client creation'
|
80
|
+
# get the db and ensure we created the client in-memory only
|
81
|
+
assert_equal old_clients.size, Client.find(:all).size
|
82
|
+
# put the client to DB
|
83
|
+
new_client.save
|
84
|
+
wait SDB_DELAY, 'test 03: after in-memory client saving'
|
85
|
+
# get all db again and compare to original list
|
86
|
+
assert_equal old_clients.size+1, Client.find(:all).size
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_04_find_all
|
90
|
+
# retrieve all the DB, make sure all are in place
|
91
|
+
clients = Client.find(:all)
|
92
|
+
ids = clients.map{|client| client.id }[0..1]
|
93
|
+
assert_equal @clients.size + 1, clients.size
|
94
|
+
# retrieve all presidents (must find: Bush, Putin, Medvedev)
|
95
|
+
assert_equal 3, Client.find(:all, :conditions => ["post=?",'president']).size
|
96
|
+
# retrieve all russian presidents (must find: Putin, Medvedev)
|
97
|
+
assert_equal 2, Client.find(:all, :conditions => ["post=? and country=?",'president', 'Russia']).size
|
98
|
+
# retrieve all russian presidents and all women (must find: Putin, Medvedev, 2 Maries and Sandy)
|
99
|
+
assert_equal 5, Client.find(:all, :conditions => ["post=? and country=? or gender=?",'president', 'Russia','female']).size
|
100
|
+
# find all rissian presidents Bushes
|
101
|
+
assert_equal 0, Client.find(:all, :conditions => ["post=? and country=? and name=?",'president', 'Russia','Bush']).size
|
102
|
+
# --- find by ids
|
103
|
+
# must find 1 rec (by rec id) and return it
|
104
|
+
assert_equal ids.first, Client.find(ids.first).id
|
105
|
+
# must find 1 rec (by one item array) and return an array
|
106
|
+
assert_equal ids.first, Client.find([ids.first]).first.id
|
107
|
+
# must find 2 recs (by a list of comma separated ids) and return an array
|
108
|
+
assert_equal ids.size, Client.find(*ids).size
|
109
|
+
# must find 2 recs (by an array of ids) and return an array
|
110
|
+
assert_equal ids.size, Client.find(ids).size
|
111
|
+
ids << 'dummy_id'
|
112
|
+
# must raise an error when getting unexistent record
|
113
|
+
assert_raise(Aws::ActiveSdb::ActiveSdbError) do
|
114
|
+
Client.find(ids)
|
115
|
+
end
|
116
|
+
# find one record by unknown id
|
117
|
+
assert_raise(Aws::ActiveSdb::ActiveSdbError) do
|
118
|
+
Client.find('dummy_id')
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_04b_find_all_dashed
|
123
|
+
# retrieve all the DB, make sure all are in place
|
124
|
+
clients = DashClient.find(:all)
|
125
|
+
ids = clients.map{|client| client.id }[0..1]
|
126
|
+
assert_equal @clients.size + 1, clients.size
|
127
|
+
# retrieve all presidents (must find: Bush, Putin, Medvedev)
|
128
|
+
assert_equal 3, DashedClient.find(:all, :conditions => ["[?=?]",'post','president']).size
|
129
|
+
# retrieve all russian presidents (must find: Putin, Medvedev)
|
130
|
+
assert_equal 2, DashedClient.find(:all, :conditions => ["['post'=?] intersection ['country'=?]",'president', 'Russia']).size
|
131
|
+
# retrieve all russian presidents and all women (must find: Putin, Medvedev, 2 Maries and Sandy)
|
132
|
+
assert_equal 5, DashedClient.find(:all, :conditions => ["['post'=?] intersection ['country'=?] union ['gender'=?]",'president', 'Russia','female']).size
|
133
|
+
# find all rissian presidents Bushes
|
134
|
+
assert_equal 0, DashedClient.find(:all, :conditions => ["['post'=?] intersection ['country'=?] intersection ['name'=?]",'president', 'Russia','Bush']).size
|
135
|
+
# --- find by ids
|
136
|
+
# must find 1 rec (by rec id) and return it
|
137
|
+
assert_equal ids.first, DashedClient.find(ids.first).id
|
138
|
+
# must find 1 rec (by one item array) and return an array
|
139
|
+
assert_equal ids.first, DashedClient.find([ids.first]).first.id
|
140
|
+
# must find 2 recs (by a list of comma separated ids) and return an array
|
141
|
+
assert_equal ids.size, DashedClient.find(*ids).size
|
142
|
+
# must find 2 recs (by an array of ids) and return an array
|
143
|
+
assert_equal ids.size, DashedClient.find(ids).size
|
144
|
+
ids << 'dummy_id'
|
145
|
+
# must raise an error when getting unexistent record
|
146
|
+
assert_raise(RightAws::ActiveSdb::ActiveSdbError) do
|
147
|
+
DashedClient.find(ids)
|
148
|
+
end
|
149
|
+
# find one record by unknown id
|
150
|
+
assert_raise(RightAws::ActiveSdb::ActiveSdbError) do
|
151
|
+
DashedClient.find('dummy_id')
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_05_find_first
|
156
|
+
# find any record
|
157
|
+
assert Client.find(:first)
|
158
|
+
# find any president
|
159
|
+
assert Client.find(:first, :conditions => ["post=? and country=?",'president','Russia'])
|
160
|
+
# find any rissian president
|
161
|
+
assert_nil Client.find(:first, :conditions => ["post=? and country=?",'president','Rwanda'])
|
162
|
+
# find any unexistent record
|
163
|
+
assert Client.find(:first, :conditions => ["?=?",'post','president'])
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_06_find_all_by_helpers
|
167
|
+
# find all Bushes
|
168
|
+
assert_equal 1, Client.find_all_by_name('Bush').size
|
169
|
+
# find all russian presidents
|
170
|
+
assert_equal 2, Client.find_all_by_post_and_country('president','Russia').size
|
171
|
+
# find all women in USA that love flowers
|
172
|
+
assert_equal 2, Client.find_all_by_gender_and_country_and_hobby('female','Russia','flowers').size
|
173
|
+
# order and auto_load:
|
174
|
+
clients = Client.find_all_by_post('president', :order => 'name', :auto_load => true)
|
175
|
+
assert_equal [['Bush'], ['Medvedev'], ['Putin']], clients.map{|c| c['name']}
|
176
|
+
clients = Client.find_all_by_post('president', :order => 'name desc', :auto_load => true)
|
177
|
+
assert_equal [['Putin'], ['Medvedev'], ['Bush']], clients.map{|c| c['name']}
|
178
|
+
end
|
179
|
+
|
180
|
+
def test_07_find_by_helpers
|
181
|
+
# find mr Bush
|
182
|
+
assert Client.find_by_name('Bush')
|
183
|
+
# find any russian president
|
184
|
+
assert Client.find_by_post_and_country('president','Russia')
|
185
|
+
# find Mary in Russia that loves flowers
|
186
|
+
# order and auto_load:
|
187
|
+
assert_equal ['Bush'], Client.find_by_post('president', :order => 'name', :auto_load => true)['name']
|
188
|
+
assert_equal ['Putin'], Client.find_by_post('president', :order => 'name desc', :auto_load => true)['name']
|
189
|
+
end
|
190
|
+
|
191
|
+
def test_08_reload
|
192
|
+
putin = Client.find_by_name('Putin')
|
193
|
+
# attributes must be empty until reload (except 'id' field)
|
194
|
+
assert_nil putin['name']
|
195
|
+
assert_nil putin['country']
|
196
|
+
assert_nil putin['gender']
|
197
|
+
assert_nil putin['expiration']
|
198
|
+
assert_nil putin['post']
|
199
|
+
# reloaded attributes must have 5 items + id
|
200
|
+
putin.reload
|
201
|
+
assert_equal 6, putin.attributes.size
|
202
|
+
# check all attributes
|
203
|
+
assert_equal ['Putin'], putin['name']
|
204
|
+
assert_equal ['Russia'], putin['country']
|
205
|
+
assert_equal ['male'], putin['gender']
|
206
|
+
assert_equal ['2008'], putin['expiration']
|
207
|
+
assert_equal ['president'], putin['post']
|
208
|
+
end
|
209
|
+
|
210
|
+
def test_09_select
|
211
|
+
# select all records
|
212
|
+
assert_equal 7, Client.select(:all).size
|
213
|
+
# LIMIT
|
214
|
+
# 1 record
|
215
|
+
assert Client.select(:first).is_a?(Client)
|
216
|
+
# select 2 recs
|
217
|
+
assert_equal 2, Client.select(:all, :limit => 2).size
|
218
|
+
# ORDER
|
219
|
+
# select all recs ordered by 'expration' (must find only recs where 'expration' attribute presents)
|
220
|
+
result = Client.select(:all, :order => 'expiration')
|
221
|
+
assert_equal 3, result.size
|
222
|
+
assert_equal ['2008', '2009', '2012'], result.map{ |c| c['expiration'] }.flatten
|
223
|
+
# desc order
|
224
|
+
result = Client.select(:all, :order => 'expiration desc')
|
225
|
+
assert_equal ['2012', '2009', '2008'], result.map{ |c| c['expiration'] }.flatten
|
226
|
+
# CONDITIONS
|
227
|
+
result = Client.select(:all, :conditions => ["expiration >= ?", 2009], :order => 'name')
|
228
|
+
assert_equal ['Bush', 'Medvedev'], result.map{ |c| c['name'] }.flatten
|
229
|
+
result = Client.select(:all, :conditions => "hobby='flowers' AND gender='female'", :order => 'name')
|
230
|
+
assert_equal ['Mary', 'Sandy'], result.map{ |c| c['name'] }.flatten
|
231
|
+
# SELECT
|
232
|
+
result = Client.select(:all, :select => 'hobby', :conditions => "gender IS NOT NULL", :order => 'name')
|
233
|
+
hobbies = result.map{|c| c['hobby']}
|
234
|
+
# must return all recs
|
235
|
+
assert_equal 6, result.size
|
236
|
+
# but anly 3 of them have this field set
|
237
|
+
assert_equal 3, hobbies.compact.size
|
238
|
+
end
|
239
|
+
|
240
|
+
def test_10_select_by
|
241
|
+
assert_equal 2, Client.select_all_by_hobby('flowers').size
|
242
|
+
assert_equal 2, Client.select_all_by_hobby_and_country('flowers', 'Russia').size
|
243
|
+
assert_equal ['Putin'], Client.select_by_post_and_expiration('president','2008')['name']
|
244
|
+
end
|
245
|
+
|
246
|
+
def test_11_save_and_put
|
247
|
+
putin = Client.find_by_name('Putin')
|
248
|
+
putin.reload
|
249
|
+
putin['hobby'] = 'ski'
|
250
|
+
# SAVE method (replace values)
|
251
|
+
putin.save
|
252
|
+
wait SDB_DELAY, 'test 09: after saving'
|
253
|
+
# check that DB was updated with 'ski'
|
254
|
+
new_putin = Client.find_by_name('Putin')
|
255
|
+
new_putin.reload
|
256
|
+
assert ['ski'], new_putin['hobby']
|
257
|
+
# replace hobby
|
258
|
+
putin['hobby'] = 'dogs'
|
259
|
+
putin.save
|
260
|
+
wait SDB_DELAY, 'test 09: after saving'
|
261
|
+
# check that 'ski' in DB was replaced by 'dogs'
|
262
|
+
new_putin = Client.find_by_name('Putin')
|
263
|
+
new_putin.reload
|
264
|
+
assert ['dogs'], new_putin['hobby']
|
265
|
+
# PUT method (add values)
|
266
|
+
putin['hobby'] = 'ski'
|
267
|
+
putin.put
|
268
|
+
wait SDB_DELAY, 'test 09: after putting'
|
269
|
+
# check that 'ski' was added to 'dogs'
|
270
|
+
new_putin = Client.find_by_name('Putin')
|
271
|
+
new_putin.reload
|
272
|
+
assert ['dogs', 'ski'], new_putin['hobby'].sort
|
273
|
+
end
|
274
|
+
|
275
|
+
def test_12_save_and_put_attributes
|
276
|
+
putin = Client.find_by_name('Putin')
|
277
|
+
putin.reload
|
278
|
+
# SAVE method (replace values)
|
279
|
+
putin.save_attributes('language' => 'russian')
|
280
|
+
wait SDB_DELAY, 'test 10: after save_attributes'
|
281
|
+
# check that DB was updated with 'ski'
|
282
|
+
new_putin = Client.find_by_name('Putin')
|
283
|
+
new_putin.reload
|
284
|
+
assert ['russian'], new_putin['language']
|
285
|
+
# replace 'russian' by 'german'
|
286
|
+
putin.save_attributes('language' => 'german')
|
287
|
+
wait SDB_DELAY, 'test 10: after save_attributes'
|
288
|
+
# check that 'russian' in DB was replaced by 'german'
|
289
|
+
new_putin = Client.find_by_name('Putin')
|
290
|
+
new_putin.reload
|
291
|
+
assert ['german'], new_putin['language']
|
292
|
+
# PUT method (add values)
|
293
|
+
putin.put_attributes('language' => ['russian', 'english'])
|
294
|
+
wait SDB_DELAY, 'test 10: after put_attributes'
|
295
|
+
# now Putin must know all the languages
|
296
|
+
new_putin = Client.find_by_name('Putin')
|
297
|
+
new_putin.reload
|
298
|
+
assert ['english', 'german', 'russian'], new_putin['language'].sort
|
299
|
+
end
|
300
|
+
|
301
|
+
def test_13_delete
|
302
|
+
putin = Client.find_by_name('Putin')
|
303
|
+
putin.reload
|
304
|
+
# --- delete_values
|
305
|
+
# remove an unknown attribute
|
306
|
+
# should return an empty hash
|
307
|
+
assert_equal( {}, putin.delete_values('undefined_attribute' => 'ohoho'))
|
308
|
+
# remove 2 languages
|
309
|
+
lang_hash = {'language' => ['english', 'german']}
|
310
|
+
assert_equal lang_hash, putin.delete_values(lang_hash)
|
311
|
+
wait SDB_DELAY, 'test 11: after put_attributes'
|
312
|
+
# now Putin must know only russian lang
|
313
|
+
new_putin = Client.find_by_name('Putin')
|
314
|
+
new_putin.reload
|
315
|
+
assert ['russian'], new_putin['language'].sort
|
316
|
+
# --- delete_attributes
|
317
|
+
putin.delete_attributes('language', 'hobby')
|
318
|
+
wait SDB_DELAY, 'test 11: after delete_attributes'
|
319
|
+
# trash hoddy and langs
|
320
|
+
new_putin = Client.find_by_name('Putin')
|
321
|
+
new_putin.reload
|
322
|
+
assert_nil new_putin['language']
|
323
|
+
assert_nil new_putin['hobby']
|
324
|
+
# --- delete item
|
325
|
+
putin.delete
|
326
|
+
wait SDB_DELAY, 'test 11: after delete item'
|
327
|
+
assert_nil Client.find_by_name('Putin')
|
328
|
+
end
|
329
|
+
|
330
|
+
def test_14_delete_domain
|
331
|
+
assert Client.delete_domain
|
332
|
+
wait SDB_DELAY, 'test 12: after delete domain'
|
333
|
+
assert_raise(Aws::AwsError) do
|
334
|
+
Client.find :all
|
335
|
+
end
|
336
|
+
end
|
337
|
+
|
338
|
+
end
|
@@ -0,0 +1,207 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
require File.dirname(__FILE__) + '/../test_credentials.rb'
|
3
|
+
|
4
|
+
class TestSdb < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
TestCredentials.get_credentials
|
8
|
+
STDOUT.sync = true
|
9
|
+
@domain = 'right_sdb_awesome_test_domain'
|
10
|
+
@item = 'toys'
|
11
|
+
@attr = { 'Jon' => %w{beer car} }
|
12
|
+
# Interface instance
|
13
|
+
@sdb = Aws::SdbInterface.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
|
14
|
+
end
|
15
|
+
|
16
|
+
SDB_DELAY = 2
|
17
|
+
|
18
|
+
def wait(delay, msg='')
|
19
|
+
print "waiting #{delay} seconds #{msg}"
|
20
|
+
while delay>0 do
|
21
|
+
delay -= 1
|
22
|
+
print '.'
|
23
|
+
sleep 1
|
24
|
+
end
|
25
|
+
puts
|
26
|
+
end
|
27
|
+
|
28
|
+
#---------------------------
|
29
|
+
# Aws::SdbInterface
|
30
|
+
#---------------------------
|
31
|
+
|
32
|
+
def test_00_delete_domain
|
33
|
+
# delete the domain to reset all the things
|
34
|
+
assert @sdb.delete_domain(@domain), 'delete_domain fail'
|
35
|
+
wait SDB_DELAY, 'after domain deletion'
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_01_create_domain
|
39
|
+
# check that domain does not exist
|
40
|
+
assert !@sdb.list_domains[:domains].include?(@domain)
|
41
|
+
# create domain
|
42
|
+
assert @sdb.create_domain(@domain), 'create_domain fail'
|
43
|
+
wait SDB_DELAY, 'after domain creation'
|
44
|
+
# check that we have received new domain from Amazin
|
45
|
+
assert @sdb.list_domains[:domains].include?(@domain)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_02_put_attributes
|
49
|
+
# put attributes
|
50
|
+
assert @sdb.put_attributes(@domain, @item, @attr)
|
51
|
+
wait SDB_DELAY, 'after putting attributes'
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_03_get_attributes
|
55
|
+
# get attributes
|
56
|
+
values = @sdb.get_attributes(@domain, @item)[:attributes]['Jon'].to_a.sort
|
57
|
+
# compare to original list
|
58
|
+
assert_equal values, @attr['Jon'].sort
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_04_add_attributes
|
62
|
+
# add new attribute
|
63
|
+
new_value = 'girls'
|
64
|
+
@sdb.put_attributes @domain, @item, {'Jon' => new_value}
|
65
|
+
wait SDB_DELAY, 'after putting attributes'
|
66
|
+
# get attributes ('girls' must be added to already existent attributes)
|
67
|
+
values = @sdb.get_attributes(@domain, @item)[:attributes]['Jon'].to_a.sort
|
68
|
+
assert_equal values, (@attr['Jon'] << new_value).sort
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_05_replace_attributes
|
72
|
+
# replace attributes
|
73
|
+
@sdb.put_attributes @domain, @item, {'Jon' => 'pub'}, :replace
|
74
|
+
wait SDB_DELAY, 'after replacing attributes'
|
75
|
+
# get attributes (all must be removed except of 'pub')
|
76
|
+
values = @sdb.get_attributes(@domain, @item)[:attributes]['Jon']
|
77
|
+
assert_equal values, ['pub']
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_06_delete_attribute
|
81
|
+
# add value 'girls' and 'vodka' to 'Jon'
|
82
|
+
@sdb.put_attributes @domain, @item, {'Jon' => ['girls', 'vodka']}
|
83
|
+
wait SDB_DELAY, 'after adding attributes'
|
84
|
+
# get attributes ('girls' and 'vodka' must be added 'pub')
|
85
|
+
values = @sdb.get_attributes(@domain, @item)[:attributes]['Jon'].to_a.sort
|
86
|
+
assert_equal values, ['girls', 'pub', 'vodka']
|
87
|
+
# delete a single value 'girls' from attribute 'Jon'
|
88
|
+
@sdb.delete_attributes @domain, @item, 'Jon' => ['girls']
|
89
|
+
wait SDB_DELAY, 'after the deletion of attribute'
|
90
|
+
# get attributes ('girls' must be removed)
|
91
|
+
values = @sdb.get_attributes(@domain, @item)[:attributes]['Jon']
|
92
|
+
assert_equal values, ['pub', 'vodka']
|
93
|
+
# delete all values from attribute 'Jon'
|
94
|
+
@sdb.delete_attributes @domain, @item, ['Jon']
|
95
|
+
wait SDB_DELAY, 'after the deletion of attributes'
|
96
|
+
# get attributes (values must be empty)
|
97
|
+
values = @sdb.get_attributes(@domain, @item)[:attributes]['Jon']
|
98
|
+
assert_equal values, nil
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_07_delete_item
|
102
|
+
@sdb.put_attributes @domain, @item, {'Volodya' => ['girls', 'vodka']}
|
103
|
+
wait SDB_DELAY, 'after adding attributes'
|
104
|
+
# get attributes ('girls' and 'vodka' must be there)
|
105
|
+
values = @sdb.get_attributes(@domain, @item)[:attributes]['Volodya'].to_a.sort
|
106
|
+
assert_equal ['girls', 'vodka'], values
|
107
|
+
# delete an item
|
108
|
+
@sdb.delete_attributes @domain, @item
|
109
|
+
sleep 1
|
110
|
+
# get attributes (values must be empty)
|
111
|
+
values = @sdb.get_attributes(@domain, @item)[:attributes]['Volodya']
|
112
|
+
assert_nil values
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_11_signature_version_2
|
116
|
+
sdb = Aws::SdbInterface.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key, :signature_version => '2')
|
117
|
+
domains = nil
|
118
|
+
assert_nothing_thrown "Failed to use signature V2" do
|
119
|
+
domains = sdb.list_domains
|
120
|
+
end
|
121
|
+
assert domains
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_12_unicode
|
125
|
+
|
126
|
+
# This was creating a bad signature
|
127
|
+
s = ''
|
128
|
+
File.open("unicode.txt", "r") { |f|
|
129
|
+
s = f.read
|
130
|
+
}
|
131
|
+
# s = s.force_encoding("UTF-8")
|
132
|
+
puts 's=' + s.inspect
|
133
|
+
puts "encoding? " + s.encoding.name
|
134
|
+
# s = s.encode("ASCII")
|
135
|
+
# todo: I'm thinking just iterate through characters and swap out ones that aren't in ascii range.
|
136
|
+
@sdb.put_attributes @domain, @item, {"badname"=>[s]}
|
137
|
+
sleep 1
|
138
|
+
value = @sdb.get_attributes(@domain, @item)[:attributes]['badname'][0]
|
139
|
+
puts 'value=' + value.inspect
|
140
|
+
# assert value == s # NOT WORKING, not even sure this is a valid test though
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_15_array_of_attrs
|
145
|
+
item = 'multiples'
|
146
|
+
assert_nothing_thrown "Failed to put multiple attrs" do
|
147
|
+
@sdb.put_attributes(@domain, item, {:one=>1, :two=>2, :three=>3})
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_16_zero_len_attrs
|
152
|
+
item = 'zeroes'
|
153
|
+
assert_nothing_thrown "Failed to put zero-length attributes" do
|
154
|
+
@sdb.put_attributes(@domain, item, {:one=>"", :two=>"", :three=>""})
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_17_nil_attrs
|
159
|
+
item = 'nils'
|
160
|
+
res = nil
|
161
|
+
assert_nothing_thrown do
|
162
|
+
@sdb.put_attributes(@domain, item, {:one=>nil, :two=>nil, :three=>'chunder'})
|
163
|
+
end
|
164
|
+
sleep 1
|
165
|
+
assert_nothing_thrown do
|
166
|
+
res = @sdb.get_attributes(@domain, item)
|
167
|
+
end
|
168
|
+
assert_nil(res[:attributes]['one'][0])
|
169
|
+
assert_nil(res[:attributes]['two'][0])
|
170
|
+
assert_not_nil(res[:attributes]['three'][0])
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_18_url_escape
|
174
|
+
item = 'urlescapes'
|
175
|
+
content = {:a=>"one & two & three",
|
176
|
+
:b=>"one ? two / three"}
|
177
|
+
@sdb.put_attributes(@domain, item, content)
|
178
|
+
|
179
|
+
res = @sdb.get_attributes(@domain, item)
|
180
|
+
assert_equal(content[:a], res[:attributes]['a'][0])
|
181
|
+
assert_equal(content[:b], res[:attributes]['b'][0])
|
182
|
+
end
|
183
|
+
|
184
|
+
def test_19_put_attrs_by_post
|
185
|
+
item = 'reqgirth'
|
186
|
+
i = 0
|
187
|
+
sa = ""
|
188
|
+
while (i < 64) do
|
189
|
+
sa += "aaaaaaaa"
|
190
|
+
i += 1
|
191
|
+
end
|
192
|
+
@sdb.put_attributes(@domain, item, {:a => sa, :b => sa, :c => sa, :d => sa, :e => sa})
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_21_query_with_atributes
|
196
|
+
# not applicable anymore
|
197
|
+
end
|
198
|
+
|
199
|
+
# Keep this test last, because it deletes the domain...
|
200
|
+
def test_40_delete_domain
|
201
|
+
assert @sdb.delete_domain(@domain), 'delete_domain fail'
|
202
|
+
wait SDB_DELAY, 'after domain deletion'
|
203
|
+
# check that domain does not exist
|
204
|
+
assert !@sdb.list_domains[:domains].include?(@domain)
|
205
|
+
end
|
206
|
+
|
207
|
+
end
|