mς €γΈEc@s—dZdkZdefd„ƒYZdefd„ƒYZdefd„ƒYZdeefd „ƒYZd fd „ƒYZd kl Z d „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() NtObjectcBstZd„Zd„ZRS(NcCsdS(N((tself((tE/data/zmath/zope/lib/python/transaction/tests/test_register_compat.pytcommitbscCsdS(N((R((Rtabortes(t__name__t __module__RR(((RR`s t CommitErrorcBstZd„ZRS(NcCstdƒ‚dS(NR(t RuntimeError(R((RRjs(RRR(((RRhst AbortErrorcBstZd„ZRS(NcCstdƒ‚dS(NR(R(R((RRos(RRR(((RR mst BothErrorcBstZRS(N(RR(((RR rstTestConnectioncBsYtZd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Z d „Z RS( NcCsg|_g|_g|_dS(N(Rt committedtabortedtcalls(R((Rt__init__ws  cCs ||_tiƒi|ƒdS(N(Rtobjt_p_jart transactiontgettregister(RR((RR|s cCstt|ƒƒS(N(tstrtidR(R((RtsortKey€scCs|iidƒdS(Ntbegin(RRtappend(Rttxn((Rt tpc_beginƒscCs|iidƒdS(Ntvote(RRR(RR((Rttpc_vote†scCs|iidƒdS(Ntfinish(RRR(RR((Rt tpc_finish‰scCs|iidƒdS(NR(RRR(RR((Rt tpc_abortŒscCs|iƒ|ii|ƒdS(N(RRRR R(RRR((RRs cCs|iƒ|ii|ƒdS(N(RRRR R(RRR((RR“s ( RRRRRRRRR RR(((RR us        (sdoctestcCs tiƒS(N(tdoctestt DocTestSuite(((Rt test_suite™s( t__doc__RtobjectRRR R R t zope.testingR!R#(RRRR R#R!R R ((Rt?\s "