aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-03-28 17:29:37 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2011-03-28 17:29:37 -0700
commit25f94971abf71fe51089f53b72cc08b636c230b3 (patch)
tree1bf6bd533cc3362ea5257e0b6b7ae7e43e7e5a25
parent4211866b7a1d0abf0c9150fd61ea67a8043b831d (diff)
downloadrails-25f94971abf71fe51089f53b72cc08b636c230b3.tar.gz
rails-25f94971abf71fe51089f53b72cc08b636c230b3.tar.bz2
rails-25f94971abf71fe51089f53b72cc08b636c230b3.zip
adding active_connections? to the connection pool for finding open connections
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb6
-rw-r--r--activerecord/test/cases/connection_adapters/connection_handler_test.rb33
2 files changed, 39 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
index 61e44d09bf..7a900055a9 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
@@ -352,6 +352,12 @@ module ActiveRecord
@connection_pools[name] = ConnectionAdapters::ConnectionPool.new(spec)
end
+ # Returns true if there are any active connections among the connection
+ # pools that the ConnectionHandler is managing.
+ def active_connections?
+ connection_pools.values.any? { |pool| pool.active_connection? }
+ end
+
# Returns any connections in use by the current thread back to the pool,
# and also returns connections to the pool cached by threads that are no
# longer alive.
diff --git a/activerecord/test/cases/connection_adapters/connection_handler_test.rb b/activerecord/test/cases/connection_adapters/connection_handler_test.rb
new file mode 100644
index 0000000000..abf317768f
--- /dev/null
+++ b/activerecord/test/cases/connection_adapters/connection_handler_test.rb
@@ -0,0 +1,33 @@
+require "cases/helper"
+
+module ActiveRecord
+ module ConnectionAdapters
+ class ConnectionHandlerTest < ActiveRecord::TestCase
+ def setup
+ @handler = ConnectionHandler.new
+ @handler.establish_connection 'america', Base.connection_pool.spec
+ @klass = Struct.new(:name).new('america')
+ end
+
+ def test_retrieve_connection
+ assert @handler.retrieve_connection(@klass)
+ end
+
+ def test_active_connections?
+ assert !@handler.active_connections?
+ assert @handler.retrieve_connection(@klass)
+ assert @handler.active_connections?
+ @handler.clear_active_connections!
+ assert !@handler.active_connections?
+ end
+
+ def test_retrieve_connection_pool_with_ar_base
+ assert_nil @handler.retrieve_connection_pool(ActiveRecord::Base)
+ end
+
+ def test_retrieve_connection_pool
+ assert_not_nil @handler.retrieve_connection_pool(@klass)
+ end
+ end
+ end
+end