[Zope3-checkins] CVS: Zope3/src/zodb/storage/tests - version.py:1.8 undo.py:1.12 test_memory.py:1.2 test_fsindex.py:1.3 test_file.py:1.11 packable.py:1.8 base.py:1.15

Jeremy Hylton jeremy@zope.com
Tue, 22 Apr 2003 11:23:43 -0400


Update of /cvs-repository/Zope3/src/zodb/storage/tests
In directory cvs.zope.org:/tmp/cvs-serv13741/tests

Modified Files:
	version.py undo.py test_memory.py test_fsindex.py test_file.py 
	packable.py base.py 
Log Message:
Merge the jeremy-new-pack-branch to the trunk.

The primary change is a completely new implementation of file storage pack.


=== Zope3/src/zodb/storage/tests/version.py 1.7 => 1.8 ===
--- Zope3/src/zodb/storage/tests/version.py:1.7	Thu Mar 20 18:01:41 2003
+++ Zope3/src/zodb/storage/tests/version.py	Tue Apr 22 11:23:12 2003
@@ -336,7 +336,51 @@
 
         snooze()
         self._storage.pack(time.time())
+        
+        db.commitVersion("testversion")
+        txn = get_transaction()
+        txn.note("commit version")
+        txn.commit()
+        
+        cn = db.open()
+        root = cn.root()
+        root["obj"] = "no version"
+
+        txn = get_transaction()
+        txn.note("modify obj")
+        txn.commit()
+
+        self._storage.pack(time.time())
+
+    def testPackVersionsInPast(self):
+        db = DB(self._storage)
+        cn = db.open(version="testversion")
+        root = cn.root()
+
+        obj = root["obj"] = MinPO("obj")
+        root["obj2"] = MinPO("obj2")
+        txn = get_transaction()
+        txn.note("create 2 objs in version")
+        txn.commit()
+
+        obj.value = "77"
+        txn = get_transaction()
+        txn.note("modify obj in version")
+        txn.commit()
 
+        t0 = time.time()
+        snooze()
+
+        # undo the modification to generate a mix of backpointers
+        # and versions for pack to chase
+        info = db.undoInfo()
+        db.undo(info[0]["id"])
+        txn = get_transaction()
+        txn.note("undo modification")
+        txn.commit()
+
+        self._storage.pack(t0)
+        
         db.commitVersion("testversion")
         txn = get_transaction()
         txn.note("commit version")
@@ -352,3 +396,64 @@
 
         self._storage.pack(time.time())
 
+    def testPackVersionReachable(self):
+        db = DB(self._storage)
+        cn = db.open()
+        root = cn.root()
+
+        names = "a", "b", "c"
+
+        for name in names:
+            root[name] = MinPO(name)
+            get_transaction().commit()
+
+        for name in names:
+            cn2 = db.open(version=name)
+            rt2 = cn2.root()
+            obj = rt2[name]
+            obj.value = MinPO("version")
+            get_transaction().commit()
+            cn2.close()
+
+        root["d"] = MinPO("d")
+        get_transaction().commit()
+
+        self._storage.pack(time.time())
+        cn.sync()
+        cn._cache.clear()
+
+        # make sure all the non-version data is there
+        for name, obj in root.items():
+            self.assertEqual(name, obj.value)
+
+        # make sure all the version-data is there,
+        # and create a new revision in the version
+        for name in names:
+            cn2 = db.open(version=name)
+            rt2 = cn2.root()
+            obj = rt2[name].value
+            self.assertEqual(obj.value, "version")
+            obj.value = "still version"
+            get_transaction().commit()
+            cn2.close()
+
+        db.abortVersion("b")
+        txn = get_transaction()
+        txn.note("abort version b")
+        txn.commit()
+
+        t = time.time()
+        snooze()
+        
+        L = db.undoInfo()
+        db.undo(L[0]["id"])
+        txn = get_transaction()
+        txn.note("undo abort")
+        txn.commit()
+        
+        self._storage.pack(t)
+
+        cn2 = db.open(version="b")
+        rt2 = cn2.root()
+        self.assertEqual(rt2["b"].value.value, "still version")
+            


