Plan 9 from Bell Labs’s /usr/web/sources/contrib/jas/root/sys/lib/python2.7/bsddb/test/test_thread.pyo

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


��Qc@sDdZddlZddlZddlZddlZddlmZdZyeWn'ek
r}de	fd��YZnXddl
Z
ddlmZm
Z
mZmZmZmZmZer
ddlmZejd	d
kr�dlmZq
ddlmZnd
e
jfd��YZdefd��YZdefd��YZdefd��YZdefd��YZdefd��YZdefd��YZdefd��YZ de fd��YZ!de fd ��YZ"d!e fd"��YZ#d#e fd$��YZ$d%�Z%e&d&kr@e
j'd'd(�ndS()s-TestCases for multi-threaded access to a DB.
i�N(trandomt-tWindowsErrorcBseZRS((t__name__t
__module__(((s,/sys/lib/python2.7/bsddb/test/test_thread.pyRs(tdbtdbutilsttest_supporttverbosethave_threadstget_new_environment_pathtget_new_database_path(tThreadii(t
currentThread(tcurrent_threadtBaseThreadedTestCasecBsGeZejZdZdZdZd�Zd�Z	d�Z
d�ZRS(icCs�trtjt_nt�|_tj�|_	|j
�|j	j|j|jtj
B�|jjd|_tj|j	�|_|jr�|jj|j�n|jj|j|j|jtj
B�dS(Ns.db(RtsyststdoutRt_deadlock_VerboseFileR
thomeDirRtDBEnvtenvt
setEnvOptstopentenvflagst	DB_CREATEt	__class__RtfilenametDBtdt
dbsetflagst	set_flagstdbtypetdbopenflags(tself((s,/sys/lib/python2.7/bsddb/test/test_thread.pytsetUp&s
 	cCs.|jj�|jj�tj|j�dS(N(RtcloseRRtrmtreeR(R"((s,/sys/lib/python2.7/bsddb/test/test_thread.pyttearDown5s

cCsdS(N((R"((s,/sys/lib/python2.7/bsddb/test/test_thread.pyR:scCstj|gd�S(Ni(tDASHtjoin(R"tkey((s,/sys/lib/python2.7/bsddb/test/test_thread.pytmakeData=s(RRRt
DB_UNKNOWNR R!RRR#R&RR*(((s,/sys/lib/python2.7/bsddb/test/test_thread.pyR s				tConcurrentDataStoreBasecBsUeZejZejejBejBZdZdZ	dZ
d�Zd�Zd�Z
RS(ii�c
	CsTtr%dGddGHd|jjGHnt|j�}ddl}|j|�|j|j}|j|j}|j	|j|j|�|j	|j|j|�|j
||dk�g}x{t|j�D]j}td|j
d|j|fd	d
|�}tjddkr"|jt�n	t|_|j|�q�Wg}x�t|j�D]}}|||||d!}	|	j�|||||d!}
td|jd|j|	|
fd	d
|�}|j|�qRWxD|D]<}tjddkr|jt�n	t|_|j�q�Wx|D]}|j�q!Wx|D]}|j�q<WdS(Ns
s-=is(Running %s.test01_1WriterMultiReaders...i�ittargettargstnames	reader %diis	writer %d(RRRtrangetrecordsRtshuffletwriterstreaderstassertEqualt
assertTruetxrangeRtreaderThreadRRtversion_infot	setDaemontTruetdaemontappendtsorttwriterThreadtstartR((
R"tkeysRtrecords_per_writertreaders_per_writerR4txtrtR3tatbtwttt((s,/sys/lib/python2.7/bsddb/test/test_thread.pyttest01_1WriterMultiReadersKsN


	


	

c	Cs$tjddkr%t�j�}nt�j}trLd|ttfGHnt|�t|�}|}x�|D]�}d|}t	j
|j||j|�dd�tr�|ddkr�d|t|fGHn|d	8}|so|j
�j�|}qoqoWtrd
|GHntr d|GHndS(Niis%s: creating records %d - %ds%04dtmax_retriesiids%s: records %d - %d finishedis%s: finished creating recordss%s: thread finished(RR9R
tgetNameR/RR@tstoptlenRtDeadlockWraptputR*tpop(	R"RRAR4R/tcounttcount2RDR)((s,/sys/lib/python2.7/bsddb/test/test_thread.pyR?}s*



c
Cs�tjddkr%t�j�}nt�j}x�td�D]�}|j�}d}|j�}xE|r�|d7}|\}}	|j|j	|�|	�|j
�}qeWtr�d||fGHn|j�q>Wtr�|GHndS(Niiiis%s: found %d recordss%s: thread finished(
RR9R
RLR/R7tcursortfirstR5R*tnextRR$(
R"Rt	readerNumR/titcRRtrecR)tdata((s,/sys/lib/python2.7/bsddb/test/test_thread.pyR8�s"	
(RRRt	DB_THREADR!tDB_INIT_CDBt
DB_INIT_MPOOLRR4R3R1RJR?R8(((s,/sys/lib/python2.7/bsddb/test/test_thread.pyR,Ds		2	tBTreeConcurrentDataStorecBs#eZejZdZdZdZRS(ii
i�(RRRtDB_BTREER R3R4R1(((s,/sys/lib/python2.7/bsddb/test/test_thread.pyR_�s	tHashConcurrentDataStorecBs#eZejZdZdZdZRS(ii
i�(RRRtDB_HASHR R3R4R1(((s,/sys/lib/python2.7/bsddb/test/test_thread.pyRa�s	tSimpleThreadedBasecBs^eZejZejejBejBZdZdZ	dZ
d�Zd�Zd�Z
d�ZRS(i
ii�cCs|jjtj�dS(N(Rt
set_lk_detectRtDB_LOCK_DEFAULT(R"((s,/sys/lib/python2.7/bsddb/test/test_thread.pyR�sc
	CsTtr%dGddGHd|jjGHnt|j�}ddl}|j|�|j|j}|j|j}|j	|j|j|�|j	|j|j|�|j
||dk�g}x{t|j�D]j}td|j
d|j|fd	d
|�}tjddkr"|jt�n	t|_|j|�q�Wg}x�t|j�D]}}|||||d!}	|	j�|||||d!}
td|jd|j|	|
fd	d
|�}|j|�qRWxD|D]<}tjddkr|jt�n	t|_|j�q�Wx|D]}|j�q!Wx|D]}|j�q<WdS(Ns
s-=is Running %s.test02_SimpleLocks...i�iR-R.R/s	reader %diis	writer %d(RRRR0R1RR2R3R4R5R6R7RR8RRR9R:R;R<R=R>R?R@R((
R"RARRBRCR4RDRER3RFRGRHRI((s,/sys/lib/python2.7/bsddb/test/test_thread.pyttest02_SimpleLocks�sL


	


	

c	Cstjddkr%t�j�}nt�j}trLd|ttfGHnt|�t|�}|}x�|D]�}d|}t	j
|j||j|�dd�tr�|ddkr�d|t|fGHn|d	8}|so|j
�j�|}qoqoWtrd
|GHndS(Niis%s: creating records %d - %ds%04dRKiids%s: records %d - %d finishedis%s: thread finished(RR9R
RLR/RR@RMRNRRORPR*RQ(	R"RRAR4R/RRRSRDR)((s,/sys/lib/python2.7/bsddb/test/test_thread.pyR?�s&



c	Cs�tjddkr%t�j�}nt�j}|j�}d}tj|jdd�}xQ|r�|d7}|\}}|j	|j
|�|�tj|jdd�}q^Wtr�d||fGHn|j
�tr�|GHndS(NiiRKi
is%s: found %d recordss%s: thread finished(RR9R
RLR/RTRRORUR5R*RVRR$(	R"RRWR/RYRRRZR)R[((s,/sys/lib/python2.7/bsddb/test/test_thread.pyR8s 	

(RRRR\R!R^tDB_INIT_LOCKRR4R3R1RRfR?R8(((s,/sys/lib/python2.7/bsddb/test/test_thread.pyRc�s			2	tBTreeSimpleThreadedcBseZejZRS((RRRR`R (((s,/sys/lib/python2.7/bsddb/test/test_thread.pyRh-stHashSimpleThreadedcBseZejZRS((RRRRbR (((s,/sys/lib/python2.7/bsddb/test/test_thread.pyRi1stThreadedTransactionsBasecBs�eZejejBZejejBejBejBej	BZ
dZdZdZ
dZd�Zd�Zd�Zd�Zd�ZRS(ii�cCsdS(N((R"((s,/sys/lib/python2.7/bsddb/test/test_thread.pyREsc	Cs�tr%dGddGHd|jjGHnt|j�}ddl}|j|�|j|j}|j|j}|j	|j|j|�|j	|j|j|�|j
||dk�g}x{t|j�D]j}td|j
d|j|fd	d
|�}tjddkr"|jt�n	t|_|j|�q�Wg}x�t|j�D]s}|||||d!}	|||||d!}
td|jd|j|	|
fd	d
|�}|j|�qRWtd|j�}tjddkr�jt�n	t|_|j�xD|D]<}
tjddkrA|
jt�n	t|
_|
j�qWx|D]}
|
j�q_Wx|D]}
|
j�qzWt|_|j�dS(Ns
s-=is)Running %s.test03_ThreadedTransactions...i�iR-R.R/s	reader %diis	writer %d(RRRR0R1RR2R3R4R5R6R7RR8RRR9R:R;R<R=R?tdeadlockThreadR@R(tFalsetdoLockDetect(R"RARRBRCR4RDRER3RFRGRHtdtRI((s,/sys/lib/python2.7/bsddb/test/test_thread.pyttest03_ThreadedTransactionsIsZ


	
	

	

	cCs�tjddkr%t�j�}nt�j}t|�t|�}x,t|�ruy�|jjd|j	�}|| }x_|D]W}d|}	|j
|	|j|	�|�tr�|ddkr�d|t
|fGHq�q�W|j�||}|j�j
�WqJtjtjfk
rq}
trdtjdkrKd||
d	fGHqdd||
jd	fGHn|j�qJXqJWtr�d
|GHndS(Niis%04dids%s: records %d - %d finishediis%s: Aborting transaction (%s)is%s: thread finished(ii(RR9R
RLR/RNRt	txn_begintNonettxnFlagRPR*RR@tcommitRQRtDBLockDeadlockErrortDBLockNotGrantedErrorR.tabort(R"RRAR4R/RRttxntkeys2RDR)tval((s,/sys/lib/python2.7/bsddb/test/test_thread.pyR?�s2




cCs�tjddkr%t�j�}nt�j}t}x;|sty�|jjd|j	�}|j
|�}d}|j�}xE|r�|d7}|\}	}
|j|j
|	�|
�|j�}qWtr�d||fGHn|j�|j�t}Wq:tjtjfk
rp}trYtjd	kr@d||dfGHqYd||jdfGHn|j�|j�q:Xq:Wtr�d|GHndS(
Niiis%s: found %d recordsiis%s: Aborting transaction (%s)s%s: thread finished(ii(RR9R
RLR/RlRRpRqRrRTRUR5R*RVRR$RsR;RRtRuR.Rv(R"RRWR/tfinishedRwRYRRRZR)R[Ry((s,/sys/lib/python2.7/bsddb/test/test_thread.pyR8�s<		




cCsxt|_xh|jrstjd�y7|jjtjtj�}t	rX|rXd|GHnWqtj
k
roqXqWdS(Ng����s.deadlock: Aborted %d deadlocked transaction(s)(R;RmttimetsleepRtlock_detectRtDB_LOCK_RANDOMtDB_LOCK_CONFLICTRtDBError(R"taborted((s,/sys/lib/python2.7/bsddb/test/test_thread.pyRk�s	
	
(RRRR\tDB_AUTO_COMMITR!R^RgtDB_INIT_LOGtDB_INIT_TXNRR4R3R1RrRRoR?R8Rk(((s,/sys/lib/python2.7/bsddb/test/test_thread.pyRj8s
		;		#tBTreeThreadedTransactionscBs#eZejZdZdZdZRS(ii
i�(RRRR`R R3R4R1(((s,/sys/lib/python2.7/bsddb/test/test_thread.pyR��s	tHashThreadedTransactionscBs#eZejZdZdZdZRS(ii
i�(RRRRbR R3R4R1(((s,/sys/lib/python2.7/bsddb/test/test_thread.pyR��s	tBTreeThreadedNoWaitTransactionscBs,eZejZdZdZdZejZ	RS(ii
i�(
RRRR`R R3R4R1t
DB_TXN_NOWAITRr(((s,/sys/lib/python2.7/bsddb/test/test_thread.pyR��s
	tHashThreadedNoWaitTransactionscBs,eZejZdZdZdZejZ	RS(ii
i�(
RRRRbR R3R4R1R�Rr(((s,/sys/lib/python2.7/bsddb/test/test_thread.pyR��s
	cCs�tj�}tr�|jtjt��|jtjt��|jtjt��|jtjt��|jtjt	��|jtjt
��|jtjt��|jtjt��ndGH|S(Ns-Threads not available, skipping thread tests.(
tunittestt	TestSuiteR	taddTestt	makeSuiteR_RaRhRiR�R�R�R�(tsuite((s,/sys/lib/python2.7/bsddb/test/test_thread.pyt
test_suite�st__main__tdefaultTestR�((t__doc__tosRR{terrnoRR'Rt	NameErrort	ExceptionR�ttest_allRRRRR	R
Rt	threadingRR9R
RtTestCaseRR,R_RaRcRhRiRjR�R�R�R�R�Rtmain(((s,/sys/lib/python2.7/bsddb/test/test_thread.pyt<module>s@
4$m	l�
	

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.