[Zope-Checkins] CVS: Zope/lib/python/Products/ZCTextIndex/tests - testIndex.py:1.11.74.1
Casey Duncan
casey@zope.com
Wed, 4 Jun 2003 00:26:39 -0400
Update of /cvs-repository/Zope/lib/python/Products/ZCTextIndex/tests
In directory cvs.zope.org:/tmp/cvs-serv20173/tests
Modified Files:
Tag: casey-zctextindex-fewer-conflicts-branch
testIndex.py
Log Message:
Change _totaldoclen to a BTree.Length.Length to avoid write conflicts. Add tests for conflicts on index and reindex. These failed before the change to _totaldoclen, but now pass.
=== Zope/lib/python/Products/ZCTextIndex/tests/testIndex.py 1.11 => 1.11.74.1 ===
--- Zope/lib/python/Products/ZCTextIndex/tests/testIndex.py:1.11 Wed Jun 12 17:45:53 2002
+++ Zope/lib/python/Products/ZCTextIndex/tests/testIndex.py Wed Jun 4 00:26:39 2003
@@ -12,6 +12,7 @@
#
##############################################################################
+import os
from unittest import TestCase, TestSuite, main, makeSuite
from Products.ZCTextIndex.Lexicon import Lexicon, Splitter
@@ -145,9 +146,75 @@
class OkapiIndexTest(IndexTest):
IndexFactory = OkapiIndex
+class TestIndexConflict(TestCase):
+
+ storage = None
+
+ def tearDown(self):
+ if self.storage is not None:
+ self.storage.close()
+
+ def openDB(self):
+ from ZODB.FileStorage import FileStorage
+ from ZODB.DB import DB
+ n = 'fs_tmp__%s' % os.getpid()
+ self.storage = FileStorage(n)
+ self.db = DB(self.storage)
+
+ def test_index_doc_conflict(self):
+ self.index = OkapiIndex(Lexicon())
+ self.openDB()
+ r1 = self.db.open().root()
+ r1['i'] = self.index
+ get_transaction().commit()
+
+ r2 = self.db.open().root()
+ copy = r2['i']
+ # Make sure the data is loaded
+ list(copy._docweight.items())
+ list(copy._docwords.items())
+ list(copy._wordinfo.items())
+ list(copy._lexicon._wids.items())
+ list(copy._lexicon._words.items())
+
+ self.assertEqual(self.index._p_serial, copy._p_serial)
+
+ self.index.index_doc(0, 'The time has come')
+ get_transaction().commit()
+
+ copy.index_doc(1, 'That time has gone')
+ get_transaction().commit()
+
+ def test_reindex_doc_conflict(self):
+ self.index = OkapiIndex(Lexicon())
+ self.index.index_doc(0, 'Sometimes change is good')
+ self.index.index_doc(1, 'Then again, who asked')
+ self.openDB()
+ r1 = self.db.open().root()
+ r1['i'] = self.index
+ get_transaction().commit()
+
+ r2 = self.db.open().root()
+ copy = r2['i']
+ # Make sure the data is loaded
+ list(copy._docweight.items())
+ list(copy._docwords.items())
+ list(copy._wordinfo.items())
+ list(copy._lexicon._wids.items())
+ list(copy._lexicon._words.items())
+
+ self.assertEqual(self.index._p_serial, copy._p_serial)
+
+ self.index.index_doc(0, 'Sometimes change isn\'t bad')
+ get_transaction().commit()
+
+ copy.index_doc(1, 'Then again, who asked you?')
+ get_transaction().commit()
+
def test_suite():
return TestSuite((makeSuite(CosineIndexTest),
makeSuite(OkapiIndexTest),
+ makeSuite(TestIndexConflict),
))
if __name__=='__main__':