=== Zope3/src/zodb/storage/tests/undo.py 1.11 => 1.12 ===
--- Zope3/src/zodb/storage/tests/undo.py:1.11	Thu Apr 10 03:27:30 2003
+++ Zope3/src/zodb/storage/tests/undo.py	Tue Apr 22 11:23:12 2003
@@ -21,6 +21,14 @@
 class C(Persistent):
     pass
 
+def listeq(L1, L2):
+    """Return True if L1.sort() == L2.sort()"""
+    c1 = L1[:]
+    c2 = L2[:]
+    c1.sort()
+    c2.sort()
+    return c1 == c2
+
 class TransactionalUndoStorage:
 
     def _transaction_begin(self):
@@ -389,7 +397,6 @@
         eq(zodb_unpickle(data), MinPO(54))
         self._iterate()
 
-
     def testNotUndoable(self):
         eq = self.assertEqual
         # Set things up so we've got a transaction that can't be undone
@@ -540,6 +547,98 @@
         eq(o1.obj, o2)
         eq(o1.obj.obj, o3)
         self._iterate()
+
+    def testPackAfterUndoDeletion(self):
+        db = DB(self._storage)
+        cn = db.open()
+        root = cn.root()
+
+        pack_times = []
+        def set_pack_time():
+            snooze()
+            pack_times.append(time.time())
+
+        root["key0"] = MinPO(0)
+        root["key1"] = MinPO(1)
+        root["key2"] = MinPO(2)
+        txn = get_transaction()
+        txn.note("create 3 keys")
+        txn.commit()
+
+        set_pack_time()
+
+        del root["key1"]
+        txn = get_transaction()
+        txn.note("delete 1 key")
+        txn.commit()
+
+        set_pack_time()
+        
+        root._p_deactivate()
+        cn.sync()
+        self.assert_(listeq(root.keys(), ["key0", "key2"]))
+        
+        L = db.undoInfo()
+        db.undo(L[0]["id"])
+        txn = get_transaction()
+        txn.note("undo deletion")
+        txn.commit()
+
+        set_pack_time()
+
+        root._p_deactivate()
+        cn.sync()
+        self.assert_(listeq(root.keys(), ["key0", "key1", "key2"]))
+        
+        for t in pack_times:
+            self._storage.pack(t)
+
+            root._p_deactivate()
+            cn.sync()
+            self.assert_(listeq(root.keys(), ["key0", "key1", "key2"]))
+            for i in range(3):
+                obj = root["key%d" % i]
+                self.assertEqual(obj.value, i)
+            root.items()
+
+    def testPackAfterUndoManyTimes(self):
+        db = DB(self._storage)
+        cn = db.open()
+        rt = cn.root()
+
+        rt["test"] = MinPO(1)
+        get_transaction().commit()
+        rt["test2"] = MinPO(2)
+        get_transaction().commit()
+        rt["test"] = MinPO(3)
+        txn = get_transaction()
+        txn.note("root of undo")
+        txn.commit()
+
+        packtimes = []
+        for i in range(10):
+            L = db.undoInfo()
+            db.undo(L[0]["id"])
+            txn = get_transaction()
+            txn.note("undo %d" % i)
+            txn.commit()
+            rt._p_deactivate()
+            cn.sync()
+
+            self.assertEqual(rt["test"].value, i % 2 and 3 or 1)
+            self.assertEqual(rt["test2"].value, 2)
+            
+            packtimes.append(time.time())
+            snooze()
+
+        for t in packtimes:
+            self._storage.pack(t)
+            cn.sync()
+            cn._cache.clear()
+            # The last undo set the value to 3 and pack should
+            # never change that.
+            self.assertEqual(rt["test"].value, 3)
+            self.assertEqual(rt["test2"].value, 2)
 
     def testTransactionalUndoIterator(self):
         # check that data_txn set in iterator makes sense


