[Zodb-checkins] CVS: ZODB3/ZEO/tests - ConnectionTests.py:1.4.2.1.6.1

Jeremy Hylton jeremy@zope.com
Tue, 17 Dec 2002 18:22:36 -0500


Update of /cvs-repository/ZODB3/ZEO/tests
In directory cvs.zope.org:/tmp/cvs-serv5647/ZEO/tests

Modified Files:
      Tag: ZODB3-fast-restart-branch
	ConnectionTests.py 
Log Message:
Add several tests of short circuit cache verification.

Fix DummyDB to accept kwargs to invalidate().

Add TestClientStorage wrapper that keeps the return value of
verify_cache().


=== ZODB3/ZEO/tests/ConnectionTests.py 1.4.2.1 => 1.4.2.1.6.1 ===
--- ZODB3/ZEO/tests/ConnectionTests.py:1.4.2.1	Thu Oct  3 20:09:05 2002
+++ ZODB3/ZEO/tests/ConnectionTests.py	Tue Dec 17 18:22:36 2002
@@ -32,8 +32,13 @@
 from ZODB.tests import StorageTestBase
 from ZODB.tests.StorageTestBase import zodb_unpickle, MinPO
 
+class TestClientStorage(ClientStorage):
+
+    def verify_cache(self, stub):
+        self.verify_result = ClientStorage.verify_cache(self, stub)
+
 class DummyDB:
-    def invalidate(self, *args):
+    def invalidate(self, *args, **kwargs):
         pass
 
 class ConnectionTests(StorageTestBase.StorageTestBase):
@@ -71,13 +76,13 @@
 
     def openClientStorage(self, cache='', cache_size=200000, wait=1,
                           read_only=0, read_only_fallback=0):
-        base = ClientStorage(self.addr,
-                             client=cache,
-                             cache_size=cache_size,
-                             wait=wait,
-                             min_disconnect_poll=0.1,
-                             read_only=read_only,
-                             read_only_fallback=read_only_fallback)
+        base = TestClientStorage(self.addr,
+                                 client=cache,
+                                 cache_size=cache_size,
+                                 wait=wait,
+                                 min_disconnect_poll=0.1,
+                                 read_only=read_only,
+                                 read_only_fallback=read_only_fallback)
         storage = base
         storage.registerDB(DummyDB(), None)
         return storage
@@ -503,3 +508,105 @@
 
         self._storage = self.openClientStorage()
         self._dostore()
+
+    def checkNoVerificationOnServerRestart(self):
+        self._storage = self.openClientStorage()
+        # When we create a new storage, it should always do a full
+        # verification
+        self.assertEqual(self._storage.verify_result, "full verification")
+        self._dostore()
+        self.shutdownServer()
+        self.pollDown()
+        self._storage.verify_result = None
+        self.startServer(create=0)
+        self.pollUp()
+        # There were no transactions committed, so no verification
+        # should be needed.
+        self.assertEqual(self._storage.verify_result, "no verification")
+        
+    def checkNoVerificationOnServerRestartWith2Clients(self):
+        perstorage = self.openClientStorage(cache="test")
+        self.assertEqual(perstorage.verify_result, "full verification")
+        
+        self._storage = self.openClientStorage()
+        oid = self._storage.new_oid()
+        # When we create a new storage, it should always do a full
+        # verification
+        self.assertEqual(self._storage.verify_result, "full verification")
+        # do two storages of the object to make sure an invalidation
+        # message is generated
+        revid = self._dostore(oid)
+        self._dostore(oid, revid)
+
+        perstorage.load(oid, '')
+
+        self.shutdownServer()
+
+        self.pollDown()
+        self._storage.verify_result = None
+        perstorage.verify_result = None
+        self.startServer(create=0)
+        self.pollUp()
+        # There were no transactions committed, so no verification
+        # should be needed.
+        self.assertEqual(self._storage.verify_result, "no verification")
+
+        perstorage.close()
+        self.assertEqual(perstorage.verify_result, "no verification")
+
+    def checkQuickVerificationWith2Clients(self):
+        perstorage = self.openClientStorage(cache="test")
+        self.assertEqual(perstorage.verify_result, "full verification")
+        
+        self._storage = self.openClientStorage()
+        oid = self._storage.new_oid()
+        # When we create a new storage, it should always do a full
+        # verification
+        self.assertEqual(self._storage.verify_result, "full verification")
+        # do two storages of the object to make sure an invalidation
+        # message is generated
+        revid = self._dostore(oid)
+        revid = self._dostore(oid, revid)
+
+        perstorage.load(oid, '')
+        perstorage.close()
+        
+        revid = self._dostore(oid, revid)
+
+        perstorage = self.openClientStorage(cache="test")
+        self.assertEqual(perstorage.verify_result, "quick verification")
+
+        self.assertEqual(perstorage.load(oid, ''),
+                         self._storage.load(oid, ''))
+
+
+
+    def checkVerificationWith2ClientsInvqOverflow(self):
+        perstorage = self.openClientStorage(cache="test1")
+        self.assertEqual(perstorage.verify_result, "full verification")
+        
+        self._storage = self.openClientStorage()
+        oid = self._storage.new_oid()
+        # When we create a new storage, it should always do a full
+        # verification
+        self.assertEqual(self._storage.verify_result, "full verification")
+        # do two storages of the object to make sure an invalidation
+        # message is generated
+        revid = self._dostore(oid)
+        revid = self._dostore(oid, revid)
+
+        perstorage.load(oid, '')
+        perstorage.close()
+
+        # the test code sets invq bound to 2
+        for i in range(5):
+            revid = self._dostore(oid, revid)
+
+        perstorage = self.openClientStorage(cache="test1")
+        self.assertEqual(perstorage.verify_result, "full verification")
+        perstorage.sync()
+
+        self.assertEqual(self._storage.load(oid, '')[1], revid)
+        self.assertEqual(perstorage.load(oid, ''),
+                         self._storage.load(oid, ''))
+