Permalink
Browse files

Add ConnectionPool#pool_type to get the type of connection pool in use

You can't use is_a? easily to check the type, since the class
may not be loaded.
  • Loading branch information...
1 parent 30c8bc7 commit ac3fe7e8f57a9ba8cbea718622cca911f53d038c @jeremyevans committed Oct 26, 2012
View
@@ -1,5 +1,7 @@
=== HEAD
+* Add ConnectionPool#pool_type to get the type of connection pool in use (jeremyevans)
+
* Explicitly mark primary keys as NOT NULL on SQLite (jeremyevans)
* Add support for renaming primary key columns on MySQL (jeremyevans)
@@ -76,6 +76,10 @@ def size
@conns.length
end
+ def pool_type
+ :sharded_single
+ end
+
private
# Disconnect from the given server, if connected.
@@ -157,6 +157,10 @@ def servers
sync{@servers.keys}
end
+ def pool_type
+ :sharded_threaded
+ end
+
private
# Assigns a connection to the supplied thread for the given server, if one
@@ -30,5 +30,9 @@ def hold(server=nil)
end
end
+ def pool_type
+ :single
+ end
+
CONNECTION_POOL_MAP[[true, false]] = self
end
@@ -112,6 +112,10 @@ def hold(server=nil)
sync{release(t)} if conn
end
end
+
+ def pool_type
+ :threaded
+ end
private
@@ -854,6 +854,10 @@
end
shared_examples_for "All connection pools classes" do
+ specify "should have pool_type return a symbol" do
+ @class.new(mock_db.call{123}, {}).pool_type.should be_a_kind_of(Symbol)
+ end
+
specify "should have all_connections yield current and available connections" do
p = @class.new(mock_db.call{123}, {})
p.hold{|c| p.all_connections{|c1| c.should == c1}}

0 comments on commit ac3fe7e

Please sign in to comment.