connection_pool 2.2.1 → 2.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -8
- data/Changes.md +6 -0
- data/lib/connection_pool.rb +32 -19
- data/lib/connection_pool/timed_stack.rb +1 -0
- data/lib/connection_pool/version.rb +1 -1
- data/test/test_connection_pool.rb +15 -0
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf8177bf07f6c8e68b13f28416f6ccc0c64803af
|
4
|
+
data.tar.gz: ff9c836ce5576d4d0cb1edf8d858a761f982e437
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73bda4d8d0b3cc9daef5c93bb98b7649d811bd5c8f467e25c3aaf7d3353541225e7b30e1efd481a14e45f5c56b5fc846d49dabdd9a167702a71c4a9631a9b6a2
|
7
|
+
data.tar.gz: a331275f67b3635e09792e646113e32bdc74254a2cdff032e972c6f2ebedd6391a1e508c36be7c4e33b40e2a07efe029a2ad0267c3ba4dc20b22813df86427bb
|
data/.travis.yml
CHANGED
data/Changes.md
CHANGED
data/lib/connection_pool.rb
CHANGED
@@ -51,6 +51,7 @@ class ConnectionPool
|
|
51
51
|
|
52
52
|
@available = TimedStack.new(@size, &block)
|
53
53
|
@key = :"current-#{@available.object_id}"
|
54
|
+
@key_count = :"current-#{@available.object_id}-count"
|
54
55
|
end
|
55
56
|
|
56
57
|
if Thread.respond_to?(:handle_interrupt)
|
@@ -84,20 +85,26 @@ else
|
|
84
85
|
end
|
85
86
|
|
86
87
|
def checkout(options = {})
|
87
|
-
|
88
|
-
|
89
|
-
@
|
88
|
+
if ::Thread.current[@key]
|
89
|
+
::Thread.current[@key_count]+= 1
|
90
|
+
::Thread.current[@key]
|
90
91
|
else
|
91
|
-
|
92
|
+
::Thread.current[@key_count]= 1
|
93
|
+
::Thread.current[@key]= @available.pop(options[:timeout] || @timeout)
|
92
94
|
end
|
93
|
-
|
94
|
-
stack.push conn
|
95
|
-
conn
|
96
95
|
end
|
97
96
|
|
98
97
|
def checkin
|
99
|
-
|
100
|
-
|
98
|
+
if ::Thread.current[@key]
|
99
|
+
if ::Thread.current[@key_count] == 1
|
100
|
+
@available.push(::Thread.current[@key])
|
101
|
+
::Thread.current[@key]= nil
|
102
|
+
else
|
103
|
+
::Thread.current[@key_count]-= 1
|
104
|
+
end
|
105
|
+
else
|
106
|
+
raise ConnectionPool::Error, 'no connections are checked out'
|
107
|
+
end
|
101
108
|
|
102
109
|
nil
|
103
110
|
end
|
@@ -106,20 +113,18 @@ end
|
|
106
113
|
@available.shutdown(&block)
|
107
114
|
end
|
108
115
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
if stack.empty?
|
113
|
-
raise ConnectionPool::Error, 'no connections are checked out'
|
114
|
-
else
|
115
|
-
stack.pop
|
116
|
-
end
|
116
|
+
# Size of this connection pool
|
117
|
+
def size
|
118
|
+
@size
|
117
119
|
end
|
118
120
|
|
119
|
-
|
120
|
-
|
121
|
+
# Number of pool entries available for checkout at this instant.
|
122
|
+
def available
|
123
|
+
@available.length
|
121
124
|
end
|
122
125
|
|
126
|
+
private
|
127
|
+
|
123
128
|
class Wrapper < ::BasicObject
|
124
129
|
METHODS = [:with, :pool_shutdown]
|
125
130
|
|
@@ -135,6 +140,14 @@ end
|
|
135
140
|
@pool.shutdown(&block)
|
136
141
|
end
|
137
142
|
|
143
|
+
def pool_size
|
144
|
+
@pool.size
|
145
|
+
end
|
146
|
+
|
147
|
+
def pool_available
|
148
|
+
@pool.available
|
149
|
+
end
|
150
|
+
|
138
151
|
def respond_to?(id, *args)
|
139
152
|
METHODS.include?(id) || with { |c| c.respond_to?(id, *args) }
|
140
153
|
end
|
@@ -498,4 +498,19 @@ class TestConnectionPool < Minitest::Test
|
|
498
498
|
|
499
499
|
assert_equal ['with', 'wrapped'], recorder.calls
|
500
500
|
end
|
501
|
+
|
502
|
+
def test_stats_without_active_connection
|
503
|
+
pool = ConnectionPool.new(size: 2) { NetworkConnection.new }
|
504
|
+
|
505
|
+
assert_equal(2, pool.size)
|
506
|
+
assert_equal(2, pool.available)
|
507
|
+
end
|
508
|
+
|
509
|
+
def test_stats_with_active_connection
|
510
|
+
pool = ConnectionPool.new(size: 2) { NetworkConnection.new }
|
511
|
+
|
512
|
+
pool.with do
|
513
|
+
assert_equal(1, pool.available)
|
514
|
+
end
|
515
|
+
end
|
501
516
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: connection_pool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Perham
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2018-05-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -96,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
96
|
version: '0'
|
97
97
|
requirements: []
|
98
98
|
rubyforge_project:
|
99
|
-
rubygems_version: 2.
|
99
|
+
rubygems_version: 2.6.13
|
100
100
|
signing_key:
|
101
101
|
specification_version: 4
|
102
102
|
summary: Generic connection pool for Ruby
|
@@ -104,4 +104,3 @@ test_files:
|
|
104
104
|
- test/helper.rb
|
105
105
|
- test/test_connection_pool.rb
|
106
106
|
- test/test_connection_pool_timed_stack.rb
|
107
|
-
has_rdoc:
|