��Qc@s�dZddlZddlZddlmZmZmZmZmZm Z er�ddl
mZddlZej
ddkr�ddl
mZq�ddl
mZnd ejfd
��YZd�Zedkr�jd
d�ndS(s/
TestCases for testing the locking sub-system.
i�N(tdbttest_supporttverbosethave_threadstget_new_environment_pathtget_new_database_path(tThreadii(t
currentThread(tcurrent_threadtLockingTestCasecBs>eZd�Zd�Zd�Zd�Zd�Zd�ZRS(cCsMt�|_tj�|_|jj|jtjtjBtjBtj B�dS(N(
RthomeDirRtDBEnvtenvtopent DB_THREADt
DB_INIT_MPOOLtDB_INIT_LOCKt DB_CREATE(tself((s*/sys/lib/python2.7/bsddb/test/test_lock.pytsetUpscCs!|jj�tj|j�dS(N(RtcloseRtrmtreeR
(R((s*/sys/lib/python2.7/bsddb/test/test_lock.pyttearDowns
cCs�tr%dGddGHd|jjGHn|jj�}trFd|GHn|jj|dtj�}trsd|GHn|jj|�tr�d|GHn|jj |�dS( Ns
s-=isRunning %s.test01_simple...s
locker ID: %sssome locked thingsAquired lock: %ssReleased lock: %s(
Rt __class__t__name__Rtlock_idtlock_getRt
DB_LOCK_WRITEtlock_puttlock_id_free(RtanIDtlock((s*/sys/lib/python2.7/bsddb/test/test_lock.pyt
test01_simple"s
cCs�tr%dGddGHd|jjGHng}|jtd|jdtjf��|jtd|jdtjf��|jtd|jdtjf��|jtd|jdtjf��|jtd|jdtjf��|jtd|jdtjf��|jtd|jdtjf��|jtd|jdtjf��|jtd|jdtjf��xP|D]H}ddl }|j
dd kr�|jt�n t|_
|j�qWx|D]}|j�q�Wd
�}dS(Ns
s-=isRunning %s.test02_threaded...ttargettargsi�iicSs�|jjdtj�|j|jjtj�d�|jjdtj�|j|jjtj�d�|jjdtj�|j|jjtj�d�|jjdtj�|j|jjtj�d�dS(Nii@�i�x(Rtset_timeoutRtDB_SET_LOCK_TIMEOUTtassertEqualtget_timeouttDB_SET_TXN_TIMEOUT(R((s*/sys/lib/python2.7/bsddb/test/test_lock.pyttest03_lock_timeoutVs(RRRtappendRt theThreadRRtDB_LOCK_READtsystversion_infot setDaemontTruetdaemontstarttjoin(RtthreadsttR,R(((s*/sys/lib/python2.7/bsddb/test/test_lock.pyttest02_threaded3s>
cs��jjdtj��jjdtj��jjdtj��jjdtj���fd��t�_d�_td��}ddl }|j
ddkr�|jt�n t|_
|j��jjdtj��jj�}�jj�}�j||��jj|d tj�}tj�}�jtj�jj|d tj�tj�}t�_�j||d
k��jj|�|j��jj|��jj|�tj�d
kr�j�jdk�ndS(Nii@�i�xcsVxO�jsQ�jjtj��_�jrAx
�js<q0WPntjd�qWdS(Ngz��?(tendRtlock_detectRtDB_LOCK_EXPIREtcountttimetsleep((tdeadlock_detectionR(s*/sys/lib/python2.7/bsddb/test/test_lock.pyR<fs R!i�ii�sshared lockg���?ii(ii(RR#RR$R'tFalseR6R9RR,R-R.R/R0R1RtassertNotEqualRRR:tassertRaisestDBLockNotGrantedErrorR+t
assertTrueRR2Rtversion(RR4R,RtanID2Rt
start_timetend_time((R<Rs*/sys/lib/python2.7/bsddb/test/test_lock.pyttest04_lock_timeout2`s<
cCsddl}|jddkr1t�j�}nt�j}|tjkrUd}nd}|jj�}t r�d||fGHnxrt
d�D]d}|jj|d|�}t r�d |||fGHn|jj|�t r�d
|||fGHq�q�W|jj
|�dS(Ni�iitwritetreads%s: locker ID: %si�ssome locked things%s: Aquired %s lock: %ss%s: Released %s lock: %s(R,R-RtgetNametnameRRRRRtxrangeRRR(RtlockTypeR,RJtltRtiR((s*/sys/lib/python2.7/bsddb/test/test_lock.pyR*�s$ (Rt
__module__RRR R5RFR*(((s*/sys/lib/python2.7/bsddb/test/test_lock.pyR s - .cCsHtj�}tr+|jtjt��n|jtjtd��|S(Nttest01(tunittestt TestSuiteRtaddTestt makeSuiteR (tsuite((s*/sys/lib/python2.7/bsddb/test/test_lock.pyt
test_suite�s
t__main__tdefaultTestRV(t__doc__R:RQttest_allRRRRRRt threadingRR,R-RRtTestCaseR RVRtmain(((s*/sys/lib/python2.7/bsddb/test/test_lock.pyt<module>s.�
|