hackerdude-aws 2.3.25

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../../lib/right_aws'
@@ -0,0 +1,206 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+ require File.dirname(__FILE__) + '/../test_credentials.rb'
3
+
4
+
5
+ class TestSqs < Test::Unit::TestCase
6
+
7
+ GRANTEE_EMAIL_ADDRESS = 'fester@example.com'
8
+ RIGHT_MESSAGE_TEXT = 'Right test message'
9
+
10
+
11
+ def setup
12
+ TestCredentials.get_credentials
13
+ @sqs = Aws::SqsInterface.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
14
+ @queue_name = 'right_sqs_test_gen2_queue'
15
+ # for classes
16
+ @s = Aws::Sqs.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
17
+ end
18
+
19
+ # Wait for the queue to appear in the queues list.
20
+ # Amazon needs some time to after the queue creation to place
21
+ # it to the accessible queues list. If we dont want to get
22
+ # the additional faults then wait a bit...
23
+ def wait_for_queue_url(queue_name)
24
+ queue_url = nil
25
+ until queue_url
26
+ queue_url = @sqs.queue_url_by_name(queue_name)
27
+ unless queue_url
28
+ print '-'
29
+ STDOUT.flush
30
+ sleep 1
31
+ end
32
+ end
33
+ queue_url
34
+ end
35
+
36
+
37
+ #---------------------------
38
+ # Rightscale::SqsInterface
39
+ #---------------------------
40
+
41
+ def test_01_create_queue
42
+ queue_url = @sqs.create_queue @queue_name
43
+ assert queue_url[/http.*#{@queue_name}/], 'New queue creation failed'
44
+ end
45
+
46
+ def test_02_list_queues
47
+ wait_for_queue_url(@queue_name)
48
+ queues = @sqs.list_queues('right_')
49
+ assert queues.size>0, 'Must more that 0 queues in list'
50
+ end
51
+
52
+ def test_03_set_and_get_queue_attributes
53
+ queue_url = @sqs.queue_url_by_name(@queue_name)
54
+ assert queue_url[/http.*#{@queue_name}/], "#{@queue_name} must exist!"
55
+ assert @sqs.set_queue_attributes(queue_url, 'VisibilityTimeout', 111), 'Set_queue_attributes fail'
56
+ sleep 20 # Amazon needs some time to change attribute
57
+ assert_equal '111', @sqs.get_queue_attributes(queue_url)['VisibilityTimeout'], 'New VisibilityTimeout must be equal to 111'
58
+ end
59
+
60
+ def test_06_send_message
61
+ queue_url = @sqs.queue_url_by_name(@queue_name)
62
+ # send 5 messages for the tests below
63
+ assert @sqs.send_message(queue_url, RIGHT_MESSAGE_TEXT)
64
+ assert @sqs.send_message(queue_url, RIGHT_MESSAGE_TEXT)
65
+ assert @sqs.send_message(queue_url, RIGHT_MESSAGE_TEXT)
66
+ assert @sqs.send_message(queue_url, RIGHT_MESSAGE_TEXT)
67
+ assert @sqs.send_message(queue_url, RIGHT_MESSAGE_TEXT)
68
+ sleep 2
69
+ end
70
+
71
+ def test_07_get_queue_length
72
+ queue_url = @sqs.queue_url_by_name(@queue_name)
73
+ assert_equal 5, @sqs.get_queue_length(queue_url), 'Queue must have 5 messages'
74
+ end
75
+
76
+ def test_08_receive_message
77
+ queue_url = @sqs.queue_url_by_name(@queue_name)
78
+ r_message = @sqs.receive_message(queue_url, 1)[0]
79
+ assert r_message, "Receive returned no message(s), but this is not necessarily incorrect"
80
+ assert_equal RIGHT_MESSAGE_TEXT, r_message['Body'], 'Receive message got wrong message text'
81
+ end
82
+
83
+ def test_09_delete_message
84
+ queue_url = @sqs.queue_url_by_name(@queue_name)
85
+ message = @sqs.receive_message(queue_url)[0]
86
+ assert @sqs.delete_message(queue_url, message['ReceiptHandle']), 'Delete_message fail'
87
+ assert @sqs.pop_message(queue_url), 'Pop_message fail'
88
+ end
89
+
90
+ def test_10_clear_and_delete_queue
91
+ queue_url = @sqs.queue_url_by_name(@queue_name)
92
+ assert @sqs.delete_queue(queue_url)
93
+ end
94
+
95
+ #---------------------------
96
+ # Aws::Sqs classes
97
+ #---------------------------
98
+
99
+ def test_20_sqs_create_delete_queue
100
+ assert @s, 'Aws::Sqs must exist'
101
+ # get queues list
102
+ queues_size = @s.queues.size
103
+ # create new queue
104
+ queue = @s.queue("#{@queue_name}_20", true)
105
+ # check that it is created
106
+ assert queue.is_a?(Aws::Sqs::Queue)
107
+ wait_for_queue_url(@queue_name)
108
+ # check that amount of queues has increased
109
+ assert_equal queues_size + 1, @s.queues.size
110
+ # delete queue
111
+ assert queue.delete
112
+ end
113
+
114
+ def test_21_queue_create
115
+ # create new queue
116
+ queue = Aws::Sqs::Queue.create(@s, "#{@queue_name}_21", true)
117
+ # check that it is created
118
+ assert queue.is_a?(Aws::Sqs::Queue)
119
+ wait_for_queue_url(@queue_name)
120
+ end
121
+
122
+ def test_22_queue_attributes
123
+ queue = Aws::Sqs::Queue.create(@s, "#{@queue_name}_21", false)
124
+ # get a list of attrinutes
125
+ attributes = queue.get_attribute
126
+ assert attributes.is_a?(Hash) && attributes.size>0
127
+ # get attribute value and increase it by 10
128
+ v = (queue.get_attribute('VisibilityTimeout').to_i + 10).to_s
129
+ # set attribute
130
+ assert queue.set_attribute('VisibilityTimeout', v)
131
+ # wait a bit
132
+ sleep 20
133
+ # check that attribute has changed
134
+ assert_equal v, queue.get_attribute('VisibilityTimeout')
135
+ # get queue visibility timeout
136
+ assert_equal v, queue.visibility
137
+ # change it
138
+ queue.visibility = queue.visibility.to_i + 10
139
+ # make sure that it is changed
140
+ assert v.to_i + 10, queue.visibility
141
+ end
142
+
143
+ def test_24_send_size
144
+ queue = Aws::Sqs::Queue.create(@s, "#{@queue_name}_24", true)
145
+ # send 5 messages
146
+ assert queue.push('a1')
147
+ assert queue.push('a2')
148
+ assert queue.push('a3')
149
+ assert queue.push('a4')
150
+ assert queue.push('a5')
151
+ sleep 2
152
+ # check queue size
153
+ assert_equal 5, queue.size
154
+ # send one more
155
+ assert queue.push('a6')
156
+ sleep 2
157
+ # check queue size again
158
+ assert_equal 6, queue.size
159
+ end
160
+
161
+ def test_25_message_receive_pop_delete
162
+ queue = Aws::Sqs::Queue.create(@s, "#{@queue_name}_24", false)
163
+ # get queue size
164
+ size = queue.size
165
+ # get first message
166
+ m1 = queue.receive(10)
167
+ assert m1.is_a?(Aws::Sqs::Message)
168
+ # pop second message
169
+ m2 = queue.pop
170
+ assert m2.is_a?(Aws::Sqs::Message)
171
+ # make sure that queue size has decreased
172
+ assert_equal size-1, queue.size
173
+ # delete messsage
174
+ assert m1.delete
175
+ # make sure that queue size has decreased again
176
+ assert_equal size-2, queue.size
177
+ end
178
+
179
+ def test_26
180
+ queue = Aws::Sqs::Queue.create(@s, "#{@queue_name}_24", false)
181
+ # lock message
182
+ queue.receive(100)
183
+ # clear queue
184
+ assert queue.clear
185
+ # queue size is greater than zero
186
+ assert queue.size>0
187
+ end
188
+
189
+ def test_27_set_amazon_problems
190
+ original_problems = Aws::SqsInterface.amazon_problems
191
+ assert(original_problems.length > 0)
192
+ Aws::SqsInterface.amazon_problems= original_problems << "A New Problem"
193
+ new_problems = Aws::SqsInterface.amazon_problems
194
+ assert_equal(new_problems, original_problems)
195
+
196
+ Aws::SqsInterface.amazon_problems= nil
197
+ assert_nil(Aws::SqsInterface.amazon_problems)
198
+ end
199
+
200
+ def test_28_check_threading_model
201
+ assert(!@sqs.multi_thread)
202
+ newsqs = Aws::SqsInterface.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key, {:multi_thread => true})
203
+ assert(newsqs.multi_thread)
204
+ end
205
+
206
+ end
@@ -0,0 +1,54 @@
1
+ class TestCredentials
2
+
3
+ @@aws_access_key_id = nil
4
+ @@aws_secret_access_key = nil
5
+ @@account_number = nil
6
+ @@config = nil
7
+
8
+ def self.config
9
+ @@config
10
+ end
11
+
12
+ def self.aws_access_key_id
13
+ @@aws_access_key_id
14
+ end
15
+
16
+ def self.aws_access_key_id=(newval)
17
+ @@aws_access_key_id = newval
18
+ end
19
+
20
+ def self.account_number
21
+ @@account_number
22
+ end
23
+
24
+ def self.account_number=(newval)
25
+ @@account_number = newval
26
+ end
27
+
28
+ def self.aws_secret_access_key
29
+ @@aws_secret_access_key
30
+ end
31
+
32
+ def self.aws_secret_access_key=(newval)
33
+ @@aws_secret_access_key = newval
34
+ end
35
+
36
+ require 'yaml'
37
+
38
+ def self.get_credentials
39
+ #Dir.chdir do
40
+ begin
41
+
42
+ Dir.chdir(File.expand_path("~/.test-configs")) do
43
+ credentials = YAML::load(File.open("aws.yml"))
44
+ @@config = credentials
45
+ self.aws_access_key_id = credentials["amazon"]["access_key"]
46
+ self.aws_secret_access_key = credentials["amazon"]["secret_key"]
47
+ end
48
+ rescue Exception => e
49
+ puts "#{e.message}"
50
+ raise e
51
+ end
52
+ #end
53
+ end
54
+ end
@@ -0,0 +1,13 @@
1
+ require 'test/unit'
2
+ $: << File.dirname(__FILE__)
3
+ require 'test_credentials'
4
+ TestCredentials.get_credentials
5
+
6
+ require 'http_connection'
7
+ require 'ec2/test_ec2.rb'
8
+ require 's3/test_s3.rb'
9
+ require 's3/test_s3_stubbed.rb'
10
+ require 'sqs/test_sqs.rb'
11
+ require 'sqs/test_right_sqs_gen2.rb'
12
+ require 'sdb/test_sdb.rb'
13
+ require 'acf/test_acf.rb'
metadata ADDED
@@ -0,0 +1,182 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hackerdude-aws
3
+ version: !ruby/object:Gem::Version
4
+ hash: 49
5
+ prerelease: false
6
+ segments:
7
+ - 2
8
+ - 3
9
+ - 25
10
+ version: 2.3.25
11
+ platform: ruby
12
+ authors:
13
+ - Travis Reeder
14
+ - Chad Arimura
15
+ - RightScale
16
+ - David Martinez
17
+ autorequire:
18
+ bindir: bin
19
+ cert_chain: []
20
+
21
+ date: 2010-11-17 00:00:00 -08:00
22
+ default_executable:
23
+ dependencies:
24
+ - !ruby/object:Gem::Dependency
25
+ name: uuidtools
26
+ prerelease: false
27
+ requirement: &id001 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ hash: 3
33
+ segments:
34
+ - 0
35
+ version: "0"
36
+ type: :runtime
37
+ version_requirements: *id001
38
+ - !ruby/object:Gem::Dependency
39
+ name: http_connection
40
+ prerelease: false
41
+ requirement: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ hash: 3
47
+ segments:
48
+ - 0
49
+ version: "0"
50
+ type: :runtime
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: xml-simple
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ type: :runtime
65
+ version_requirements: *id003
66
+ - !ruby/object:Gem::Dependency
67
+ name: activesupport
68
+ prerelease: false
69
+ requirement: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ hash: 3
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ type: :runtime
79
+ version_requirements: *id004
80
+ description: AWS Ruby Library for interfacing with Amazon Web Services. Alexa-experimental branch.
81
+ email: travis@appoxy.com
82
+ executables: []
83
+
84
+ extensions: []
85
+
86
+ extra_rdoc_files:
87
+ - README.markdown
88
+ files:
89
+ - lib/acf/right_acf_interface.rb
90
+ - lib/alexa/alexa.rb
91
+ - lib/aws.rb
92
+ - lib/awsbase/aws_response_array.rb
93
+ - lib/awsbase/benchmark_fix.rb
94
+ - lib/awsbase/right_awsbase.rb
95
+ - lib/awsbase/support.rb
96
+ - lib/ec2/right_ec2.rb
97
+ - lib/ec2/right_mon_interface.rb
98
+ - lib/elb/elb_interface.rb
99
+ - lib/rds/rds.rb
100
+ - lib/right_aws.rb
101
+ - lib/s3/right_s3.rb
102
+ - lib/s3/right_s3_interface.rb
103
+ - lib/sdb/active_sdb.rb
104
+ - lib/sdb/right_sdb_interface.rb
105
+ - lib/sqs/right_sqs.rb
106
+ - lib/sqs/right_sqs_interface.rb
107
+ - README.markdown
108
+ - test/acf/test_acf.rb
109
+ - test/acf/test_helper.rb
110
+ - test/alexa/test_alexa.rb
111
+ - test/alexa/test_helper.rb
112
+ - test/ec2/test_ec2.rb
113
+ - test/ec2/test_helper.rb
114
+ - test/ec2/test_mon.rb
115
+ - test/elb/test_elb.rb
116
+ - test/http_connection.rb
117
+ - test/rds/test_rds.rb
118
+ - test/s3/test_helper.rb
119
+ - test/s3/test_s3.rb
120
+ - test/s3/test_s3_stubbed.rb
121
+ - test/sdb/test_active_sdb.rb
122
+ - test/sdb/test_helper.rb
123
+ - test/sdb/test_sdb.rb
124
+ - test/sqs/test_helper.rb
125
+ - test/sqs/test_sqs.rb
126
+ - test/test_credentials.rb
127
+ - test/ts_right_aws.rb
128
+ has_rdoc: true
129
+ homepage: http://github.com/hackerdude/aws/
130
+ licenses: []
131
+
132
+ post_install_message:
133
+ rdoc_options:
134
+ - --charset=UTF-8
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ hash: 3
143
+ segments:
144
+ - 0
145
+ version: "0"
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ none: false
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ hash: 3
152
+ segments:
153
+ - 0
154
+ version: "0"
155
+ requirements: []
156
+
157
+ rubyforge_project:
158
+ rubygems_version: 1.3.7
159
+ signing_key:
160
+ specification_version: 3
161
+ summary: AWS Ruby Library for interfacing with Amazon Web Services. Hackerdude branch including Alexa (Experimental).
162
+ test_files:
163
+ - test/acf/test_acf.rb
164
+ - test/acf/test_helper.rb
165
+ - test/alexa/test_alexa.rb
166
+ - test/alexa/test_helper.rb
167
+ - test/ec2/test_ec2.rb
168
+ - test/ec2/test_helper.rb
169
+ - test/ec2/test_mon.rb
170
+ - test/elb/test_elb.rb
171
+ - test/http_connection.rb
172
+ - test/rds/test_rds.rb
173
+ - test/s3/test_helper.rb
174
+ - test/s3/test_s3.rb
175
+ - test/s3/test_s3_stubbed.rb
176
+ - test/sdb/test_active_sdb.rb
177
+ - test/sdb/test_helper.rb
178
+ - test/sdb/test_sdb.rb
179
+ - test/sqs/test_helper.rb
180
+ - test/sqs/test_sqs.rb
181
+ - test/test_credentials.rb
182
+ - test/ts_right_aws.rb