em_aws 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- em_aws (0.2.2)
4
+ em_aws (0.2.3)
5
5
  aws-sdk
6
6
  em-http-request
7
7
  em-synchrony
@@ -11,8 +11,7 @@ GEM
11
11
  specs:
12
12
  ZenTest (4.8.2)
13
13
  addressable (2.3.2)
14
- aws-sdk (1.8.0)
15
- httparty (~> 0.7)
14
+ aws-sdk (1.8.1.1)
16
15
  json (~> 1.4)
17
16
  nokogiri (>= 1.4.4)
18
17
  uuidtools (~> 2.1)
@@ -30,18 +29,9 @@ GEM
30
29
  em-synchrony (1.0.3)
31
30
  eventmachine (>= 1.0.0.beta.1)
32
31
  eventmachine (1.0.0)
33
- eventmachine (1.0.0-java)
34
32
  http_parser.rb (0.5.3)
35
- http_parser.rb (0.5.3-java)
36
- httparty (0.10.2)
37
- multi_json (~> 1.0)
38
- multi_xml (>= 0.5.2)
39
33
  json (1.7.6)
40
- json (1.7.6-java)
41
- multi_json (1.5.0)
42
- multi_xml (0.5.2)
43
34
  nokogiri (1.5.6)
44
- nokogiri (1.5.6-java)
45
35
  rspec (2.12.0)
46
36
  rspec-core (~> 2.12.0)
47
37
  rspec-expectations (~> 2.12.0)
data/README.md CHANGED
@@ -50,11 +50,22 @@ are created lazy, so pools grow until they meet the set pool size.
50
50
 
51
51
  ## Streaming
52
52
  Requires [AWS-SKD-Ruby >= 1.6.3](http://aws.amazon.com/releasenotes/Ruby/5728376747252106)
53
+
54
+ # Stream from disk
55
+ # You can pass an IO object in the :data option instead but the object must
56
+ # respond to :path. We cannot stream from memory at this time.
57
+ EM.synchrony do
58
+ s3 = AWS::S3.new
59
+ s3.buckets['bucket_name'].objects["foo.txt"].write(:file => "path_to_file")
60
+ EM.stop
61
+ end
53
62
 
63
+ # Stream from AWS
54
64
  EM.synchrony do
55
65
  s3 = AWS::S3.new
56
- file = File.open("path_to_file")
57
- s3.buckets['bucket_name'].objects["foo.txt"].write(file)
66
+ s3.buckets['bucket_name'].objects["foo.txt"].read do |chunk|
67
+ puts chunk
68
+ end
58
69
  EM.stop
59
70
  end
60
71
 
@@ -33,7 +33,6 @@ module AWS
33
33
  # Run the block on the retrieved connection. Then return the connection
34
34
  # back to the pool.
35
35
  def run(url, &block)
36
- url = url.to_s.split("?")[0].to_s.gsub(/\/$/, "") # homogenize
37
36
  connection = santize_connection(connection(url))
38
37
  block.call(connection)
39
38
  ensure
@@ -24,6 +24,13 @@ module AWS
24
24
  # }))
25
25
  class EMHttpHandler
26
26
 
27
+ EM_PASS_THROUGH_ERRORS = [
28
+ NoMethodError, FloatDomainError, TypeError, NotImplementedError,
29
+ SystemExit, Interrupt, SyntaxError, RangeError, NoMemoryError,
30
+ ArgumentError, ZeroDivisionError, LoadError, NameError,
31
+ LocalJumpError, SignalException, ScriptError,
32
+ SystemStackError, RegexpError, IndexError,
33
+ ]
27
34
  # @return [Hash] The default options to send to EM-Synchrony on each request.
28
35
  attr_reader :default_request_options
29
36
  attr_accessor :status_0_retries
@@ -81,9 +88,9 @@ module AWS
81
88
  def fetch_url(request)
82
89
  url = nil
83
90
  if request.use_ssl?
84
- url = "https://#{request.host}:443#{request.uri}"
91
+ url = "https://#{request.host}:443"
85
92
  else
86
- url = "http://#{request.host}#{request.uri}"
93
+ url = "http://#{request.host}"
87
94
  end
88
95
  url
89
96
  end
@@ -113,16 +120,18 @@ module AWS
113
120
  opts
114
121
  end
115
122
 
116
- def fetch_request_options(request,method)
123
+ def fetch_request_options(request)
117
124
  opts = default_request_options.
118
125
  merge(fetch_headers(request).
119
126
  merge(fetch_proxy(request)).
120
- merge(fetch_ssl(request)))
121
- if (method == :get)
122
- opts[:query] = request.body
127
+ merge(fetch_ssl(request)))
128
+ opts[:query] = request.querystring
129
+ if request.body_stream.respond_to?(:path)
130
+ opts[:file] = request.body_stream.path
123
131
  else
124
- opts[:body] = request.body
132
+ opts[:body] = request.body.to_s
125
133
  end
134
+ opts[:path] = request.path if request.path
126
135
  opts
127
136
  end
128
137
 
@@ -140,7 +149,7 @@ module AWS
140
149
  end
141
150
  nil
142
151
  end
143
-
152
+
144
153
  # AWS needs all headers downcased, and for some reason x-amz-expiration and
