mò &U²Ic@sTdZdkZdkZdkZdkZdkZdkZdklZdklZye e fWne j odZ dZ nXdZ ydk lZlZe ZWnej o e ZnXdkZdklZyd klZlZWn&ej od klZlZnXd eifd „ƒYZd efd „ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZ defd„ƒYZ!de!fd„ƒYZ"de!fd„ƒYZ#de!fd„ƒYZ$d e!fd!„ƒYZ%d"„Z&e'd#joei(d$d%ƒndS(&s-TestCases for multi-threaded access to a DB. N(spprint(srandomiit-(sThreads currentThread(sverbose(sdbsdbutilstBaseThreadedTestCasecBsGtZeiZdZdZdZd„Zd„Z d„Z d„Z RS(NicCs4totit_ntiitiiti dƒdƒ}||_ yti |ƒWn/t j o#}|itijo‚q‹nXtiƒ|_|iƒ|ii||itiBƒ|iid|_ti|iƒ|_|io|ii|iƒn|ii|i|i|i tiBƒdS(Nitdb_homes.db(!tverbosetsyststdouttdbutilst_deadlock_VerboseFiletostpathtjointdirnametargvthomeDirtselftmkdirtOSErrorteterrnotEEXISTtdbtDBEnvtenvt setEnvOptstopentenvflagst DB_CREATEt __class__t__name__tfilenametDBtdt dbsetflagst set_flagstdbtypet dbopenflags(RRR ((t3/data/zmath/lib/python2.4/bsddb/test/test_thread.pytsetUp.s"(    cCs.|iiƒ|iiƒti|iƒdS(N(RRtcloseRtshutiltrmtreeR (R((R$ttearDownBs  cCsdS(N((R((R$RGscCsti|gdƒS(Ni(tDASHR tkey(RR+((R$tmakeDataJs( Rt __module__Rt DB_UNKNOWNR"R#R RR%R)RR,(((R$R(s    tConcurrentDataStoreBasecBsUtZeiZeieiBeiBZdZdZ dZ d„Z d„Z d„Z RS(Niièc Csto dGddGHd|iiGHng}xUt|iƒD]D}td|i d|i |i |fdd|ƒ}|i |ƒq=WxOt|iƒD]>}td|id|i |fdd |ƒ}|i |ƒq•Wx|D]}|iƒqÞWx|D]}|iƒqùWdS( Ns s-=is(Running %s.test01_1WriterMultiReaders...ttargettargstnames writer %ds reader %d(RRRRtthreadstrangetwriterstxtThreadt writerThreadRtrecordstwttappendtreaderst readerThreadtrttttstartR (RR>R:R3R?R6((R$ttest01_1WriterMultiReadersXs,   c Csëtƒiƒ}||}||dd}tod|||fGHnxtt||ƒD]c}d|}t i |i||i|ƒddƒto'|ddjod|||fGHqXqXWto d |GHnto d |GHndS( Nis%s: creating records %d - %ds%04dt max_retriesi idis%s: records %d - %d finisheds%s: finished creating recordss%s: thread finished(t currentThreadtgetNameR2thowManyt writerNumR@tstopRR4R6R+Rt DeadlockWrapRtputRR,( RRRERFRGR@R+R6R2((R$R8rs     c Csètid|ƒtƒiƒ} x­tdƒD]Ÿ}|i ƒ}d}|i ƒ}xG|o?|d7}|\}}|i|i|ƒ|ƒ|iƒ}qTWtod| |fGHn|iƒtidƒq-Wto d| GHndS(Nf0.01iiis%s: found %d recordsf0.050000000000000003s%s: thread finished(ttimetsleept readerNumRCRDR2R4tloopRtcursortctcounttfirsttrecR+tdataRt assertEqualR,tnextRR&( RRRLRPROR+RRRSRMR2((R$R=’s&      (RR-Rt DB_THREADR#t DB_INIT_CDBt DB_INIT_MPOOLRR<R5R9RAR8R=(((R$R/Qs   tBTreeConcurrentDataStorecBs#tZeiZdZdZdZRS(Nii iè(RR-RtDB_BTREER"R5R<R9(((R$RY¨s tHashConcurrentDataStorecBs#tZeiZdZdZdZRS(Nii iè(RR-RtDB_HASHR"R5R<R9(((R$R[¯s tSimpleThreadedBasecBs^tZeiZeieiBeiBZdZdZ dZ d„Z d„Z d„Z d„ZRS(NiiiècCs|iitiƒdS(N(RRt set_lk_detectRtDB_LOCK_DEFAULT(R((R$R¿sc Csto dGddGHd|iiGHng}xUt|iƒD]D}td|i d|i |i |fdd|ƒ}|i |ƒq=WxOt|iƒD]>}td|id|i |fdd |ƒ}|i |ƒq•Wx|D]}|iƒqÞWx|D]}|iƒqùWdS( Ns s-=is Running %s.test02_SimpleLocks...R0R1R2s writer %ds reader %d(RRRRR3R4R5R6R7R8RR9R:R;R<R=R>R?R@R (RR>R:R3R?R6((R$ttest02_SimpleLocksÂs,   c CsUtƒiƒ} ||}||dd}tod| ||fGHnxàt||ƒD]Ï}d|}t i |i||i|ƒddƒto'|ddjod| ||fGHntƒd jo\xYt||ƒD]D} d|}t i |i|ddƒ} |i| |i|ƒƒqÛWqXqXWyt i |iddƒWn(tij o}to d GHqpnXxÊt||ƒD]¹}d|}t i |i|ddƒ} to'|ddjod | || fGHn|i| |i|ƒƒtƒd jo7t i |i|ddƒtod | |fGHq9q€q€Wto d| GHndS(Nis%s: creating records %d - %ds%04dRBi idis%s: records %d - %d finishedf0.050000000000000003scould not complete sync()...s%s: fetched record (%s, %s)f0.10000000000000001s%s: deleted record %ss%s: thread finished(RCRDR2RERFR@RGRtxrangeR6R+RRHRRIRR,trandomtytgetRSRTtsyncRtDBIncompleteErrortvaltdelete( RRRERFRGR@RgR+R6RcRSR2((R$R8ÚsH    % c Cstid|ƒtƒiƒ} xÅtdƒD]·}|i ƒ}d}t i |iddƒ}xS|oK|d7}|\}}|i|i|ƒ|ƒt i |iddƒ}q`Wtod| |fGHn|iƒtidƒq-Wto d | GHndS( Nf0.01iiRBi is%s: found %d recordsf0.050000000000000003s%s: thread finished(RJRKRLRCRDR2R4RMRRNRORPRRHRQRRR+RSRRTR,RURR&( RRRLRPROR+RRRSRMR2((R$R=s&     (RR-RRVR#RXt DB_INIT_LOCKRR<R5R9RR`R8R=(((R$R]¸s    -tBTreeSimpleThreadedcBstZeiZRS(N(RR-RRZR"(((R$RjstHashSimpleThreadedcBstZeiZRS(N(RR-RR\R"(((R$Rk!stThreadedTransactionsBasecBs‹tZeieiBZeieiBeiBeiBei BZ dZ dZ dZ dZd„Zd„Zd„Zd„Zd„Zd„ZRS( NiiÐcCsdS(N((R((R$R5sc Cs@to dGddGHd|iiGHng}xUt|iƒD]D}td|i d|i |i |fdd|ƒ}|i |ƒq=WxOt|iƒD]>}td|id|i |fdd |ƒ}|i |ƒq•Wtd|iƒ}|iƒx|D]}|iƒqúWx|D]}|iƒqWt|_|iƒdS( Ns s-=is)Running %s.test03_ThreadedTransactions...R0R1R2s writer %ds reader %d(RRRRR3R4R5R6R7R8RR9R:R;R<R=R>tdeadlockThreadtdtR@R?R tFalset doLockDetect(RR>R:R3R?R6Rn((R$ttest03_ThreadedTransactions9s4     c Cs t}xÿ|p÷yš|iid|iƒ}xkt||ƒD]Z} d| }|i||i|ƒ|ƒto'| ddjod||| fGHq;q;W|iƒt}Wq titifj o>}tod||dfGHn|iƒtidƒq Xq WdS(Ns%04didis%s: records %d - %d finisheds%s: Aborting transaction (%s)if0.050000000000000003(RotfinishedRRt txn_begintNonettxnFlagttxnR4R@RGR6R+RRIR,RR2tcommittTrueRtDBLockDeadlockErrortDBLockNotGrantedErrorRgtabortRJRK( RRR2R@RGRvRgRrR+R6((R$tdoWriteYs$    c Cs tƒiƒ} ||}||dd}tod| ||fGHnd}x=t |||ƒD])}|i || |t|||ƒƒqaWto d| GHnto d| GHnt} x2| p*yÍg} |iid|iƒ}x~t dƒD]p}ttƒ|ƒ|} d| } |i| d|tiƒ} | dj o!|i| |ƒ| i| ƒqôqôW|i ƒt!} tod| | fGHnWq¿ti"ti#fj o>}tod | |dfGHn|i%ƒt&i'd ƒq¿Xq¿Wto d | GHndS( Nis%s: creating records %d - %dids%s: finished creating recordss%s: deleting a few recordsi s%04ds%s: deleted records %ss%s: Aborting transaction (%s)f0.050000000000000003s%s: thread finished((RCRDR2RERFR@RGRtstepR4R6RR|RtminRoRrtrecsRRsRtRuRvtintRbR+RdRtDB_RMWRSRhR;RwRxRyRzRgR{RJRK(RRRERFRvRgR@RGR}R+RRSR2RrR6((R$R8ksL '       c Cs“tid|dƒtƒiƒ} xTtdƒD]F} t}x*|p"y»|i i d|iƒ}|i|ƒ}d}|iƒ} xG| o?|d7}| \}} |i|i|ƒ| ƒ|iƒ} q†Wtod| |fGHn|iƒ|iƒt}Wq@ti ti!fj oH}tod| |dfGHn|iƒ|i#ƒtidƒq@Xq@Wtidƒq1Wto d| GHndS( Nf0.01f0.050000000000000003iiis%s: found %d recordss%s: Aborting transaction (%s)s%s: thread finished($RJRKRLRCRDR2R4RMRoRrRRRsRtRuRvRRNRORPRQRRR+RSRTR,RURR&RwRxRRyRzRgR{( RRRLRPRvRORgRrR+RRRSRMR2((R$R=”s@         cCst|_xo|iodtidƒy:|iititi ƒ}t o|o d|GHnWq ti j oq Xq WdS(Nf0.5s.deadlock: Aborted %d deadlocked transaction(s)( RxRRpRJRKRt lock_detectRtDB_LOCK_RANDOMtDB_LOCK_CONFLICTtabortedRtDBError(RR…((R$Rmµs   (RR-RRVtDB_AUTO_COMMITR#RXRit DB_INIT_LOGt DB_INIT_TXNRR<R5R9RuRRqR|R8R=Rm(((R$Rl(s%   ) !tBTreeThreadedTransactionscBs#tZeiZdZdZdZRS(NiiiÐ(RR-RRZR"R5R<R9(((R$RŠÃs tHashThreadedTransactionscBs#tZeiZdZdZdZRS(NiiiÐ(RR-RR\R"R5R<R9(((R$R‹És tBTreeThreadedNoWaitTransactionscBs,tZeiZdZdZdZeiZ RS(NiiiÐ( RR-RRZR"R5R<R9t DB_TXN_NOWAITRu(((R$RŒÏs  tHashThreadedNoWaitTransactionscBs,tZeiZdZdZdZeiZ RS(NiiiÐ( RR-RR\R"R5R<R9RRu(((R$RŽÖs  cCsÐtiƒ}to´|ititƒƒ|ititƒƒ|ititƒƒ|itit ƒƒ|itit ƒƒ|itit ƒƒ|itit ƒƒ|itit ƒƒndGH|S(Ns-Threads not available, skipping thread tests.(tunittestt TestSuitetsuitet have_threadstaddTestt makeSuiteRYR[RjRkRŠR‹RŒRŽ(R‘((R$t test_suiteàs t__main__t defaultTestR•()t__doc__RRRJRR'ttempfiletpprintRbRxRot NameErrorR*t threadingR7RCR’t ImportErrorRttest_allRtbsddb3RRtbsddbtTestCaseRR/RYR[R]RjRkRlRŠR‹RŒRŽR•Rtmain(RŽRRCRRbR'R‹R™RR/RšR•RxRŒRŠR7RjRRR]R’R*RoRkR[RlRRJRYRR((R$t?sP             )W e›