Ñò
4äKc @ sŸ d Z d d k Z d e f d „ ƒ YZ d e f d „ ƒ YZ d e f d „ ƒ YZ d e e f d
„ ƒ YZ d d d „ ƒ YZ d d k Z d
„ Z e Z
d S( sh Test 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ÿÿÿÿNt Objectc B s e Z d „ Z d „ Z RS( c C s d S( N( ( t self( ( sJ /usr/lib/python2.6/site-packages/transaction/tests/test_register_compat.pyt commitb s c C s d S( N( ( R ( ( sJ /usr/lib/python2.6/site-packages/transaction/tests/test_register_compat.pyt aborte s ( t __name__t
__module__R R ( ( ( sJ /usr/lib/python2.6/site-packages/transaction/tests/test_register_compat.pyR ` s t CommitErrorc B s e Z d „ Z RS( c C s t d ƒ ‚ d S( NR ( t RuntimeError( R ( ( sJ /usr/lib/python2.6/site-packages/transaction/tests/test_register_compat.pyR j s ( R R R ( ( ( sJ /usr/lib/python2.6/site-packages/transaction/tests/test_register_compat.pyR h s t
AbortErrorc B s e Z d „ Z RS( c C s t d ƒ ‚ d S( NR ( R ( R ( ( sJ /usr/lib/python2.6/site-packages/transaction/tests/test_register_compat.pyR o s ( R R R ( ( ( sJ /usr/lib/python2.6/site-packages/transaction/tests/test_register_compat.pyR m s t BothErrorc B s e Z RS( ( R R ( ( ( sJ /usr/lib/python2.6/site-packages/transaction/tests/test_register_compat.pyR r s t TestConnectionc B sY e Z d „ Z d „ Z d „ Z d „ Z d „ Z d „ Z d „ Z d „ Z d „ Z
RS( c C s g | _ g | _ g | _ d S( N( t committedt abortedt calls( R ( ( sJ /usr/lib/python2.6/site-packages/transaction/tests/test_register_compat.pyt __init__w s c C s | | _ t i ƒ i | ƒ d S( N( t _p_jart transactiont gett register( R t obj( ( sJ /usr/lib/python2.6/site-packages/transaction/tests/test_register_compat.pyR | s c C s t t | ƒ ƒ S( N( t strt id( R ( ( sJ /usr/lib/python2.6/site-packages/transaction/tests/test_register_compat.pyt sortKey€ s c C s | i i d ƒ d S( Nt begin( R
t append( R t txn( ( sJ /usr/lib/python2.6/site-packages/transaction/tests/test_register_compat.pyt tpc_beginƒ s c C s | i i d ƒ d S( Nt vote( R
R ( R R ( ( sJ /usr/lib/python2.6/site-packages/transaction/tests/test_register_compat.pyt tpc_vote† s c C s | i i d ƒ d S( Nt finish( R
R ( R R ( ( sJ /usr/lib/python2.6/site-packages/transaction/tests/test_register_compat.pyt
tpc_finish‰ s c C s | i i d ƒ d S( NR ( R
R ( R R ( ( sJ /usr/lib/python2.6/site-packages/transaction/tests/test_register_compat.pyt tpc_abortŒ s c C s | i ƒ | i i | ƒ d S( N( R R R ( R R R ( ( sJ /usr/lib/python2.6/site-packages/transaction/tests/test_register_compat.pyR s
c C s | i ƒ | i i | ƒ d S( N( R R R ( R R R ( ( sJ /usr/lib/python2.6/site-packages/transaction/tests/test_register_compat.pyR “ s
( R R R R R R R R R R R ( ( ( sJ /usr/lib/python2.6/site-packages/transaction/tests/test_register_compat.pyR
u s c C s
t i ƒ S( N( t doctestt DocTestSuite( ( ( sJ /usr/lib/python2.6/site-packages/transaction/tests/test_register_compat.pyt
test_suite™ s ( ( t __doc__R t objectR R R R R
R R" t additional_tests( ( ( sJ /usr/lib/python2.6/site-packages/transaction/tests/test_register_compat.pyt