145
154
  # x-amz-restore need to be arrays
146
155
  def fetch_response_headers(response)
@@ -163,13 +172,13 @@ module AWS
163
172
  # status_0_retries we assume there is a network error
164
173
  def process_request(request,response,async=false,retries=0,&read_block)
165
174
  method = "a#{request.http_method}".downcase.to_sym # aget, apost, aput, adelete, ahead
166
- opts = fetch_request_options(request,method)
175
+ opts = fetch_request_options(request)
167
176
  opts[:async] = (async || opts[:async])
168
177
  url = fetch_url(request)
169
178
  begin
170
179
  http_response = fetch_response(url,method,opts,&read_block)
171
180
  unless opts[:async]
172
- response.status = http_response.response_header.status.to_i
181
+ response.status = http_response.response_header.status.to_i
173
182
  if response.status == 0
174
183
  if retries <= status_0_retries.to_i
175
184
  process_request(request,response,(retries + 1),&read_block)
@@ -181,9 +190,14 @@ module AWS
181
190
  response.body = http_response.response
182
191
  end
183
192
  end
184
- rescue *AWS::Core::Http::NetHttpHandler::NETWORK_ERRORS
185
- response.network_error = true
193
+ rescue Timeout::Error => error
194
+ response.network_error = error
195
+ rescue *EM_PASS_THROUGH_ERRORS => error
196
+ raise error
197
+ rescue Exception => error
198
+ response.network_error = error
186
199
  end
200
+ nil
187
201
  end
188
202
  end
189
203
  end
@@ -1,3 +1,3 @@
1
1
  module EmAws
2
- VERSION = "0.2.2"
3
- end
2
+ VERSION = "0.2.3"
3
+ end
@@ -57,17 +57,6 @@ module AWS
57
57
  lambda { @em_connection_pool.send(:connection,'http://some_url.com')}.should raise_error(Timeout::Error)
58
58
  end
59
59
  end
60
-
61
- describe '#run' do
62
- it "should homogenize url as much as possible by remove params and trailing '/'" do
63
- url = "http://www.testurl123.com/?foo=bar"
64
- @em_connection_pool.run(url) do {
65
- #stuff
66
- }
67
- end
68
- @em_connection_pool.instance_variable_get(:@pools)["http://www.testurl123.com"].should_not be_nil
69
- end
70
- end
71
60
 
72
61
  context 'integration test with parallel requests' do
73
62
  # 10 parallel requests
@@ -14,6 +14,11 @@
14
14
  require 'spec_helper'
15
15
  module AWS::Core
16
16
  module Http
17
+ class EMFooIO
18
+ def path
19
+ "/my_path/test.text"
20
+ end
21
+ end
17
22
  describe EMHttpHandler do
18
23
 
19
24
  let(:handler) { EMHttpHandler.new(default_request_options) }
@@ -23,6 +28,8 @@ module AWS::Core
23
28
  let(:req) do
24
29
  r = Http::Request.new
25
30
  r.host = "foo.bar.com"
31
+ r.uri = "/my_path/?foo=bar"
32
+ r.body_stream = StringIO.new("myStringIO")
26
33
  r
27
34
  end
28
35
 
@@ -84,7 +91,7 @@ module AWS::Core
84
91
  #puts handler.default_request_options
85
92
  handler.default_request_options[:private_key_file].should == "blarg"
86
93
  end
87
- end
94
+ end
88
95
  end
89
96
  describe '#process_request' do
90
97
  context 'too many retries' do
@@ -98,6 +105,32 @@ module AWS::Core
98
105
  end
99
106
  end
100
107
  end
108
+ describe '#fetch_request_options' do
109
+
110
+ it "should set :query and :body to request.querystring" do
111
+ opts = handler.send(:fetch_request_options,(req))
112
+ opts[:query].should eql(req.querystring)
113
+ end
114
+
115
+ it "should set :path to request.path" do
116
+ opts = handler.send(:fetch_request_options,(req))
117
+ opts[:path].should eql(req.path)
118
+ end
119
+ context "request.body_stream is a StringIO" do
120
+ it "should set :body to request.body_stream" do
121
+ opts = handler.send(:fetch_request_options,(req))
122
+ opts[:body].should eql("myStringIO")
123
+ end
124
+ end
125
+ context "request.body_stream is an object that responds to :path" do
126
+ it "should set :file to object.path " do
127
+ my_io = EMFooIO.new
128
+ req.stub(:body_stream).and_return(my_io)
129
+ opts = handler.send(:fetch_request_options,(req))
130
+ opts[:file].should eql(my_io.path)
131
+ end
132
+ end
133
+ end
101
134
  describe '#fetch_proxy' do
102
135
  context ':proxy_uri' do
103
136
  it 'passes proxy address and port from the request' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em_aws
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-28 00:00:00.000000000 Z
12
+ date: 2013-02-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk
@@ -135,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
135
  version: '0'
136
136
  requirements: []
137
137
  rubyforge_project: em_aws
138
- rubygems_version: 1.8.24
138
+ rubygems_version: 1.8.25
139
139
  signing_key:
140
140
  specification_version: 3
141
141
  summary: Adds EM-Synchrony support to AWS-SDK gem