Esempio n. 1
0
 def setUp(self):
     ZODB.tests.util.TestCase.setUp(self)
     from ZODB.Connection import Connection
     self.db = StubDatabase()
     self.datamgr = Connection(self.db)
     self.datamgr.open()
     self.transaction = StubTransaction()
Esempio n. 2
0
 def close(self):
     db = self._db
     try:
         Connection.close(self)
     finally:
         if db is not None and self._osio is not None:
             self._osio = None
             db._conf_resource.release(self)
Esempio n. 3
0
 def close(self):
     db = self._db
     try:
         Connection.close(self)
     finally:
         if db is not None and self._osio is not None:
             self._osio = None
             db._conf_resource.release(self)
Esempio n. 4
0
    def __init__(self, version='', cache_size=400,
        cache_deactivate_after=None, mvcc=True, txn_mgr=None,
        synch=True):

        self.cache_hits = 0
        self.cache_misses = 0

        Connection.__init__(self, version, cache_size, cache_deactivate_after,\
                            mvcc, txn_mgr, synch)
Esempio n. 5
0
 def setUp(self):
     ZODB.tests.util.TestCase.setUp(self)
     from ZODB.Connection import Connection
     self.db = StubDatabase()
     self.datamgr = Connection(self.db)
     self.datamgr.open()
     self.transaction = StubTransaction()
Esempio n. 6
0
 def _setDB(self, odb):
     Connection._setDB(self, odb)
     pool_ctl = odb.pool_scan_ctl
     if pool_ctl is not None:
         ctl = self._scan_ctl
         if ctl is None:
             self._scan_ctl = ctl = pool_ctl.new_connection()
         if ctl.elapsed():
             # Scan inside a transaction.
             transaction.get().register(self)
             # Let the scanner know which OIDs matter.
             ctl.set_oids(self._cache.cache_data.keys())
             # If it's time, scan on behalf of the whole pool.
             if pool_ctl.elapsed():
                 pool_ctl.scan()
             # If there were any invalidations, process them now.
             if self._invalidated:
                 self._flush_invalidations()
Esempio n. 7
0
 def _setDB(self, odb):
     Connection._setDB(self, odb)
     pool_ctl = odb.pool_scan_ctl
     if pool_ctl is not None:
         ctl = self._scan_ctl
         if ctl is None:
             self._scan_ctl = ctl = pool_ctl.new_connection()
         if ctl.elapsed():
             # Scan inside a transaction.
             transaction.get().register(self)
             # Let the scanner know which OIDs matter.
             ctl.set_oids(self._cache.cache_data.keys())
             # If it's time, scan on behalf of the whole pool.
             if pool_ctl.elapsed():
                 pool_ctl.scan()
             # If there were any invalidations, process them now.
             if self._invalidated:
                 self._flush_invalidations()
Esempio n. 8
0
 def tpc_finish(self, transaction):
     self.loaded_objects = False
     Connection.tpc_finish(self, transaction)
Esempio n. 9
0
 def tpc_abort(self, transaction):
     self.loaded_objects = False
     Connection.tpc_abort(self, transaction)
Esempio n. 10
0
 def tpc_finish(self, transaction):
     self.loaded_objects = False
     Connection.tpc_finish(self, transaction)
Esempio n. 11
0
 def tpc_abort(self, transaction):
     self.loaded_objects = False
     Connection.tpc_abort(self, transaction)
