]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
the return of --mockpool, mocking you and your crappy code that doesn't clean up...
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 31 Mar 2009 20:16:38 +0000 (20:16 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 31 Mar 2009 20:16:38 +0000 (20:16 +0000)
lib/sqlalchemy/pool.py
test/orm/merge.py
test/profiling/alltests.py
test/testlib/compat.py
test/testlib/testing.py

index c39b4b225bf29be9ca61bad09852a702c4f64856..f96e1215c4ac2f6e564967b4206e519a4132ef1e 100644 (file)
@@ -276,7 +276,7 @@ class _ConnectionRecord(object):
 
 
 def _finalize_fairy(connection, connection_record, pool, ref=None):
-    if ref is not None and connection_record.backref is not ref:
+    if ref is not None and (connection_record.backref is not ref or isinstance(pool, AssertionPool)):
         return
     if connection is not None:
         try:
@@ -753,7 +753,8 @@ class StaticPool(Pool):
         Pool.__init__(self, creator, **params)
         self._conn = creator()
         self.connection = _ConnectionRecord(self)
-
+        self.connection = None
+        
     def status(self):
         return "StaticPool"
 
@@ -785,68 +786,41 @@ class AssertionPool(Pool):
 
     ## TODO: modify this to handle an arbitrary connection count.
 
-    def __init__(self, creator, **params):
-        """
-        Construct an AssertionPool.
-
-        :param creator: a callable function that returns a DB-API
-          connection object.  The function will be called with
-          parameters.
-
-        :param recycle: If set to non -1, number of seconds between
-          connection recycling, which means upon checkout, if this
-          timeout is surpassed the connection will be closed and
-          replaced with a newly opened connection. Defaults to -1.
-
-        :param echo: If True, connections being pulled and retrieved
-          from the pool will be logged to the standard output, as well
-          as pool sizing information.  Echoing can also be achieved by
-          enabling logging for the "sqlalchemy.pool"
-          namespace. Defaults to False.
-
-        :param use_threadlocal: If set to True, repeated calls to
-          :meth:`connect` within the same application thread will be
-          guaranteed to return the same connection object, if one has
-          already been retrieved from the pool and has not been
-          returned yet.  Offers a slight performance advantage at the
-          cost of individual transactions by default.  The
-          :meth:`unique_connection` method is provided to bypass the
-          threadlocal behavior installed into :meth:`connect`.
-
-        :param reset_on_return: If true, reset the database state of
-          connections returned to the pool.  This is typically a
-          ROLLBACK to release locks and transaction resources.
-          Disable at your own peril.  Defaults to True.
-
-        :param listeners: A list of
-          :class:`~sqlalchemy.interfaces.PoolListener`-like objects or
-          dictionaries of callables that receive events when DB-API
-          connections are created, checked out and checked in to the
-          pool.
-
-        """
-        Pool.__init__(self, creator, **params)
-        self.connection = _ConnectionRecord(self)
-        self._conn = self.connection
-
+    def __init__(self, *args, **kw):
+        self._conn = None
+        self._checked_out = False
+        Pool.__init__(self, *args, **kw)
+        
     def status(self):
         return "AssertionPool"
 
-    def create_connection(self):
-        raise AssertionError("Invalid")
-
     def do_return_conn(self, conn):
-        assert conn is self._conn and self.connection is None
-        self.connection = conn
+        if not self._checked_out:
+            raise AssertionError("connection is not checked out")
+        self._checked_out = False
+        assert conn is self._conn
 
     def do_return_invalid(self, conn):
-        raise AssertionError("Invalid")
+        self._conn = None
+        self._checked_out = False
+    
+    def dispose(self):
+        self._checked_out = False
+        self._conn.close()
 
+    def recreate(self):
+        self.log("Pool recreating")
+        return AssertionPool(self._creator, echo=self._should_log_info, listeners=self.listeners)
+        
     def do_get(self):
-        assert self.connection is not None
-        c = self.connection
-        self.connection = None
-        return c
+        if self._checked_out:
+            raise AssertionError("connection is already checked out")
+            
+        if not self._conn:
+            self._conn = self.create_connection()
+        
+        self._checked_out = True
+        return self._conn
 
 class _DBProxy(object):
     """Layers connection pooling behavior on top of a standard DB-API module.
index ab56dd9783811f7caf5793b7ecca59985b77b005..790cd449506dec0c1d7b85d3608a4feaf4daa3d8 100644 (file)
@@ -1,6 +1,7 @@
 import testenv; testenv.configure_for_tests()
 from testlib import sa, testing
-from testlib.sa.util import OrderedSet
+from testlib.sa import util
+OrderedSet = util.OrderedSet
 from testlib.sa.orm import mapper, relation, create_session, PropComparator, synonym, comparable_property
 from testlib.testing import eq_, ne_
 from orm import _base, _fixtures
index 19401098c19117f4fdbefd1c8eca04e099112f41..226a02a648b6caf4c32a18667c9013e9bc3ad03c 100644 (file)
@@ -1,5 +1,5 @@
 import testenv; testenv.configure_for_tests()
-from testlib import sa_unittest as unittest
+from testlib import sa_unittest as unittest, testing
 
 
 def suite():
@@ -11,7 +11,7 @@ def suite():
         'profiling.zoomark_orm',
         )
     alltests = unittest.TestSuite()
-    if testenv.testlib.config.coverage_enabled:
+    if testenv.testlib.config.coverage_enabled or testing.jython:
         return alltests
         
     for name in modules_to_test:
index a0226869c20db2575bcb6cabade0b1e373aeb5b7..dd23560be856a3e282beb5802e6f30483d46cdb2 100644 (file)
@@ -1,9 +1,11 @@
 import sys, types, __builtin__
 
-__all__ = '_function_named', 'callable'
+__all__ = '_function_named', 'callable', 'py3k', 'jython'
 
 py3k = getattr(sys, 'py3kwarning', False) or sys.version_info >= (3, 0)
 
+jython = sys.platform.startswith('java')
+
 def _function_named(fn, name):
     """Return a function with a given __name__.
 
index 982eb026d414720df986455d1ef1b32acd8d1159..6963fcb49e7630fcdb004f80b0f69500a30985a0 100644 (file)
@@ -12,7 +12,7 @@ import warnings
 from cStringIO import StringIO
 
 import testlib.config as config
-from testlib.compat import _function_named
+from testlib.compat import *
 from testlib.engines import drop_all_tables
 
 # Delayed imports