right_aws 1.6.2 → 1.7.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.
@@ -55,10 +55,10 @@ module RightAws
55
55
  # see: http://docs.amazonwebservices.com/AmazonSimpleDB/2007-11-07/DeveloperGuide/
56
56
  #
57
57
  def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
58
- init({ :name => 'S3',
59
- :default_host => ENV['S3_URL'] ? URI.parse(ENV['S3_URL']).host : DEFAULT_HOST,
60
- :default_port => ENV['S3_URL'] ? URI.parse(ENV['S3_URL']).port : DEFAULT_PORT,
61
- :default_protocol => ENV['S3_URL'] ? URI.parse(ENV['S3_URL']).scheme : DEFAULT_PROTOCOL },
58
+ init({ :name => 'SDB',
59
+ :default_host => ENV['SDB_URL'] ? URI.parse(ENV['SDB_URL']).host : DEFAULT_HOST,
60
+ :default_port => ENV['SDB_URL'] ? URI.parse(ENV['SDB_URL']).port : DEFAULT_PORT,
61
+ :default_protocol => ENV['SDB_URL'] ? URI.parse(ENV['SDB_URL']).scheme : DEFAULT_PROTOCOL },
62
62
  aws_access_key_id || ENV['AWS_ACCESS_KEY_ID'],
63
63
  aws_secret_access_key || ENV['AWS_SECRET_ACCESS_KEY'],
64
64
  params)
@@ -144,7 +144,7 @@ module RightAws
144
144
  # (similar to ActiveRecord::Base#find using :conditions => ['query', param1, .., paramN])
145
145
  #
146
146
  def query_expression_from_array(params) #:nodoc:
147
- if params
147
+ unless params.blank?
148
148
  query = params.shift.to_s
149
149
  query.gsub(/(\\)?(\?)/) do
150
150
  if $1 # if escaped '\?' is found - replace it by '?' without backslash
@@ -181,13 +181,13 @@ module RightAws
181
181
  end
182
182
 
183
183
  # Pops (and deletes) first accessible message from queue.
184
- # Returns Message instance or +nil+ it the queue is empty.
184
+ # Returns Message instance or +nil+ if the queue is empty.
185
185
  #
186
186
  # queue.pop #=> #<RightAws::SqsGen2::Message:0xb7bf0884 ... >
187
187
  #
188
188
  def pop
189
189
  list = @sqs.interface.pop_messages(@url, 1)
190
- return nil if list == nil
190
+ return nil if list.empty?
191
191
  entry = list[0]
192
192
  msg = Message.new(self, entry['MessageId'], entry['ReceiptHandle'],
193
193
  entry['Body'], visibility)
@@ -64,5 +64,5 @@ class TestEc2 < Test::Unit::TestCase
64
64
  ## # key must be deleted already
65
65
  ## assert_raise(Rightscale::AwsError) { @ec2.delete_key_pair(@key) }
66
66
  end
67
-
67
+
68
68
  end
@@ -0,0 +1,249 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestSdb < Test::Unit::TestCase
4
+
5
+ DOMAIN_NAME = 'right_sdb_awesome_test_domain'
6
+
7
+ class Client < RightAws::ActiveSdb::Base
8
+ set_domain_name DOMAIN_NAME
9
+ end
10
+
11
+ def setup
12
+ STDOUT.sync = true
13
+ @clients = [
14
+ { 'name' => 'Bush', 'country' => 'USA', 'gender' => 'male', 'expiration' => '2009', 'post' => 'president' },
15
+ { 'name' => 'Putin', 'country' => 'Russia', 'gender' => 'male', 'expiration' => '2008', 'post' => 'president' },
16
+ { 'name' => 'Medvedev', 'country' => 'Russia', 'gender' => 'male', 'expiration' => '2012', 'post' => 'president' },
17
+ { 'name' => 'Mary', 'country' => 'USA', 'gender' => 'female', 'hobby' => ['patchwork', 'bundle jumping'] },
18
+ { 'name' => 'Sandy', 'country' => 'Russia', 'gender' => 'female', 'hobby' => ['flowers', 'cats', 'cooking'] },
19
+ { 'name' => 'Mary', 'country' => 'Russia', 'gender' => 'female', 'hobby' => ['flowers', 'cats', 'cooking'] } ]
20
+ RightAws::ActiveSdb.establish_connection(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
21
+ end
22
+
23
+ SDB_DELAY = 3
24
+
25
+ def wait(delay, msg='')
26
+ print " waiting #{delay} seconds: #{msg}"
27
+ while delay>0 do
28
+ delay -= 1
29
+ print '.'
30
+ sleep 1
31
+ end
32
+ puts
33
+ end
34
+
35
+ #---------------------------
36
+ # Rightscale::SdbInterface
37
+ #---------------------------
38
+
39
+ def test_00_delete_domain
40
+ assert RightAws::ActiveSdb.delete_domain(DOMAIN_NAME)
41
+ wait SDB_DELAY, 'test 00: after domain deletion'
42
+ end
43
+
44
+ def test_01_create_domain
45
+ # check that domain does not exist
46
+ assert !RightAws::ActiveSdb.domains.include?(DOMAIN_NAME)
47
+ # create domain
48
+ assert Client.create_domain
49
+ wait SDB_DELAY, 'test 01: after domain creation'
50
+ # check that we have received new domain from Amazin
51
+ assert RightAws::ActiveSdb.domains.include?(DOMAIN_NAME)
52
+ end
53
+
54
+ def test_02_create_items
55
+ # check that DB is empty
56
+ clients = Client.find(:all)
57
+ assert clients.blank?
58
+ # put some clients there
59
+ @clients.each do |client|
60
+ Client.create client
61
+ end
62
+ wait SDB_DELAY, 'test 02: after clients creation'
63
+ # check that DB has all the clients we just putted
64
+ clients = Client.find(:all)
65
+ assert_equal @clients.size, clients.size
66
+ end
67
+
68
+ def test_03_create_and_save_new_item
69
+ # get the db
70
+ old_clients = Client.find(:all)
71
+ # create new client
72
+ new_client = Client.new('country' => 'unknown', 'dummy' => 'yes')
73
+ wait SDB_DELAY, 'test 03: after in-memory client creation'
74
+ # get the db and ensure we created the client in-memory only
75
+ assert_equal old_clients.size, Client.find(:all).size
76
+ # put the client to DB
77
+ new_client.save
78
+ wait SDB_DELAY, 'test 03: after in-memory client saving'
79
+ # get all db again and compare to original list
80
+ assert_equal old_clients.size+1, Client.find(:all).size
81
+ end
82
+
83
+ def test_04_find_all
84
+ # retrieve all the DB, make sure all are in place
85
+ clients = Client.find(:all)
86
+ ids = clients.map{|client| client.id }[0..1]
87
+ assert_equal @clients.size + 1, clients.size
88
+ # retrieve all presidents (must find: Bush, Putin, Medvedev)
89
+ assert_equal 3, Client.find(:all, :conditions => ["[?=?]",'post','president']).size
90
+ # retrieve all russian presidents (must find: Putin, Medvedev)
91
+ assert_equal 2, Client.find(:all, :conditions => ["['post'=?] intersection ['country'=?]",'president', 'Russia']).size
92
+ # retrieve all russian presidents and all women (must find: Putin, Medvedev, 2 Maries and Sandy)
93
+ assert_equal 5, Client.find(:all, :conditions => ["['post'=?] intersection ['country'=?] union ['gender'=?]",'president', 'Russia','female']).size
94
+ # find all rissian presidents Bushes
95
+ assert_equal 0, Client.find(:all, :conditions => ["['post'=?] intersection ['country'=?] intersection ['name'=?]",'president', 'Russia','Bush']).size
96
+ # --- find by ids
97
+ # must find 1 rec (by rec id) and return it
98
+ assert_equal ids.first, Client.find(ids.first).id
99
+ # must find 1 rec (by one item array) and return an array
100
+ assert_equal ids.first, Client.find([ids.first]).first.id
101
+ # must find 2 recs (by a list of comma separated ids) and return an array
102
+ assert_equal ids.size, Client.find(*ids).size
103
+ # must find 2 recs (by an array of ids) and return an array
104
+ assert_equal ids.size, Client.find(ids).size
105
+ ids << 'dummy_id'
106
+ # must raise an error when getting unexistent record
107
+ assert_raise(RightAws::ActiveSdb::ActiveSdbError) do
108
+ Client.find(ids)
109
+ end
110
+ end
111
+
112
+ def test_05_find_first
113
+ # find any record
114
+ assert Client.find(:first)
115
+ # find any president
116
+ assert Client.find(:first, :conditions => ["[?=?]",'post','president'])
117
+ # find any rissian president
118
+ assert Client.find(:first, :conditions => ["['post'=?] intersection ['country'=?]",'president','Russia'])
119
+ # find any unexistent record
120
+ assert_nil Client.find(:first, :conditions => ["['post'=?] intersection ['country'=?]",'president','Rwanda'])
121
+ end
122
+
123
+ def test_06_find_all_by_helpers
124
+ # find all Bushes
125
+ assert_equal 1, Client.find_all_by_name('Bush').size
126
+ # find all russian presidents
127
+ assert_equal 2, Client.find_all_by_post_and_country('president','Russia').size
128
+ # find all women in USA that love flowers
129
+ assert_equal 2, Client.find_all_by_gender_and_country_and_hobby('female','Russia','flowers').size
130
+ end
131
+
132
+ def test_07_find_by_helpers
133
+ # find mr Bush
134
+ assert Client.find_by_name('Bush')
135
+ # find any russian president
136
+ assert Client.find_by_post_and_country('president','Russia')
137
+ # find Mary in Russia that loves flowers
138
+ assert Client.find_by_gender_and_country_and_hobby('female','Russia','flowers')
139
+ end
140
+
141
+ def test_08_reload
142
+ putin = Client.find_by_name('Putin')
143
+ # attributes must be empty until reload (except 'id' field)
144
+ assert_nil putin['name']
145
+ assert_nil putin['country']
146
+ assert_nil putin['gender']
147
+ assert_nil putin['expiration']
148
+ assert_nil putin['post']
149
+ # reloaded attributes must have 5 items + id
150
+ putin.reload
151
+ assert_equal 6, putin.attributes.size
152
+ # check all attributes
153
+ assert_equal ['Putin'], putin['name']
154
+ assert_equal ['Russia'], putin['country']
155
+ assert_equal ['male'], putin['gender']
156
+ assert_equal ['2008'], putin['expiration']
157
+ assert_equal ['president'], putin['post']
158
+ end
159
+
160
+
161
+ def test_09_save_and_put
162
+ putin = Client.find_by_name('Putin')
163
+ putin.reload
164
+ putin['hobby'] = 'ski'
165
+ # SAVE method (replace values)
166
+ putin.save
167
+ wait SDB_DELAY, 'test 09: after saving'
168
+ # check that DB was updated with 'ski'
169
+ new_putin = Client.find_by_name('Putin')
170
+ new_putin.reload
171
+ assert ['ski'], new_putin['hobby']
172
+ # replace hobby
173
+ putin['hobby'] = 'dogs'
174
+ putin.save
175
+ wait SDB_DELAY, 'test 09: after saving'
176
+ # check that 'ski' in DB was replaced by 'dogs'
177
+ new_putin = Client.find_by_name('Putin')
178
+ new_putin.reload
179
+ assert ['dogs'], new_putin['hobby']
180
+ # PUT method (add values)
181
+ putin['hobby'] = 'ski'
182
+ putin.put
183
+ wait SDB_DELAY, 'test 09: after putting'
184
+ # check that 'ski' was added to 'dogs'
185
+ new_putin = Client.find_by_name('Putin')
186
+ new_putin.reload
187
+ assert ['dogs', 'ski'], new_putin['hobby'].sort
188
+ end
189
+
190
+ def test_10_save_and_put_attributes
191
+ putin = Client.find_by_name('Putin')
192
+ putin.reload
193
+ # SAVE method (replace values)
194
+ putin.save_attributes('language' => 'russian')
195
+ wait SDB_DELAY, 'test 10: after save_attributes'
196
+ # check that DB was updated with 'ski'
197
+ new_putin = Client.find_by_name('Putin')
198
+ new_putin.reload
199
+ assert ['russian'], new_putin['language']
200
+ # replace 'russian' by 'german'
201
+ putin.save_attributes('language' => 'german')
202
+ wait SDB_DELAY, 'test 10: after save_attributes'
203
+ # check that 'russian' in DB was replaced by 'german'
204
+ new_putin = Client.find_by_name('Putin')
205
+ new_putin.reload
206
+ assert ['german'], new_putin['language']
207
+ # PUT method (add values)
208
+ putin.put_attributes('language' => ['russian', 'english'])
209
+ wait SDB_DELAY, 'test 10: after put_attributes'
210
+ # now Putin must know all the languages
211
+ new_putin = Client.find_by_name('Putin')
212
+ new_putin.reload
213
+ assert ['english', 'german', 'russian'], new_putin['language'].sort
214
+ end
215
+
216
+ def test_11_delete
217
+ putin = Client.find_by_name('Putin')
218
+ putin.reload
219
+ # --- delete_values
220
+ # remove 2 languages
221
+ putin.delete_values('language' => ['english', 'german'])
222
+ wait SDB_DELAY, 'test 11: after put_attributes'
223
+ # now Putin must know only russian lang
224
+ new_putin = Client.find_by_name('Putin')
225
+ new_putin.reload
226
+ assert ['russian'], new_putin['language'].sort
227
+ # --- delete_attributes
228
+ putin.delete_attributes('language', 'hobby')
229
+ wait SDB_DELAY, 'test 11: after put_attributes'
230
+ # trash hoddy and langs
231
+ new_putin = Client.find_by_name('Putin')
232
+ new_putin.reload
233
+ assert_nil new_putin['language']
234
+ assert_nil new_putin['hobby']
235
+ # --- delete item
236
+ putin.delete
237
+ wait SDB_DELAY, 'test 11: after delete item'
238
+ assert_nil Client.find_by_name('Putin')
239
+ end
240
+
241
+ def test_12_delete_domain
242
+ assert Client.delete_domain
243
+ wait SDB_DELAY, 'test 12: after delete domain'
244
+ assert_raise(Rightscale::AwsError) do
245
+ Client.find :all
246
+ end
247
+ end
248
+
249
+ end
metadata CHANGED
@@ -3,15 +3,15 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: right_aws
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.6.2
7
- date: 2008-03-19 00:00:00 -07:00
6
+ version: 1.7.0
7
+ date: 2008-04-01 00:00:00 -07:00
8
8
  summary: Interface classes for the Amazon EC2, SQS, and S3 Web Services
9
9
  require_paths:
10
10
  - lib
11
11
  email: support@rightscale.com
12
12
  homepage:
13
13
  rubyforge_project: rightaws
14
- description: "== DESCRIPTION: The RightScale AWS gems have been designed to provide a robust, fast, and secure interface to Amazon EC2, Amazon S3, Amazon SQS, and Amazon SDB. These gems have been used in production by RightScale since late 2006 and are being maintained to track enhancements made by Amazon. The RightScale AWS gems comprise: - RightAws::Ec2 -- interface to Amazon EC2 (Elastic Compute Cloud) - RightAws::S3 and RightAws::S3Interface -- interface to Amazon S3 (Simple Storage Service) - RightAws::Sqs and RightAws::SqsInterface -- interface to first-generation Amazon SQS (Simple Queue Service) (API version 2007-05-01) - RightAws::SqsGen2 and RightAws::SqsGen2Interface -- interface to second-generation Amazon SQS (Simple Queue Service) (API version 2008-01-01) - RightAws::SdbInterface -- interface to Amazon SDB (SimpleDB) == FEATURES:"
14
+ description: "== DESCRIPTION: The RightScale AWS gems have been designed to provide a robust, fast, and secure interface to Amazon EC2, Amazon S3, Amazon SQS, and Amazon SDB. These gems have been used in production by RightScale since late 2006 and are being maintained to track enhancements made by Amazon. The RightScale AWS gems comprise: - RightAws::Ec2 -- interface to Amazon EC2 (Elastic Compute Cloud) - RightAws::S3 and RightAws::S3Interface -- interface to Amazon S3 (Simple Storage Service) - RightAws::Sqs and RightAws::SqsInterface -- interface to first-generation Amazon SQS (Simple Queue Service) (API version 2007-05-01) - RightAws::SqsGen2 and RightAws::SqsGen2Interface -- interface to second-generation Amazon SQS (Simple Queue Service) (API version 2008-01-01) - RightAws::SdbInterface and RightAws::ActiveSdb -- interface to Amazon SDB (SimpleDB) == FEATURES:"
15
15
  autorequire:
16
16
  default_executable:
17
17
  bindir: bin
@@ -33,31 +33,33 @@ files:
33
33
  - Manifest.txt
34
34
  - README.txt
35
35
  - Rakefile
36
- - lib/right_aws.rb
37
36
  - lib/awsbase/benchmark_fix.rb
38
- - lib/awsbase/support.rb
39
37
  - lib/awsbase/right_awsbase.rb
38
+ - lib/awsbase/support.rb
40
39
  - lib/ec2/right_ec2.rb
40
+ - lib/right_aws.rb
41
41
  - lib/s3/right_s3.rb
42
42
  - lib/s3/right_s3_interface.rb
43
+ - lib/sdb/active_sdb.rb
43
44
  - lib/sdb/right_sdb_interface.rb
44
45
  - lib/sqs/right_sqs.rb
45
- - lib/sqs/right_sqs_interface.rb
46
46
  - lib/sqs/right_sqs_gen2.rb
47
47
  - lib/sqs/right_sqs_gen2_interface.rb
48
+ - lib/sqs/right_sqs_interface.rb
48
49
  - test/ec2/test_helper.rb
49
50
  - test/ec2/test_right_ec2.rb
51
+ - test/http_connection.rb
50
52
  - test/s3/test_helper.rb
51
53
  - test/s3/test_right_s3.rb
52
54
  - test/s3/test_right_s3_stubbed.rb
53
- - test/sdb/test_right_sdb.rb
55
+ - test/sdb/test_active_sdb.rb
54
56
  - test/sdb/test_helper.rb
57
+ - test/sdb/test_right_sdb.rb
55
58
  - test/sqs/test_helper.rb
56
59
  - test/sqs/test_right_sqs.rb
57
60
  - test/sqs/test_right_sqs_gen2.rb
58
- - test/ts_right_aws.rb
59
61
  - test/test_credentials.rb
60
- - test/http_connection.rb
62
+ - test/ts_right_aws.rb
61
63
  test_files:
62
64
  - test/ts_right_aws.rb
63
65
  rdoc_options: