#!/usr/bin/env python # Regression test for ZCatalog import os,sys sys.path.insert(0,'.') try: import Testing except ImportError: sys.path[0] = "../../.." import Testing os.environ['STUPID_LOG_FILE']= "debug.log" here = os.getcwd() import Zope2 import ZODB, ZODB.FileStorage import transaction from Products.ZCatalog import ZCatalog,Vocabulary from Products.ZCatalog.Catalog import CatalogError import Persistence import ExtensionClass from Testing import dispatcher import keywords import getopt,random,time,string,mailbox,rfc822 import unittest_patched as unittest # maximum number of files to read for the test suite maxFiles = 1000 # maximum number of threads for stress testa numThreads = 4 # number of iterations for searches searchIterations = 1000 # number of iterations for catalog/uncatalog operations updateIterations = 100 # input mailbox file mbox = os.environ.get("TESTCATALOG_MBOX","/usr/home/andreas/zope.mbox") mbox2 = os.environ.get("TESTCATALOG_MBOX2", "/usr/home/andreas/python.mbox") dataDir = "" # # Don't change anything below # class testZODB: """ some wrapper stuff around ZODB """ def __init__(self, file = "data/work/Data.fs",open=1): self.db = ZODB.DB( ZODB.FileStorage.FileStorage(file) ) if open==1: self.connection = self.db.open() self.root = self.connection.root() def write(self,name,obj): self.root[name] = obj transaction.commit() def read(self,name): return self.root[name] def __del__(self): self.db.close() class testCatalog(Persistence.Persistent,unittest.TestCase): """ Wrapper around the catalog stuff """ def __init__(self,mboxname,maxfiles): self.msg_ids = [] self.num_files = 0 self.keywords = [] self.maxfiles = maxfiles self._vocabulary = Vocabulary.Vocabulary('Vocabulary', 'Vocabulary', globbing=1) self._catalog = ZCatalog.ZCatalog("zcatalog") self._catalog.addIndex('to', 'TextIndex') self._catalog.addIndex('sender', 'TextIndex') self._catalog.addIndex('subject', 'TextIndex') self._catalog.addIndex('content', 'TextIndex') self._catalog.addIndex('file_id', 'TextIndex') self._catalog.addColumn('file_id') self._catalog.addIndex('length', 'FieldIndex') self._catalog.addColumn('length') self._catalog.addIndex('date', 'FieldIndex') self._catalog.addIndex('keywords', "KeywordIndex") self.build_catalog(mboxname) def build_catalog(self,mboxname): mb = mailbox.UnixMailbox(open(mboxname,"r")) i = 0 msg = mb.next() while msg and self.num_files " % program print "to run the basic tests: %s -b -f " % program print "to run the advanced tests: %s -a -f " % program def main(): global dataDir,maxFiles opts,args = getopt.getopt(sys.argv[1:],"hiabf:xp",['help']) opts.sort() optsLst = map(lambda x: x[0],opts) if optsLst==[]: usage(os.path.basename(sys.argv[0])); sys.exit(0) for k,v in opts: if k in ['-h','--help'] : usage(os.path.basename(sys.argv[0])); sys.exit(0) if k == "-f": maxFiles = string.atoi(v) dataDir = os.path.join("data",str(maxFiles)) if '-i' in optsLst: unittest.TextTestRunner().run(get_tests('init')) if '-b' in optsLst: unittest.TextTestRunner().run(get_tests('bench1')) if '-a' in optsLst: unittest.TextTestRunner().run(get_tests('bench2')) if '-x' in optsLst: unittest.TextTestRunner().run(get_tests('exp')) if '-p' in optsLst: unittest.TextTestRunner().run(test_suite()) def test_suite(): return get_tests('basic') def get_tests(what): global dataDir,maxFiles if what=='basic': maxFiles = 100 dataDir = 'data/%d' % maxFiles t_aj = ( BuildEnv('buildTestEnvironment',dataDir,maxFiles), testSearches("testFulltextIndex",numThreads=1), testSearches("testFieldIndex",numThreads= 1), testSearches("testFieldRangeIndex",numThreads=1), testSearches("testKeywordIndex",numThreads= 1), testSearches("testKeywordRangeIndex",numThreads= 1) ) bench1_tests = ( testSearches("testFulltextIndex",numThreads=1), testSearches("testFulltextIndex",numThreads= 4), testSearches("testFieldIndex",numThreads= 1), testSearches("testFieldIndex",numThreads= 4), testSearches("testFieldRangeIndex",numThreads=1), testSearches("testFieldRangeIndex",numThreads= 4), testSearches("testKeywordIndex",numThreads= 1), testSearches("testKeywordIndex",numThreads= 4), testSearches("testKeywordRangeIndex",numThreads= 1), testSearches("testKeywordRangeIndex",numThreads=4) ) bench2_tests = ( # testSearches("testReindexing",numThreads=1), # testSearches("testIncrementalIndexing",numThreads=1), testSearches("testUpdates",numThreads=2,numUpdates=200), # testSearches("testUpdates",numThreads=4,numUpdates=200) ) exp_tests = ( # testRS("testRangeSearch"), # testSearches("testReindexing",numThreads=1), testSearches("testReindexingAndModify",numThreads=1), # testSearches("testUpdates",numThreads=10,numUpdates=100), ) init_tests = ( BuildEnv("buildTestEnvironment",dataDir,maxFiles) , ) ts = unittest.TestSuite() for x in eval('%s_tests' % what): ts.addTest(x) return ts return def pdebug(): import pdb test_suite() def debug(): test_suite().debug() def pdebug(): import pdb pdb.run('debug()') if __name__ == '__main__': main()