Skip to content

Commit cfeffcf

Browse files
committed
[test] remove tests for re-tries as config option has been removed in 5x
1 parent 5c70a99 commit cfeffcf

File tree

2 files changed

+1
-166
lines changed

2 files changed

+1
-166
lines changed

test/jdbc_connection_test.rb

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ def newConnection; @real_factory.newConnection end
307307
def startup; clear_cached_jdbc_connection_factory end
308308

309309
def setup
310-
config = JDBC_CONFIG.merge :retry_count => 1, :configure_connection => false
310+
config = JDBC_CONFIG.merge :configure_connection => false
311311
ActiveRecord::Base.establish_connection config
312312

313313
@real_connection_factory = get_jdbc_connection_factory
@@ -323,33 +323,6 @@ def teardown
323323
self.class.clear_cached_jdbc_connection_factory
324324
end
325325

326-
test 'getConnection() works' do
327-
ActiveRecord::Base.connection.execute 'SELECT 42' # MySQL
328-
end
329-
330-
test 'getConnection() fails' do
331-
@connection_factory.stubs(:newConnection).
332-
raises( java.sql.SQLException.new('failing twice 1') ).then.
333-
raises( java.sql.SQLException.new('failing twice 2') ).then.
334-
returns( @real_connection_factory.newConnection )
335-
336-
begin
337-
ActiveRecord::Base.connection.execute 'SELECT 1'
338-
fail('connection unexpectedly retrieved')
339-
rescue ActiveRecord::JDBCError => e
340-
assert e.cause
341-
assert_match /failing twice/, e.sql_exception.message
342-
end
343-
end if ar_version('3.0') # NOTE: for some reason fails on 2.3
344-
345-
test 'getConnection() works due retry count' do
346-
@connection_factory.stubs(:newConnection).
347-
raises( java.sql.SQLException.new('failing once') ).then.
348-
returns( @real_connection_factory.newConnection )
349-
350-
ActiveRecord::Base.connection.execute 'SELECT 1'
351-
end
352-
353326
class ConnectionDelegate
354327
include java.sql.Connection
355328

test/jndi_mysql_test.rb

Lines changed: 0 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -155,144 +155,6 @@ def is_connected?(connection); connection.raw_connection.to_java.connected end
155155
field_reader :connected
156156
end
157157

158-
context 'connection-retry' do
159-
160-
class DataSourceMock
161-
include javax.sql.DataSource
162-
163-
def initialize(data_source)
164-
@data_source = data_source
165-
@mockery = []
166-
end
167-
168-
def return_connection(times = 1)
169-
times.times { @mockery << false }; self
170-
end
171-
172-
def then(times = 1, &block)
173-
times.times { @mockery << block }; self
174-
end
175-
176-
def raise_sql_exception(times = 1, &block)
177-
self.then(times) do
178-
if msg = block ? block.call : nil
179-
e = java.sql.SQLException.new(msg)
180-
else
181-
e = java.sql.SQLException.new
182-
end
183-
raise e
184-
end
185-
end
186-
187-
def raise_wrapped_sql_exception(times = 1, &block)
188-
self.then(times) do
189-
if msg = block ? block.call : nil
190-
e = java.sql.SQLException.new(msg)
191-
else
192-
e = java.sql.SQLException.new
193-
end
194-
raise wrap_sql_exception(e)
195-
end
196-
end
197-
198-
def getConnection(*args)
199-
if block = @mockery.shift
200-
block.call(@data_source)
201-
else
202-
@data_source.getConnection(*args)
203-
end
204-
end
205-
206-
def wrap_sql_exception(cause)
207-
error = org.jruby.exceptions.RaiseException.new(
208-
JRuby.runtime, ActiveRecord::JDBCError, cause.message, true
209-
)
210-
error.initCause(cause)
211-
error
212-
end
213-
214-
end
215-
216-
def self.startup
217-
@@name = JNDI_MYSQL_CONFIG[:jndi]
218-
@@data_source = ActiveRecord::ConnectionAdapters::JdbcConnection.jndi_lookup @@name
219-
clear_cached_jdbc_connection_factory
220-
end
221-
222-
def self.shutdown; rebind! @@data_source if @@data_source end
223-
224-
def setup
225-
@config = JNDI_MYSQL_CONFIG.merge :retry_count => 5
226-
#, :configure_connection => false
227-
assert @@data_source.is_a? javax.sql.DataSource
228-
self.class.rebind! @data_source = DataSourceMock.new(@@data_source)
229-
# NOTE: we're assuming here that JNDI connections are lazy ...
230-
ActiveRecord::Base.establish_connection @config
231-
end
232-
233-
def teardown
234-
self.class.rebind!
235-
disconnect_if_connected
236-
self.class.clear_cached_jdbc_connection_factory
237-
end
238-
239-
def self.rebind!(data_source = @@data_source)
240-
javax.naming.InitialContext.new.rebind @@name, data_source
241-
end
242-
243-
test 'getConnection() works' do
244-
ActiveRecord::Base.connection.execute 'SELECT 42'
245-
end
246-
247-
test 'getConnection() fails' do
248-
@data_source.return_connection(1).then(5 + 1) do
249-
raise java.sql.SQLException.new("yet a failure")
250-
end
251-
252-
Thread.new { ActiveRecord::Base.connection.execute 'SELECT 1' }.join
253-
begin
254-
ActiveRecord::Base.connection.execute 'SELECT 2'
255-
fail 'connection unexpectedly retrieved'
256-
rescue ActiveRecord::JDBCError => e
257-
assert e.cause
258-
assert_match /yet.a.failure/, e.message
259-
end
260-
end if ar_version('3.0') # NOTE: for some reason fails on 2.3
261-
262-
test 'getConnection() works due retry count' do
263-
@data_source.return_connection.
264-
then { raise java.sql.SQLException.new("failure 1") }.
265-
then { raise java.sql.SQLException.new("failure 2") }.
266-
then { raise java.sql.SQLException.new("failure 3") }.
267-
return_connection(1)
268-
269-
Thread.new { ActiveRecord::Base.connection.execute 'SELECT 1' }.join
270-
ActiveRecord::Base.connection.execute 'SELECT 2'
271-
end
272-
273-
test 'getConnection() does re-lookup on failure' do
274-
another_data_source = DataSourceMock.new(@@data_source)
275-
276-
@data_source.return_connection(2).
277-
raise_sql_exception(2) { 'expected-failure' }.
278-
raise_sql_exception do
279-
self.class.rebind! another_data_source
280-
'failure after re-bound'
281-
end.
282-
raise_sql_exception(5) { 'unexpected' } # not expected to be called
283-
284-
Thread.new { ActiveRecord::Base.connection.execute 'SELECT 1' }.join
285-
assert_equal @data_source, get_jdbc_connection_factory.data_source
286-
287-
Thread.new { ActiveRecord::Base.connection.execute 'SELECT 2' }.join
288-
assert_equal @data_source, get_jdbc_connection_factory.data_source
289-
290-
ActiveRecord::Base.connection.execute 'SELECT 3'
291-
assert_not_equal @data_source, get_jdbc_connection_factory.data_source
292-
assert_equal another_data_source, get_jdbc_connection_factory.data_source
293-
end
294-
295-
end
296158

297159
private
298160

0 commit comments

Comments
 (0)