[Zope-Checkins] CVS: Products/Transience/tests -
testCounters.py:1.1.4.1 testTransactionHelper.py:1.1.4.1
testTransientObjectContainer.py:1.14.2.4
Chris McDonough
chrism at plope.com
Fri Sep 17 22:58:20 EDT 2004
Update of /cvs-repository/Products/Transience/tests
In directory cvs.zope.org:/tmp/cvs-serv394/tests
Modified Files:
Tag: Zope-2_7-branch
testTransientObjectContainer.py
Added Files:
Tag: Zope-2_7-branch
testCounters.py testTransactionHelper.py
Log Message:
Merge chrism-pre273-branch to Zope-2_7-branch. This checkin plus others
made to the ZODB 3.2 branch as included with the Zope 2.7 branch fix all
known sessioning issues to date.
Changes:
- TransientObject conflict resolver could potentially fail; when it
failed, the conflict resolution machinery could resolve the
TransientObject to None. (never reported)
- Add a knob (not exposed to UI) to turn off "inband" housekeeping
Housekeeping can now optionally be done using an external scheduling
facility by calling the "housekeep" method regularly.
- Break out actual work that _gc and _finalize do into separate _do methods
for legibility.
- Dont raise Retry in _replentish if we're in a bucket shortage and we can't
get the lock. Instead just soldier on and let the conflict happen naturally.
- Create a "roll" function and attempt to prevent conflicts in _gc by using a
roll.
- Remove "nudge" function in favor of "housekeep".
- Indicators for gc required and replentish required are simpler.
- Replace BTrees.Length.Length with dunny's Length (not _p_independent) in
order to get "number of objects in data container" right.
=== Added File Products/Transience/tests/testCounters.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
import os
from unittest import TestCase, TestSuite, makeSuite
from ZODB.POSException import ConflictError
from ZODB.FileStorage import FileStorage
from ZODB.DB import DB
from Products.Transience.Transience import Length2, Increaser
class Base(TestCase):
db = None
def setUp(self):
pass
def tearDown(self):
if self.db is not None:
self.db.close()
self.storage.cleanup()
def openDB(self):
n = 'fs_tmp__%s' % os.getpid()
self.storage = FileStorage(n)
self.db = DB(self.storage)
class TestLength2(Base):
def testConflict(self):
self.openDB()
length = Length2(0)
r1 = self.db.open().root()
r1['ob'] = length
get_transaction().commit()
r2 = self.db.open().root()
copy = r2['ob']
# The following ensures that copy is loaded.
self.assertEqual(copy(),0)
# First transaction.
length.increment(10)
length.decrement(1)
get_transaction().commit()
# Second transaction.
length = copy
length.increment(20)
length.decrement(2)
get_transaction().commit()
self.assertEqual(length(), 10+20-max(1,2))
class TestIncreaser(Base):
def testConflict(self):
self.openDB()
increaser = Increaser(0)
r1 = self.db.open().root()
r1['ob'] = increaser
get_transaction().commit()
r2 = self.db.open().root()
copy = r2['ob']
# The following ensures that copy is loaded.
self.assertEqual(copy(),0)
# First transaction.
increaser.set(10)
get_transaction().commit()
# Second transaction.
increaser = copy
increaser.set(20)
get_transaction().commit()
self.assertEqual(increaser(), 20)
def test_suite():
suite = TestSuite()
suite.addTest(makeSuite(TestLength2))
suite.addTest(makeSuite(TestIncreaser))
return suite
=== Added File Products/Transience/tests/testTransactionHelper.py ===
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
import sys, os, time, random, unittest
if __name__ == "__main__":
sys.path.insert(0, '../../..')
import ZODB
from unittest import TestCase, TestSuite, TextTestRunner, makeSuite
from Products.Transience.TransactionHelper import PreventTransactionCommit, \
makeTransactionUncommittable
class TestTransactionHelper(TestCase):
def setUp(self):
self.t = get_transaction()
def tearDown(self):
self.t = None
def testUncommittable(self):
makeTransactionUncommittable(self.t, "test")
self.assertRaises(PreventTransactionCommit, get_transaction().commit)
def test_suite():
suite = makeSuite(TestTransactionHelper, 'test')
return suite
if __name__ == '__main__':
runner = TextTestRunner(verbosity=9)
runner.run(test_suite())
=== Products/Transience/tests/testTransientObjectContainer.py 1.14.2.3 => 1.14.2.4 ===
--- Products/Transience/tests/testTransientObjectContainer.py:1.14.2.3 Sun May 30 03:56:35 2004
+++ Products/Transience/tests/testTransientObjectContainer.py Fri Sep 17 22:58:19 2004
@@ -17,7 +17,7 @@
import ZODB
from Products.Transience.Transience import TransientObjectContainer,\
- MaxTransientObjectsExceeded
+ MaxTransientObjectsExceeded, SPARE_BUCKETS, getCurrentTimeslice
from Products.Transience.TransientObject import TransientObject
import Products.Transience.Transience
import Products.Transience.TransientObject
@@ -379,6 +379,18 @@
self.t[x] = x
fauxtime.sleep(180)
self.assertEqual(len(self.t.keys()), 100)
+
+ def testGarbageCollection(self):
+ # this is pretty implementation-dependent :-(
+ for x in range(0, 100):
+ self.t[x] = x
+ sleeptime = self.period * SPARE_BUCKETS
+ fauxtime.sleep(sleeptime)
+ self.t._invoke_finalize_and_gc()
+ max_ts = self.t._last_finalized_timeslice()
+ keys = list(self.t._data.keys())
+ for k in keys:
+ self.assert_(k > max_ts, "k %s < max_ts %s" % (k, max_ts))
def _maxOut(self):
for x in range(11):
More information about the Zope-Checkins
mailing list