Esempio n. 12
0
class ConnectionDotAdd(ZODB.tests.util.TestCase):
    def setUp(self):
        ZODB.tests.util.TestCase.setUp(self)
        from ZODB.Connection import Connection
        self.db = StubDatabase()
        self.datamgr = Connection(self.db)
        self.datamgr.open()
        self.transaction = StubTransaction()

    def test_add(self):
        from ZODB.POSException import InvalidObjectReference
        obj = StubObject()
        self.assertTrue(obj._p_oid is None)
        self.assertTrue(obj._p_jar is None)
        self.datamgr.add(obj)
        self.assertTrue(obj._p_oid is not None)
        self.assertTrue(obj._p_jar is self.datamgr)
        self.assertTrue(self.datamgr.get(obj._p_oid) is obj)

        # Only first-class persistent objects may be added.
        self.assertRaises(TypeError, self.datamgr.add, object())

        # Adding to the same connection does not fail. Object keeps the
        # same oid.
        oid = obj._p_oid
        self.datamgr.add(obj)
        self.assertEqual(obj._p_oid, oid)

        # Cannot add an object from a different connection.
        obj2 = StubObject()
        obj2._p_jar = object()
        self.assertRaises(InvalidObjectReference, self.datamgr.add, obj2)

    def testResetOnAbort(self):
        # Check that _p_oid and _p_jar are reset when a transaction is
        # aborted.
        obj = StubObject()
        self.datamgr.add(obj)
        oid = obj._p_oid
        self.datamgr.abort(self.transaction)
        self.assertTrue(obj._p_oid is None)
        self.assertTrue(obj._p_jar is None)
        self.assertRaises(KeyError, self.datamgr.get, oid)

    def testResetOnTpcAbort(self):
        obj = StubObject()
        self.datamgr.add(obj)
        oid = obj._p_oid

        # Simulate an error while committing some other object.

        self.datamgr.tpc_begin(self.transaction)
        # Let's pretend something bad happens here.
        # Call tpc_abort, clearing everything.
        self.datamgr.tpc_abort(self.transaction)
        self.assertTrue(obj._p_oid is None)
        self.assertTrue(obj._p_jar is None)
        self.assertRaises(KeyError, self.datamgr.get, oid)

    def testTpcAbortAfterCommit(self):
        obj = StubObject()
        self.datamgr.add(obj)
        oid = obj._p_oid
        self.datamgr.tpc_begin(self.transaction)
        self.datamgr.commit(self.transaction)
        # Let's pretend something bad happened here.
        self.datamgr.tpc_abort(self.transaction)
        self.assertTrue(obj._p_oid is None)
        self.assertTrue(obj._p_jar is None)
        self.assertRaises(KeyError, self.datamgr.get, oid)
        self.assertEqual(self.db.storage._stored, [oid])

    def testCommit(self):
        obj = StubObject()
        self.datamgr.add(obj)
        oid = obj._p_oid
        self.datamgr.tpc_begin(self.transaction)
        self.datamgr.commit(self.transaction)
        self.datamgr.tpc_finish(self.transaction)
        self.assertTrue(obj._p_oid is oid)
        self.assertTrue(obj._p_jar is self.datamgr)

        # This next assertTrue is covered by an assert in tpc_finish.
        ##self.assertTrue(not self.datamgr._added)

        self.assertEqual(self.db.storage._stored, [oid])
        self.assertEqual(self.db.storage._finished, [oid])

    def testModifyOnGetstate(self):
        member = StubObject()
        subobj = StubObject()
        subobj.member = member
        obj = ModifyOnGetStateObject(subobj)
        self.datamgr.add(obj)
        self.datamgr.tpc_begin(self.transaction)
        self.datamgr.commit(self.transaction)
        self.datamgr.tpc_finish(self.transaction)
        storage = self.db.storage
        self.assertTrue(obj._p_oid in storage._stored, "object was not stored")
        self.assertTrue(subobj._p_oid in storage._stored,
                        "subobject was not stored")
        self.assertTrue(member._p_oid in storage._stored,
                        "member was not stored")
        self.assertTrue(self.datamgr._added_during_commit is None)

    def testUnusedAddWorks(self):
        # When an object is added, but not committed, it shouldn't be stored,
        # but also it should be an error.
        obj = StubObject()
        self.datamgr.add(obj)
        self.datamgr.tpc_begin(self.transaction)
        self.datamgr.tpc_finish(self.transaction)
        self.assertTrue(obj._p_oid not in self.datamgr._storage._stored)

    def test__resetCacheResetsReader(self):
        # https://bugs.launchpad.net/zodb/+bug/142667
        old_cache = self.datamgr._cache
        self.datamgr._resetCache()
        new_cache = self.datamgr._cache
        self.assertFalse(new_cache is old_cache)
        self.assertTrue(self.datamgr._reader._cache is new_cache)
