gene_pool 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,14 @@
1
+ === 1.1.1 / 2010-11-18
2
+
3
+ * Bug fixes
4
+ * In with_connection_auto_retry, add check for e.message =~ /expired/ as JRuby exception won't be a
5
+ Timeout::Error at this point (http://jira.codehaus.org/browse/JRUBY-5194)
6
+
7
+ === 1.1.0 / 2010-11-11
8
+
9
+ * 1 enhancement:
10
+ * Added with_connection_auto_retry to automatically retry yield block if a non-timeout exception occurs
11
+
1
12
  === 1.0.1 / 2010-09-12
2
13
 
3
14
  * Bug Fixes
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.1.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{gene_pool}
8
- s.version = "1.1.0"
8
+ s.version = "1.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Brad Pardee"]
12
- s.date = %q{2010-11-11}
12
+ s.date = %q{2010-11-18}
13
13
  s.description = %q{Generic pooling library for creating a connection pool}
14
14
  s.email = %q{bradpardee@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -97,7 +97,7 @@ class GenePool
97
97
  if close_on_error
98
98
  connection.close rescue nil
99
99
  end
100
- if (e.kind_of?(Timeout::Error))
100
+ if e.kind_of?(Timeout::Error) || e.message =~ /expired/
101
101
  remove(connection)
102
102
  raise
103
103
  end
@@ -12,16 +12,13 @@ class GenePool
12
12
  end
13
13
 
14
14
  class DummyConnection
15
+ attr_reader :count
15
16
  def initialize(count, sleep_time=nil)
16
17
  sleep sleep_time if sleep_time
17
18
  @count = count
18
19
  @closed = false
19
20
  end
20
21
 
21
- def to_i
22
- @count
23
- end
24
-
25
22
  def to_s
26
23
  @count.to_s
27
24
  end
@@ -63,7 +60,6 @@ class GenePoolTest < Test::Unit::TestCase
63
60
  @logger = nil
64
61
  # Override sleep in individual tests
65
62
  @sleep = nil
66
- @timeout = 5
67
63
  counter = 0
68
64
  mutex = Mutex.new
69
65
  @gene_pool = GenePool.new(:name => 'TestGenePool',
@@ -74,9 +70,7 @@ class GenePoolTest < Test::Unit::TestCase
74
70
  mutex.synchronize do
75
71
  count = counter += 1
76
72
  end
77
- Timeout.timeout(@timeout) do
78
- DummyConnection.new(count, @sleep)
79
- end
73
+ DummyConnection.new(count, @sleep)
80
74
  end
81
75
  end
82
76
 
@@ -90,7 +84,7 @@ class GenePoolTest < Test::Unit::TestCase
90
84
  should 'create 1 connection' do
91
85
  (1..3).each do |i|
92
86
  @gene_pool.with_connection do |conn|
93
- assert_equal conn.to_i, 1
87
+ assert_equal conn.count, 1
94
88
  assert_equal 1, @gene_pool.connections.size
95
89
  assert_equal 1, @gene_pool.checked_out.size
96
90
  assert_same conn, @gene_pool.connections[0]
@@ -104,8 +98,8 @@ class GenePoolTest < Test::Unit::TestCase
104
98
  conn1 = @gene_pool.checkout
105
99
  (1..3).each do |i|
106
100
  @gene_pool.with_connection do |conn2|
107
- assert_equal 1, conn1.to_i
108
- assert_equal 2, conn2.to_i
101
+ assert_equal 1, conn1.count
102
+ assert_equal 2, conn2.count
109
103
  assert_equal 2, @gene_pool.connections.size
110
104
  assert_equal 2, @gene_pool.checked_out.size
111
105
  assert_same conn1, @gene_pool.connections[0]
@@ -123,9 +117,9 @@ class GenePoolTest < Test::Unit::TestCase
123
117
  @gene_pool.with_connection do |conn1|
124
118
  conn2 = @gene_pool.renew(conn1)
125
119
  conn3 = @gene_pool.renew(conn2)
126
- assert_equal 1, conn1.to_i
127
- assert_equal 2, conn2.to_i
128
- assert_equal 3, conn3.to_i
120
+ assert_equal 1, conn1.count
121
+ assert_equal 2, conn2.count
122
+ assert_equal 3, conn3.count
129
123
  assert_equal 1, @gene_pool.connections.size
130
124
  assert_equal 1, @gene_pool.checked_out.size
131
125
  end
@@ -167,12 +161,10 @@ class GenePoolTest < Test::Unit::TestCase
167
161
  should 'handle aborted connection' do
168
162
  @gene_pool.with_connection do |conn1|
169
163
  @sleep = 2
170
- @timeout = 1
171
- begin
172
- @gene_pool.with_connection { |conn2| }
173
- flunk "connection should have timed out"
174
- rescue Timeout::Error => e
175
- #pass
164
+ e = assert_raises Timeout::Error do
165
+ Timeout.timeout(1) do
166
+ @gene_pool.with_connection { |conn2| }
167
+ end
176
168
  end
177
169
  assert_equal 1, @gene_pool.connections.size
178
170
  assert_equal 1, @gene_pool.checked_out.size
@@ -182,7 +174,10 @@ class GenePoolTest < Test::Unit::TestCase
182
174
  # Do another test just to be sure nothings hosed
183
175
  @sleep = nil
184
176
  @gene_pool.with_connection do |conn1|
185
- assert 1, conn1.to_i
177
+ assert 1, conn1.count
178
+ @gene_pool.with_connection do |conn2|
179
+ assert 3, conn2.count
180
+ end
186
181
  end
187
182
  end
188
183
 
@@ -192,7 +187,7 @@ class GenePoolTest < Test::Unit::TestCase
192
187
  (1..pool_size).each do |i|
193
188
  c = @gene_pool.checkout
194
189
  conns << c
195
- assert_equal i, c.to_i
190
+ assert_equal i, c.count
196
191
  assert_equal i, @gene_pool.connections.size
197
192
  assert_equal i, @gene_pool.checked_out.size
198
193
  assert_equal conns, @gene_pool.connections
@@ -237,7 +232,7 @@ class GenePoolTest < Test::Unit::TestCase
237
232
  assert_equal 0, @gene_pool.checked_out.size
238
233
  end
239
234
  ival_conns = []
240
- @gene_pool.each { |conn| ival_conns << conn.to_i }
235
+ @gene_pool.each { |conn| ival_conns << conn.count }
241
236
  ival_conns.sort!
242
237
  assert_equal (1..pool_size).to_a, ival_conns
243
238
  end
@@ -251,7 +246,7 @@ class GenePoolTest < Test::Unit::TestCase
251
246
  conn.fail_on(i)
252
247
  assert_equal 1, @gene_pool.connections.size
253
248
  assert_equal 1, @gene_pool.checked_out.size
254
- assert_equal i+1, conn.to_i
249
+ assert_equal i+1, conn.count
255
250
  end
256
251
  assert_equal stat, conns[0].closed?
257
252
  assert !conns[1].closed?
@@ -270,20 +265,25 @@ class GenePoolTest < Test::Unit::TestCase
270
265
  assert_match %r%Dummy exception%, e.message
271
266
  assert_equal 0, @gene_pool.connections.size
272
267
  assert_equal 0, @gene_pool.checked_out.size
268
+ @gene_pool.with_connection do |conn|
269
+ assert_equal 3, conn.count
270
+ end
273
271
  end
274
272
 
275
273
  should 'not auto-retry on timeout' do
276
- @sleep = 2
277
- @timeout = 1
278
274
  e = assert_raises Timeout::Error do
279
- @gene_pool.with_connection_auto_retry do |conn|
275
+ Timeout.timeout(1) do
276
+ @gene_pool.with_connection_auto_retry do |conn|
277
+ sleep 2
278
+ assert false, true
279
+ end
280
280
  end
281
281
  end
282
282
  assert_equal 0, @gene_pool.connections.size
283
283
  assert_equal 0, @gene_pool.checked_out.size
284
284
  @sleep = 0
285
285
  @gene_pool.with_connection_auto_retry do |conn|
286
- assert_equal 2, conn.to_i
286
+ assert_equal 2, conn.count
287
287
  assert_equal 1, @gene_pool.checked_out.size
288
288
  end
289
289
  assert_equal 1, @gene_pool.connections.size
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 1
8
- - 0
9
- version: 1.1.0
8
+ - 1
9
+ version: 1.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Brad Pardee
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-11-11 00:00:00 -05:00
17
+ date: 2010-11-18 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies: []
20
20