[Zodb-checkins] SVN: ZODB/trunk/src/Z Use binary pickles to deal with new oids generated by demo storage.
Jim Fulton
jim at zope.com
Sat Nov 1 14:07:39 EDT 2008
Log message for revision 92741:
Use binary pickles to deal with new oids generated by demo storage.
Added a new test class for testing packing without gc.
Moved some useful tests to PackableStorage so they are run by storages
without undo.
Changed:
U ZODB/trunk/src/ZEO/tests/testZEO.py
U ZODB/trunk/src/ZODB/tests/PackableStorage.py
U ZODB/trunk/src/ZODB/tests/testDemoStorage.py
U ZODB/trunk/src/ZODB/tests/testMappingStorage.py
-=-
Modified: ZODB/trunk/src/ZEO/tests/testZEO.py
===================================================================
--- ZODB/trunk/src/ZEO/tests/testZEO.py 2008-11-01 18:07:33 UTC (rev 92740)
+++ ZODB/trunk/src/ZEO/tests/testZEO.py 2008-11-01 18:07:39 UTC (rev 92741)
@@ -418,6 +418,7 @@
def checkPackWithMultiDatabaseReferences(self):
pass # DemoStorage pack doesn't do gc
+ checkPackAllRevisions = checkPackWithMultiDatabaseReferences
class HeartbeatTests(ZEO.tests.ConnectionTests.CommonSetupTearDown):
"""Make sure a heartbeat is being sent and that it does no harm
Modified: ZODB/trunk/src/ZODB/tests/PackableStorage.py
===================================================================
--- ZODB/trunk/src/ZODB/tests/PackableStorage.py 2008-11-01 18:07:33 UTC (rev 92740)
+++ ZODB/trunk/src/ZODB/tests/PackableStorage.py 2008-11-01 18:07:39 UTC (rev 92741)
@@ -86,7 +86,7 @@
return obj.getoid()
return None
s = StringIO()
- p = pickle.Pickler(s)
+ p = pickle.Pickler(s, 1)
p.persistent_id = getpersid
p.dump(obj)
p.dump(None)
@@ -322,12 +322,7 @@
transaction.commit()
db.pack(time.time()+1)
self.assertEqual(len(self._storage), 1)
-
-
-
-class PackableUndoStorage(PackableStorageBase):
-
def checkPackAllRevisions(self):
self._initroot()
eq = self.assertEqual
@@ -443,11 +438,9 @@
# Create a persistent object, with some initial state
obj1 = self._newobj()
oid1 = obj1.getoid()
- # Create another persistent object, with some initial state. Make
- # sure it's oid is greater than the first object's oid.
+ # Create another persistent object, with some initial state.
obj2 = self._newobj()
oid2 = obj2.getoid()
- self.failUnless(oid2 > oid1)
# Link the root object to the persistent objects, in order to keep
# them alive. Store the root object.
root.obj1 = obj1
@@ -517,6 +510,50 @@
eq(pobj.getoid(), oid2)
eq(pobj.value, 11)
+class PackableStorageWithOptionalGC(PackableStorage):
+
+ def checkPackAllRevisionsNoGC(self):
+ self._initroot()
+ eq = self.assertEqual
+ raises = self.assertRaises
+ # Create a `persistent' object
+ obj = self._newobj()
+ oid = obj.getoid()
+ obj.value = 1
+ # Commit three different revisions
+ revid1 = self._dostoreNP(oid, data=pdumps(obj))
+ obj.value = 2
+ revid2 = self._dostoreNP(oid, revid=revid1, data=pdumps(obj))
+ obj.value = 3
+ revid3 = self._dostoreNP(oid, revid=revid2, data=pdumps(obj))
+ # Now make sure all three revisions can be extracted
+ data = self._storage.loadSerial(oid, revid1)
+ pobj = pickle.loads(data)
+ eq(pobj.getoid(), oid)
+ eq(pobj.value, 1)
+ data = self._storage.loadSerial(oid, revid2)
+ pobj = pickle.loads(data)
+ eq(pobj.getoid(), oid)
+ eq(pobj.value, 2)
+ data = self._storage.loadSerial(oid, revid3)
+ pobj = pickle.loads(data)
+ eq(pobj.getoid(), oid)
+ eq(pobj.value, 3)
+ # Now pack all transactions; need to sleep a second to make
+ # sure that the pack time is greater than the last commit time.
+ now = packtime = time.time()
+ while packtime <= now:
+ packtime = time.time()
+ self._storage.pack(packtime, referencesf, gc=False)
+ # Only old revisions of the object should be gone. We don't gc
+ raises(KeyError, self._storage.loadSerial, oid, revid1)
+ raises(KeyError, self._storage.loadSerial, oid, revid2)
+ self._storage.loadSerial(oid, revid3)
+
+
+
+class PackableUndoStorage(PackableStorageBase):
+
def checkPackUnlinkedFromRoot(self):
eq = self.assertEqual
db = DB(self._storage)
Modified: ZODB/trunk/src/ZODB/tests/testDemoStorage.py
===================================================================
--- ZODB/trunk/src/ZODB/tests/testDemoStorage.py 2008-11-01 18:07:33 UTC (rev 92740)
+++ ZODB/trunk/src/ZODB/tests/testDemoStorage.py 2008-11-01 18:07:39 UTC (rev 92741)
@@ -77,8 +77,6 @@
pass # we don't support undo yet
checkUndoZombie = checkLoadBeforeUndo
- def checkPackWithMultiDatabaseReferences(self):
- pass # we never do gc
class DemoStorageWrappedBase(DemoStorageTests):
@@ -94,6 +92,13 @@
def _makeBaseStorage(self):
raise NotImplementedError
+ def checkPackOnlyOneObject(self):
+ pass # Wrapping demo storages don't do gc
+
+ def checkPackWithMultiDatabaseReferences(self):
+ pass # we never do gc
+ checkPackAllRevisions = checkPackWithMultiDatabaseReferences
+
class DemoStorageWrappedAroundMappingStorage(DemoStorageWrappedBase):
def _makeBaseStorage(self):
Modified: ZODB/trunk/src/ZODB/tests/testMappingStorage.py
===================================================================
--- ZODB/trunk/src/ZODB/tests/testMappingStorage.py 2008-11-01 18:07:33 UTC (rev 92740)
+++ ZODB/trunk/src/ZODB/tests/testMappingStorage.py 2008-11-01 18:07:39 UTC (rev 92741)
@@ -34,7 +34,7 @@
IteratorStorage.ExtendedIteratorStorage,
IteratorStorage.IteratorStorage,
MTStorage.MTStorage,
- PackableStorage.PackableStorage,
+ PackableStorage.PackableStorageWithOptionalGC,
RevisionStorage.RevisionStorage,
Synchronization.SynchronizedStorage,
):
More information about the Zodb-checkins
mailing list