hot_tub 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hot_tub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,27 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-09 00:00:00.000000000Z
12
+ date: 2013-03-31 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httpclient
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
14
30
  - !ruby/object:Gem::Dependency
15
31
  name: rspec
16
- requirement: &70279127174460 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
17
33
  none: false
18
34
  requirements:
19
35
  - - ! '>='
@@ -21,8 +37,14 @@ dependencies:
21
37
  version: '0'
22
38
  type: :development
23
39
  prerelease: false
24
- version_requirements: *70279127174460
25
- description: A very simple ruby pool gem
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: A simple thread-safe http connection pooling gem. Http client options
47
+ include HTTPClient and EM-Http-Request
26
48
  email:
27
49
  - joshmckin@gmail.com
28
50
  executables: []
@@ -37,20 +59,15 @@ files:
37
59
  - Rakefile
38
60
  - http_hot_tub.gemspec
39
61
  - lib/hot_tub.rb
40
- - lib/hot_tub/clients/client.rb
41
- - lib/hot_tub/clients/em_synchrony_client.rb
42
- - lib/hot_tub/clients/excon_client.rb
43
- - lib/hot_tub/clients/http_client_client.rb
62
+ - lib/hot_tub/pool.rb
44
63
  - lib/hot_tub/session.rb
45
64
  - lib/hot_tub/version.rb
46
- - spec/em_synchrony_client_spec.rb
47
- - spec/excon_client_spec.rb
48
- - spec/http_client_client_spec.rb
65
+ - spec/pool_spec.rb
49
66
  - spec/session_spec.rb
50
67
  - spec/spec_helper.rb
51
- - spec/test_helper_methods.rb
52
68
  homepage: https://github.com/JoshMcKin/hot_tub
53
- licenses: []
69
+ licenses:
70
+ - MIT
54
71
  post_install_message:
55
72
  rdoc_options: []
56
73
  require_paths:
@@ -69,14 +86,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
86
  version: '0'
70
87
  requirements: []
71
88
  rubyforge_project: hot_tub
72
- rubygems_version: 1.8.6
89
+ rubygems_version: 1.8.25
73
90
  signing_key:
74
91
  specification_version: 3
75
- summary: A very simple ruby pool gem
92
+ summary: A simple thread-safe http connection pooling gem.
76
93
  test_files:
77
- - spec/em_synchrony_client_spec.rb
78
- - spec/excon_client_spec.rb
79
- - spec/http_client_client_spec.rb
94
+ - spec/pool_spec.rb
80
95
  - spec/session_spec.rb
81
96
  - spec/spec_helper.rb
