Ñò 4äKc@sŸdZddkZdefd„ƒYZdefd„ƒYZdefd„ƒYZd eefd „ƒYZd dd „ƒYZddkZd „Z e Z dS(shTest backwards compatibility for resource managers using register(). The transaction package supports several different APIs for resource managers. The original ZODB3 API was implemented by ZODB.Connection. The Connection passed persistent objects to a Transaction's register() method. It's possible that third-party code also used this API, hence these tests that the code that adapts the old interface to the current API works. These tests use a TestConnection object that implements the old API. They check that the right methods are called and in roughly the right order. Common cases ------------ First, check that a basic transaction commit works. >>> cn = TestConnection() >>> cn.register(Object()) >>> cn.register(Object()) >>> cn.register(Object()) >>> transaction.commit() >>> len(cn.committed) 3 >>> len(cn.aborted) 0 >>> cn.calls ['begin', 'vote', 'finish'] Second, check that a basic transaction abort works. If the application calls abort(), then the transaction never gets into the two-phase commit. It just aborts each object. >>> cn = TestConnection() >>> cn.register(Object()) >>> cn.register(Object()) >>> cn.register(Object()) >>> transaction.abort() >>> len(cn.committed) 0 >>> len(cn.aborted) 3 >>> cn.calls [] Error handling -------------- The tricky part of the implementation is recovering from an error that occurs during the two-phase commit. We override the commit() and abort() methods of Object to cause errors during commit. Note that the implementation uses lists internally, so that objects are committed in the order they are registered. (In the presence of multiple resource managers, objects from a single resource manager are committed in order. I'm not sure if this is an accident of the implementation or a feature that should be supported by any implementation.) The order of resource managers depends on sortKey(). >>> cn = TestConnection() >>> cn.register(Object()) >>> cn.register(CommitError()) >>> cn.register(Object()) >>> transaction.commit() Traceback (most recent call last): ... RuntimeError: commit >>> len(cn.committed) 1 >>> len(cn.aborted) 3 Clean up: >>> transaction.abort() iÿÿÿÿNtObjectcBseZd„Zd„ZRS(cCsdS(N((tself((sJ/usr/lib/python2.6/site-packages/transaction/tests/test_register_compat.pytcommitbscCsdS(N((R((sJ/usr/lib/python2.6/site-packages/transaction/tests/test_register_compat.pytabortes(t__name__t __module__RR(((sJ/usr/lib/python2.6/site-packages/transaction/tests/test_register_compat.pyR`s t CommitErrorcBseZd„ZRS(cCstdƒ‚dS(NR(t RuntimeError(R((sJ/usr/lib/python2.6/site-packages/transaction/tests/test_register_compat.pyRjs(RRR(((sJ/usr/lib/python2.6/site-packages/transaction/tests/test_register_compat.pyRhst AbortErrorcBseZd„ZRS(cCstdƒ‚dS(NR(R(R((sJ/usr/lib/python2.6/site-packages/transaction/tests/test_register_compat.pyRos(RRR(((sJ/usr/lib/python2.6/site-packages/transaction/tests/test_register_compat.pyRmst BothErrorcBseZRS((RR(((sJ/usr/lib/python2.6/site-packages/transaction/tests/test_register_compat.pyR rstTestConnectioncBsYeZd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z RS( cCsg|_g|_g|_dS(N(t committedtabortedtcalls(R((sJ/usr/lib/python2.6/site-packages/transaction/tests/test_register_compat.pyt__init__ws  cCs ||_tiƒi|ƒdS(N(t_p_jart transactiontgettregister(Rtobj((sJ/usr/lib/python2.6/site-packages/transaction/tests/test_register_compat.pyR|s cCstt|ƒƒS(N(tstrtid(R((sJ/usr/lib/python2.6/site-packages/transaction/tests/test_register_compat.pytsortKey€scCs|iidƒdS(Ntbegin(R tappend(Rttxn((sJ/usr/lib/python2.6/site-packages/transaction/tests/test_register_compat.pyt tpc_beginƒscCs|iidƒdS(Ntvote(R R(RR((sJ/usr/lib/python2.6/site-packages/transaction/tests/test_register_compat.pyttpc_vote†scCs|iidƒdS(Ntfinish(R R(RR((sJ/usr/lib/python2.6/site-packages/transaction/tests/test_register_compat.pyt tpc_finish‰scCs|iidƒdS(NR(R R(RR((sJ/usr/lib/python2.6/site-packages/transaction/tests/test_register_compat.pyt tpc_abortŒscCs|iƒ|ii|ƒdS(N(RR R(RRR((sJ/usr/lib/python2.6/site-packages/transaction/tests/test_register_compat.pyRs cCs|iƒ|ii|ƒdS(N(RR R(RRR((sJ/usr/lib/python2.6/site-packages/transaction/tests/test_register_compat.pyR“s ( RRRRRRRRRRR(((sJ/usr/lib/python2.6/site-packages/transaction/tests/test_register_compat.pyR us        cCs tiƒS(N(tdoctestt DocTestSuite(((sJ/usr/lib/python2.6/site-packages/transaction/tests/test_register_compat.pyt test_suite™s(( t__doc__RtobjectRRRR R R R"tadditional_tests(((sJ/usr/lib/python2.6/site-packages/transaction/tests/test_register_compat.pyt\s "