Ńņ 4äKc @ s` d Z d e f d YZ d e f d YZ d Z e Z e d j o e i n d S( sj Sample objects for use in tests $Id: test_SampleResourceManager.py 112140 2010-05-07 15:29:36Z tseaver $ t ResourceManagerc B sk e Z d Z d Z d Z d Z d d Z d Z d Z d Z d Z d Z d Z RS( sX Sample resource manager. This class provides a trivial resource-manager implementation and doc strings to illustrate the protocol and to provide a tool for writing tests. Our sample resource manager has state that is updated through an inc method and through transaction operations. When we create a sample resource manager: >>> rm = ResourceManager() It has two pieces state, state and delta, both initialized to 0: >>> rm.state 0 >>> rm.delta 0 state is meant to model committed state, while delta represents tentative changes within a transaction. We change the state by calling inc: >>> rm.inc() which updates delta: >>> rm.delta 1 but state isn't changed until we commit the transaction: >>> rm.state 0 To commit the changes, we use 2-phase commit. We execute the first stage by calling prepare. We need to pass a transation. Our sample resource managers don't really use the transactions for much, so we'll be lazy and use strings for transactions. The sample resource manager updates the state when we call tpc_vote: >>> t1 = '1' >>> rm.tpc_begin(t1) >>> rm.state, rm.delta (0, 1) >>> rm.tpc_vote(t1) >>> rm.state, rm.delta (1, 1) Now if we call tpc_finish: >>> rm.tpc_finish(t1) Our changes are "permanent". The state reflects the changes and the delta has been reset to 0. >>> rm.state, rm.delta (1, 0) c C s1 d | _ d | _ d | _ d | _ d | _ d S( Ni ( t statet spt Nonet transactiont deltat txn_state( t self( ( sP /usr/lib/python2.6/site-packages/transaction/tests/test_SampleResourceManager.pyt __init__S s c G s1 | i | j o t d | i | f n d S( Ns&