82
- - spec/test_helper_methods.rb
@@ -1,37 +0,0 @@
1
- require "hot_tub"
2
- require 'thread'
3
- module HotTub
4
- # Super class for all HotTub clients
5
- # provides the 4 required methods to ensure compatibility
6
- class Client
7
-
8
- def client
9
- @client
10
- end
11
-
12
- def method_missing(method, *args, &blk)
13
- @client.send(method,*args,&blk)
14
- end
15
-
16
- # Override this method to perform the necessary action for ensure a client
17
- # is clean for use.
18
- def clean
19
- @client
20
- end
21
-
22
- def close
23
- @client
24
- end
25
-
26
- def dup
27
- self.class.new(@url,@options)
28
- end
29
-
30
- class << self
31
- def mutex
32
- Mutex.new
33
- end
34
- end
35
- end
36
- end
37
-
@@ -1,41 +0,0 @@
1
- require "hot_tub"
2
- require "hot_tub/clients/client"
3
- module HotTub
4
- class EmSynchronyClient < HotTub::Client
5
-
6
- def initialize(url,options={})
7
- @url = url
8
- @options = {:inactivity_timeout => 0}.merge(options)
9
- @client = EM::HttpRequest.new(url,options)
10
- end
11
-
12
- def clean
13
- if @client.conn && @client.conn.error?
14
- HotTub.logger.info "Sanitizing connection : #{EventMachine::report_connection_error_status(@client.conn.instance_variable_get(:@signature))}"
15
- @client.conn.close_connection
16
- @client.instance_variable_set(:@deferred, true)
17
- end
18
- @client
19
- end
20
-
21
- def close
22
- @client.conn.close_connection if @client.conn
23
- end
24
-
25
- # Default keepalive true for HTTP requests
26
- [:get,:head,:delete,:put,:post].each do |m|
27
- define_method m do |options={},&blk|
28
- options ={} if options.nil?
29
- options[:keepalive] = true
30
- @client.send(m,options,&blk)
31
- end
32
- end
33
-
34
- class << self
35
- # Use a fiber safe mutex
36
- def mutex
37
- EM::Synchrony::Thread::Mutex.new
38
- end
39
- end
40
- end
41
- end
@@ -1,24 +0,0 @@
1
- require "hot_tub"
2
- require "hot_tub/clients/client"
3
- require "excon"
4
- module HotTub
5
- class ExconClient < HotTub::Client
6
-
7
- def initialize(url,options={})
8
- @url = url
9
- #make sure we turn on keep-alive
10
- @options = {:headers => {"Connection" => "keep-alive"}}.merge(options)
11
- @client = Excon.new(url,options)
12
- end
13
-
14
- # pretty sure Excon handles this internally
15
- def clean
16
- @client
17
- end
18
-
19
- def close
20
- @client.socket.close
21
- end
22
-
23
- end
24
- end
@@ -1,38 +0,0 @@
1
- require "hot_tub"
2
- require "hot_tub/clients/client"
3
- require 'uri'
4
- require 'http_client'
5
- module HotTub
6
-
7
- class HttpClientClient < HotTub::Client
8
-
9
- def initialize(options={})
10
- options[:default_host] = options[:url] if (options[:url] && options[:default_host].nil?)
11
- @options = options
12
- @client = HTTP::Client.new(options)
13
- end
14
-
15
- # pretty sure HttpClient handles this internally
16
- def clean
17
- @client
18
- end
19
-
20
- def close
21
- @client.shutdown
22
- end
23
- # HttpClient has different initialization attributes so we need a custom dup
24
- def dup
25
- self.class.new(@options)
26
- end
27
- end
28
- end
29
-
30
- module HTTP
31
- class Client
32
- def read_response(request)
33
- r = execute(request)
34
- r.body
35
- r
36
- end
37
- end
38
- end
@@ -1,47 +0,0 @@
1
- unless RUBY_VERSION < '1.9' or (defined? RUBY_ENGINE and 'jruby' == RUBY_ENGINE)
2
- require "em-synchrony"
3
- require "em-synchrony/em-http"
4
- require "em-synchrony/fiber_iterator"
5
- require "hot_tub/clients/em_synchrony_client"
6
- require 'test_helper_methods'
7
- include TestHelperMethods
8
-
9
- describe HotTub::EmSynchronyClient do
10
- before(:each) do
11
- @url = "https://www.google.com"
12
- end
13
-
14
- it "Keep alive should work" do
15
- EM.synchrony do
16
- keep_alive_test HotTub::EmSynchronyClient.new(@url) do |connection|
17
- connection.get.response_header.status
18
- end
19
- EM.stop
20
- end
21
- end
22
- # context 'integration test with parallel requests' do
23
- # # 10 parallel requests
24
- # it "should work" do
25
- # @connection_pool = HotTub::Session.new(:client_options =>
26
- # {:url => "https://www.google.com"},
27
- # :never_block => true,
28
- # :client => HotTub::EmSynchronyClient)
29
- # EM.synchrony do
30
- # concurrency = 10
31
- # options = (0..19).to_a
32
- # results = []
33
- #
34
- # EM::Synchrony::FiberIterator.new(options, concurrency).each do |count|
35
- # resp = @connection_pool.get
36
- # results.push resp.response_header.status
37
- # end
38
- #
39
- # results.length.should eql(20)
40
- # results.include?(200).should be_true
41
- # @connection_pool.instance_variable_get(:@pool).length.should eql(@connection_pool.instance_variable_get(:@options)[:size])
42
- # EM.stop
43
- # end
44
- # end
45
- # end
46
- end
47
- end
@@ -1,18 +0,0 @@
1
- unless (RUBY_VERSION < '1.9' or (defined? RUBY_ENGINE and 'jruby' == RUBY_ENGINE))
2
- require "hot_tub/clients/excon_client"
3
- require 'test_helper_methods'
4
- require 'excon'
5
- include TestHelperMethods
6
- describe HotTub::ExconClient do
7
- before(:each) do
8
- @url = "https://www.google.com"
9
- end
10
-
11
- it "Keep alive should work" do
12
- keep_alive_test HotTub::ExconClient.new(@url) do |client|
13
- client.get.status
14
- end
15
- end
16
- end
17
- end
18
-
@@ -1,16 +0,0 @@
1
- if RUBY_VERSION < '1.9' or (defined? RUBY_ENGINE and 'jruby' == RUBY_ENGINE)
2
- require "hot_tub/clients/http_client_client"
3
- require 'test_helper_methods'
4
- include TestHelperMethods
5
- describe HotTub::HttpClientClient do
6
- before(:each) do
7
- @url = "https://www.google.com"
8
- end
9
- it "Keep alive should work" do
10
- keep_alive_test HotTub::HttpClientClient.new(:url => @url) do |client|
11
- c = client.get('')
12
- c.status_code
13
- end
14
- end
15
- end
16
- end
@@ -1,33 +0,0 @@
1
- module TestHelperMethods
2
- def keep_alive_test(client,&get_status_blk)
3
- responses = []
4
- start = Time.now
5
-
6
- 50.times.each do
7
- c = client.dup # want a new client everytime
8
- responses.push get_status_blk.call(c)
9
- end
10
-
11
- normal = Time.now - start
12
-
13
- # we want a whole new pool to make sure we don't cheat
14
- connection_pool = HotTub::Session.new(client)
15
-
16
- start = Time.now
17
- 50.times.each do
18
- #responses.push get_status_blk.call(connection_pool.get)
19
- connection_pool.run do |c|
20
- responses.push get_status_blk.call(c)
21
- end
22
-
23
- end
24
-
25
- keep_alive = Time.now - start
26
-
27
-
28
- puts "#{client.class.name} keep-alive: #{keep_alive}; normal: #{normal};"
29
- #puts responses.join(", ")
30
- (keep_alive < normal).should be_true
31
- end
32
-
33
- end