1 4 package com.tc.object.tx; 5 6 import com.tc.object.lockmanager.api.LockID; 7 8 import java.util.Collection ; 9 import java.util.HashSet ; 10 11 import junit.framework.TestCase; 12 13 public class LockAccountingTest extends TestCase { 14 15 private LockAccounting la; 16 private LockID lockID1; 17 private LockID lockID2; 18 private LockID lockID3; 19 private LockID lockID4; 20 private TransactionID txID1; 21 private TransactionID txID2; 22 private TransactionID txID3; 23 private TransactionID txID4; 24 private Collection lock1Txs; 25 private Collection lock2Txs; 26 private Collection lock3Txs; 27 private Collection lock4Txs; 28 29 public void setUp() { 30 la = new LockAccounting(); 31 } 32 33 public void tests() throws Exception { 34 lockID1 = new LockID("lock1"); 35 lockID2 = new LockID("lock2"); 36 lockID3 = new LockID("lock3"); 37 lockID4 = new LockID("lock4"); 38 txID1 = new TransactionID(1); 39 txID2 = new TransactionID(2); 40 txID3 = new TransactionID(3); 41 txID4 = new TransactionID(4); 42 lock1Txs = new HashSet (); 43 lock2Txs = new HashSet (); 44 lock3Txs = new HashSet (); 45 lock4Txs = new HashSet (); 46 Collection tx1locks = new HashSet (); 47 Collection tx2locks = new HashSet (); 48 Collection tx3locks = new HashSet (); 49 Collection tx4locks = new HashSet (); 50 51 tx1locks.add(lockID1); 52 lock1Txs.add(txID1); 53 tx1locks.add(lockID2); 54 lock2Txs.add(txID1); 55 56 tx2locks.add(lockID1); 57 lock1Txs.add(txID2); 58 tx2locks.add(lockID2); 59 lock2Txs.add(txID2); 60 61 tx3locks.add(lockID3); 62 lock3Txs.add(txID3); 63 64 tx4locks.add(lockID4); 65 lock4Txs.add(txID4); 66 67 la.add(txID1, tx1locks); 68 la.add(txID2, tx2locks); 69 la.add(txID3, tx3locks); 70 la.add(txID4, tx4locks); 71 72 verifyGetTransactionsFor(); 73 74 la.acknowledge(txID1); 75 assertTrue(lock1Txs.remove(txID1)); 76 assertTrue(lock2Txs.remove(txID1)); 77 assertFalse(lock3Txs.remove(txID1)); 78 assertFalse(lock4Txs.remove(txID1)); 79 verifyGetTransactionsFor(); 80 81 la.acknowledge(txID2); 82 assertTrue(lock1Txs.remove(txID2)); 83 assertTrue(lock2Txs.remove(txID2)); 84 assertFalse(lock3Txs.remove(txID2)); 85 assertFalse(lock4Txs.remove(txID2)); 86 verifyGetTransactionsFor(); 87 88 la.acknowledge(txID3); 89 assertFalse(lock1Txs.remove(txID3)); 90 assertFalse(lock2Txs.remove(txID3)); 91 assertTrue(lock3Txs.remove(txID3)); 92 assertFalse(lock4Txs.remove(txID3)); 93 verifyGetTransactionsFor(); 94 95 la.acknowledge(txID4); 96 assertFalse(lock1Txs.remove(txID4)); 97 assertFalse(lock2Txs.remove(txID4)); 98 assertFalse(lock3Txs.remove(txID4)); 99 assertTrue(lock4Txs.remove(txID4)); 100 verifyGetTransactionsFor(); 101 102 assertTrue(lock1Txs.isEmpty()); 103 assertTrue(lock2Txs.isEmpty()); 104 assertTrue(lock3Txs.isEmpty()); 105 assertTrue(lock4Txs.isEmpty()); 106 assertTrue(la.isEmpty()); 107 } 108 109 private void verifyGetTransactionsFor() { 110 assertEquals(lock1Txs, la.getTransactionsFor(lockID1)); 111 assertEquals(lock2Txs, la.getTransactionsFor(lockID2)); 112 assertEquals(lock3Txs, la.getTransactionsFor(lockID3)); 113 assertEquals(lock4Txs, la.getTransactionsFor(lockID4)); 114 } 115 116 } 117 | Popular Tags |