[Zope-Checkins] CVS: Zope2 - testCatalog.py:1.1.2.22
Andreas Jung
andreas@yetix.digicool.com
Fri, 9 Mar 2001 10:05:32 -0500
Update of /mnt/cvs-repository/Zope2/lib/python/Products/ZCatalog/tests
In directory yetix:/work/Zope2/CatalogUnit/lib/python/Products/ZCatalog/tests
Modified Files:
Tag: Catalog-Unittest-Branch
testCatalog.py
Log Message:
rewrote testUpdates()
--- Updated File testCatalog.py in package test --
--- testCatalog.py 2001/03/08 18:42:28 1.1.2.21
+++ testCatalog.py 2001/03/09 15:05:28 1.1.2.22
@@ -7,6 +7,9 @@
Andreas Jung, andreas@digicool.com
$Log$
+ Revision 1.1.2.22 2001/03/09 15:05:28 andreas
+ rewrote testUpdates()
+
Revision 1.1.2.21 2001/03/08 18:42:28 andreas
fixed typo
@@ -419,29 +422,39 @@
#############################################################
def testUpdates(self,args,kw):
- """ test reindexing of existing data """
- self.dispatcher("testUpdates" , ("funcUpdates",4 , () , {} ))
+ """ benchmark concurrent catalog/uncatalog operations """
+ self.dispatcher("testUpdates" , ("funcUpdates", kw["numThreads"] , args, kw ))
- def funcUpdates(self,*args):
- """ benchmark catalog/uncatalog operations """
+ def funcUpdates(self,*args,**kw):
+ """ benchmark concurrent catalog/uncatalog operations """
+
+
conflicts = 0
cat,msg_ids = self.get_catalog()
+ msgs = self.setupUpdatesMethod(kw["numUpdates"])
+ keys = msgs.keys()
+
env = self.th_setup()
+
+ for i in range(len(keys)):
+
+ r = whrandom.randint(0,len(msgs)-1)
- for i in range(updateIterations):
+ mid = keys[r]
+ obj = msgs[mid]
- r = whrandom.randint(0,len(msg_ids)-1)
try:
- cat.uncatMessage(msg_ids[r])
- cat.catalogObject("This test sucks",r)
- if i%10 ==0: get_transaction().commit()
+ cat.uncatalogObject(mid)
+ cat.catalogObject(obj,mid)
+ get_transaction().commit()
+ time.sleep(0.1)
except ZODB.POSException.ConflictError:
- print sys.exc_type,sys.exc_value
+# print sys.exc_type,sys.exc_value
conflicts = conflicts + 1
try:
@@ -453,13 +466,39 @@
self.th_teardown(env,conflicts=conflicts)
+ def setupUpdatesMethod(self,numUpdates):
+ """ this method prepares a datastructure for the updates test.
+ we are reading the first n mails from the primary mailbox.
+ they are used for the update test
+ """
+
+ i = 0
+ dict = {}
+
+ mb = mailbox.UnixMailbox(open(mbox,"r"))
+
+ msg = mb.next()
+ while msg and i<numUpdates:
+
+ obj = testMessage(msg)
+ mid = msg.dict["message-id"]
+
+ dict[mid] = obj
+
+ msg = mb.next()
+ i = i+1
+
+ return dict
+
+
+
#############################################################
# Test full reindexing
#############################################################
def testReindexing(self,args,kw):
""" test reindexing of existing data """
- self.dispatcher("testReindexing" , ("funcReindexing",1 , (mbox,1000) , {} ))
+ self.dispatcher("testReindexing" , ("funcReindexing",kw["numThreads"] , (mbox,1000) , {} ))
def funcReindexing(self,mbox,numfiles=100):
@@ -498,7 +537,7 @@
def testIncrementalIndexing(self,args,kw):
""" testing incremental indexing """
- self.dispatcher("testIncrementalIndexing" , ("funcReindexing",1, (mbox2,1000) , {}))
+ self.dispatcher("testIncrementalIndexing" , ("funcReindexing",kw["numThreads"], (mbox2,1000) , {}))
def get_catalog(self):
@@ -587,9 +626,10 @@
if '-a' in optsLst:
basic_tests = [
- testSearches("testUpdates",(),{"numThreads" : 4}),
- testSearches("testReindexing",(),{"numThreads" : 1}),
- testSearches("testIncrementalIndexing",(),{"numThreads" : 1})
+ testSearches("testReindexing",numThreads=1),
+ testSearches("testIncrementalIndexing",numThreads=1),
+ testSearches("testUpdates",numThreads=2,numUpdates=200),
+ testSearches("testUpdates",numThreads=4,numUpdates=200)
]
testsuite1 = TestSuite()
--- Updated File testCatalog.py in package Zope2 --
--- testCatalog.py 2001/03/08 18:42:28 1.1.2.21
+++ testCatalog.py 2001/03/09 15:05:28 1.1.2.22
@@ -7,6 +7,9 @@
Andreas Jung, andreas@digicool.com
$Log$
+ Revision 1.1.2.22 2001/03/09 15:05:28 andreas
+ rewrote testUpdates()
+
Revision 1.1.2.21 2001/03/08 18:42:28 andreas
fixed typo
@@ -419,29 +422,39 @@
#############################################################
def testUpdates(self,args,kw):
- """ test reindexing of existing data """
- self.dispatcher("testUpdates" , ("funcUpdates",4 , () , {} ))
+ """ benchmark concurrent catalog/uncatalog operations """
+ self.dispatcher("testUpdates" , ("funcUpdates", kw["numThreads"] , args, kw ))
- def funcUpdates(self,*args):
- """ benchmark catalog/uncatalog operations """
+ def funcUpdates(self,*args,**kw):
+ """ benchmark concurrent catalog/uncatalog operations """
+
+
conflicts = 0
cat,msg_ids = self.get_catalog()
+ msgs = self.setupUpdatesMethod(kw["numUpdates"])
+ keys = msgs.keys()
+
env = self.th_setup()
+
+ for i in range(len(keys)):
+
+ r = whrandom.randint(0,len(msgs)-1)
- for i in range(updateIterations):
+ mid = keys[r]
+ obj = msgs[mid]
- r = whrandom.randint(0,len(msg_ids)-1)
try:
- cat.uncatMessage(msg_ids[r])
- cat.catalogObject("This test sucks",r)
- if i%10 ==0: get_transaction().commit()
+ cat.uncatalogObject(mid)
+ cat.catalogObject(obj,mid)
+ get_transaction().commit()
+ time.sleep(0.1)
except ZODB.POSException.ConflictError:
- print sys.exc_type,sys.exc_value
+# print sys.exc_type,sys.exc_value
conflicts = conflicts + 1
try:
@@ -453,13 +466,39 @@
self.th_teardown(env,conflicts=conflicts)
+ def setupUpdatesMethod(self,numUpdates):
+ """ this method prepares a datastructure for the updates test.
+ we are reading the first n mails from the primary mailbox.
+ they are used for the update test
+ """
+
+ i = 0
+ dict = {}
+
+ mb = mailbox.UnixMailbox(open(mbox,"r"))
+
+ msg = mb.next()
+ while msg and i<numUpdates:
+
+ obj = testMessage(msg)
+ mid = msg.dict["message-id"]
+
+ dict[mid] = obj
+
+ msg = mb.next()
+ i = i+1
+
+ return dict
+
+
+
#############################################################
# Test full reindexing
#############################################################
def testReindexing(self,args,kw):
""" test reindexing of existing data """
- self.dispatcher("testReindexing" , ("funcReindexing",1 , (mbox,1000) , {} ))
+ self.dispatcher("testReindexing" , ("funcReindexing",kw["numThreads"] , (mbox,1000) , {} ))
def funcReindexing(self,mbox,numfiles=100):
@@ -498,7 +537,7 @@
def testIncrementalIndexing(self,args,kw):
""" testing incremental indexing """
- self.dispatcher("testIncrementalIndexing" , ("funcReindexing",1, (mbox2,1000) , {}))
+ self.dispatcher("testIncrementalIndexing" , ("funcReindexing",kw["numThreads"], (mbox2,1000) , {}))
def get_catalog(self):
@@ -587,9 +626,10 @@
if '-a' in optsLst:
basic_tests = [
- testSearches("testUpdates",(),{"numThreads" : 4}),
- testSearches("testReindexing",(),{"numThreads" : 1}),
- testSearches("testIncrementalIndexing",(),{"numThreads" : 1})
+ testSearches("testReindexing",numThreads=1),
+ testSearches("testIncrementalIndexing",numThreads=1),
+ testSearches("testUpdates",numThreads=2,numUpdates=200),
+ testSearches("testUpdates",numThreads=4,numUpdates=200)
]
testsuite1 = TestSuite()