Esempio n. 13
0
class ConnectionDotAdd(ZODB.tests.util.TestCase):

    def setUp(self):
        ZODB.tests.util.TestCase.setUp(self)
        from ZODB.Connection import Connection
        self.db = StubDatabase()
        self.datamgr = Connection(self.db)
        self.datamgr.open()
        self.transaction = StubTransaction()

    def test_add(self):
        from ZODB.POSException import InvalidObjectReference
        obj = StubObject()
        self.assertTrue(obj._p_oid is None)
        self.assertTrue(obj._p_jar is None)
        self.datamgr.add(obj)
        self.assertTrue(obj._p_oid is not None)
        self.assertTrue(obj._p_jar is self.datamgr)
        self.assertTrue(self.datamgr.get(obj._p_oid) is obj)

        # Only first-class persistent objects may be added.
        self.assertRaises(TypeError, self.datamgr.add, object())

        # Adding to the same connection does not fail. Object keeps the
        # same oid.
        oid = obj._p_oid
        self.datamgr.add(obj)
        self.assertEqual(obj._p_oid, oid)

        # Cannot add an object from a different connection.
        obj2 = StubObject()
        obj2._p_jar = object()
        self.assertRaises(InvalidObjectReference, self.datamgr.add, obj2)

    def testResetOnAbort(self):
        # Check that _p_oid and _p_jar are reset when a transaction is
        # aborted.
        obj = StubObject()
        self.datamgr.add(obj)
        oid = obj._p_oid
        self.datamgr.abort(self.transaction)
        self.assertTrue(obj._p_oid is None)
        self.assertTrue(obj._p_jar is None)
        self.assertRaises(KeyError, self.datamgr.get, oid)

    def testResetOnTpcAbort(self):
        obj = StubObject()
        self.datamgr.add(obj)
        oid = obj._p_oid

        # Simulate an error while committing some other object.

        self.datamgr.tpc_begin(self.transaction)
        # Let's pretend something bad happens here.
        # Call tpc_abort, clearing everything.
        self.datamgr.tpc_abort(self.transaction)
        self.assertTrue(obj._p_oid is None)
        self.assertTrue(obj._p_jar is None)
        self.assertRaises(KeyError, self.datamgr.get, oid)

    def testTpcAbortAfterCommit(self):
        obj = StubObject()
        self.datamgr.add(obj)
        oid = obj._p_oid
        self.datamgr.tpc_begin(self.transaction)
        self.datamgr.commit(self.transaction)
        # Let's pretend something bad happened here.
        self.datamgr.tpc_abort(self.transaction)
        self.assertTrue(obj._p_oid is None)
        self.assertTrue(obj._p_jar is None)
        self.assertRaises(KeyError, self.datamgr.get, oid)
        self.assertEqual(self.db.storage._stored, [oid])

    def testCommit(self):
        obj = StubObject()
        self.datamgr.add(obj)
        oid = obj._p_oid
        self.datamgr.tpc_begin(self.transaction)
        self.datamgr.commit(self.transaction)
        self.datamgr.tpc_finish(self.transaction)
        self.assertTrue(obj._p_oid is oid)
        self.assertTrue(obj._p_jar is self.datamgr)

        # This next assertTrue is covered by an assert in tpc_finish.
        ##self.assertTrue(not self.datamgr._added)

        self.assertEqual(self.db.storage._stored, [oid])
        self.assertEqual(self.db.storage._finished, [oid])

    def testModifyOnGetstate(self):
        member = StubObject()
        subobj = StubObject()
        subobj.member = member
        obj = ModifyOnGetStateObject(subobj)
        self.datamgr.add(obj)
        self.datamgr.tpc_begin(self.transaction)
        self.datamgr.commit(self.transaction)
        self.datamgr.tpc_finish(self.transaction)
        storage = self.db.storage
        self.assertTrue(obj._p_oid in storage._stored, "object was not stored")
        self.assertTrue(subobj._p_oid in storage._stored,
                "subobject was not stored")
        self.assertTrue(member._p_oid in storage._stored,
                        "member was not stored")
        self.assertTrue(self.datamgr._added_during_commit is None)

    def testUnusedAddWorks(self):
        # When an object is added, but not committed, it shouldn't be stored,
        # but also it should be an error.
        obj = StubObject()
        self.datamgr.add(obj)
        self.datamgr.tpc_begin(self.transaction)
        self.datamgr.tpc_finish(self.transaction)
        self.assertTrue(obj._p_oid not in self.datamgr._storage._stored)

    def test__resetCacheResetsReader(self):
        # https://bugs.launchpad.net/zodb/+bug/142667
        old_cache = self.datamgr._cache
        self.datamgr._resetCache()
        new_cache = self.datamgr._cache
        self.assertFalse(new_cache is old_cache)
        self.assertTrue(self.datamgr._reader._cache is new_cache)
Esempio n. 14
0
 def setUp(self):
     from ZODB.Connection import Connection
     self.db = StubDatabase()
     self.datamgr = Connection(self.db)
     self.datamgr.open()
     self.transaction = StubTransaction()
Esempio n. 15
0
 def setUp(self):
     from ZODB.Connection import Connection
     self.db = StubDatabase()
     self.datamgr = Connection(self.db)
     self.datamgr.open()
     self.transaction = StubTransaction()