=== Zope3/src/zodb/storage/tests/test_memory.py 1.1 => 1.2 ===
--- Zope3/src/zodb/storage/tests/test_memory.py:1.1	Thu Mar 20 18:02:10 2003
+++ Zope3/src/zodb/storage/tests/test_memory.py	Tue Apr 22 11:23:12 2003
@@ -45,7 +45,7 @@
     def open(self, read_only=False):
         config = BerkeleyConfig()
         config.read_only = read_only
-        self._storage = MemoryFullStorage(config)
+        self._storage = MemoryFullStorage('memory', config=config)
 
     def setUp(self):
         self.open()
@@ -70,7 +70,7 @@
     def open(self, read_only=False):
         config = BerkeleyConfig()
         config.read_only = read_only
-        self._storage = MemoryMinimalStorage(config)
+        self._storage = MemoryMinimalStorage('memory', config=config)
 
     def setUp(self):
         self.open()


=== Zope3/src/zodb/storage/tests/test_fsindex.py 1.2 => 1.3 ===
--- Zope3/src/zodb/storage/tests/test_fsindex.py:1.2	Wed Dec 25 09:12:20 2002
+++ Zope3/src/zodb/storage/tests/test_fsindex.py	Tue Apr 22 11:23:12 2003
@@ -13,7 +13,7 @@
 ##############################################################################
 
 import unittest, sys
-from zodb.storage.fsindex import fsIndex
+from zodb.storage.file.index import fsIndex
 from zodb.utils import p64
 
 


=== Zope3/src/zodb/storage/tests/test_file.py 1.10 => 1.11 ===
--- Zope3/src/zodb/storage/tests/test_file.py:1.10	Thu Mar 20 18:01:41 2003
+++ Zope3/src/zodb/storage/tests/test_file.py	Tue Apr 22 11:23:12 2003
@@ -67,8 +67,8 @@
             copy = zodb.storage.file.FileStorage('FileStorageTests.fs',
                                                  read_only=True)
         except:
-            from zodb.storage.fsdump import Dumper
-            Dumper("FileStorageTests.fs").dump()
+            from zodb.storage.file.dump import dump
+            dump("FileStorageTests.fs")
             raise
 
         L1 = copy._index.items()


=== Zope3/src/zodb/storage/tests/packable.py 1.7 => 1.8 ===
--- Zope3/src/zodb/storage/tests/packable.py:1.7	Thu Mar 20 18:01:41 2003
+++ Zope3/src/zodb/storage/tests/packable.py	Tue Apr 22 11:23:12 2003
@@ -23,7 +23,7 @@
 from zodb.ztransaction import Transaction
 from zodb.storage.tests.minpo import MinPO
 from zodb.storage.tests.base import zodb_unpickle, snooze
-from zodb.storage.fsdump import dump
+from zodb.storage.file.dump import dump
 
 
 


=== Zope3/src/zodb/storage/tests/base.py 1.14 => 1.15 ===
--- Zope3/src/zodb/storage/tests/base.py:1.14	Wed Apr 16 18:06:21 2003
+++ Zope3/src/zodb/storage/tests/base.py	Tue Apr 22 11:23:12 2003
@@ -32,6 +32,7 @@
 
 from zodb.db import DB
 from zodb.serialize import ConnectionObjectReader, ObjectWriter, findrefs
+from zodb.conflict import ResolveObjectReader
 from zodb.ztransaction import Transaction
 from zodb.storage.tests.minpo import MinPO
 from zodb.storage.base import ZERO, BerkeleyConfig
@@ -61,7 +62,9 @@
 
 def zodb_unpickle(data):
     """Unpickle an object stored using the format expected by ZODB."""
-    u = ConnectionObjectReader(None, FakeCache())
+    # Use a ResolveObjectReader because we don't want to load any
+    # object referenced by this one.
+    u = ResolveObjectReader()
     return u.getObject(data)
 
 def handle_all_serials(oid, *args):