1 4 package com.tc.object.tx; 5 6 import EDU.oswego.cs.dl.util.concurrent.SynchronizedRef; 7 8 import com.tc.management.beans.tx.MockClientTxMonitor; 9 import com.tc.net.protocol.tcm.TestChannelIDProvider; 10 import com.tc.object.MockTCObject; 11 import com.tc.object.ObjectID; 12 import com.tc.object.TestClientObjectManager; 13 import com.tc.object.lockmanager.api.LockLevel; 14 import com.tc.object.lockmanager.api.TestLockManager; 15 import com.tc.object.lockmanager.impl.ThreadLockManagerImpl; 16 import com.tc.object.logging.NullRuntimeLogger; 17 18 import junit.framework.TestCase; 19 20 public class ClientTransactionManagerTest extends TestCase { 21 ClientTransactionFactory clientTxnFactory; 22 TestRemoteTransactionManager rmtTxnMgr; 23 TestClientObjectManager objMgr; 24 TestLockManager lockMgr; 25 ClientTransactionManagerImpl clientTxnMgr; 26 MyObject pojo; 27 SynchronizedRef error = new SynchronizedRef(null); 28 29 public void setUp() throws Exception { 30 clientTxnFactory = new ClientTransactionFactoryImpl(new NullRuntimeLogger(), new TestChannelIDProvider()); 31 rmtTxnMgr = new TestRemoteTransactionManager(); 32 objMgr = new TestClientObjectManager(); 33 lockMgr = new TestLockManager(); 34 clientTxnMgr = new ClientTransactionManagerImpl(new TestChannelIDProvider(), objMgr, 35 new ThreadLockManagerImpl(lockMgr), clientTxnFactory, rmtTxnMgr, 36 new NullRuntimeLogger(), new MockClientTxMonitor()); 37 38 pojo = new MyObject(); 39 } 40 41 public void tearDown() throws Exception { 42 if (error.get() != null) { throw new RuntimeException ((Throwable ) error.get()); } 43 } 44 45 public void testCheckWriteAccess() { 46 try { 48 clientTxnMgr.checkWriteAccess(new Object ()); 49 fail(); 50 } catch (UnlockedSharedObjectException usoe) { 51 } 53 54 clientTxnMgr.begin("lock", LockLevel.READ); 56 try { 57 clientTxnMgr.checkWriteAccess(new Object ()); 58 fail(); 59 } catch (ReadOnlyException roe) { 60 } 62 clientTxnMgr.commit("lock"); 63 64 clientTxnMgr.begin("lock", LockLevel.WRITE); 65 clientTxnMgr.checkWriteAccess(new Object ()); 66 clientTxnMgr.commit("lock"); 67 68 clientTxnMgr.begin("lock", LockLevel.SYNCHRONOUS_WRITE); 69 clientTxnMgr.checkWriteAccess(new Object ()); 70 clientTxnMgr.commit("lock"); 71 72 clientTxnMgr.begin("lock", LockLevel.CONCURRENT); 73 clientTxnMgr.checkWriteAccess(new Object ()); 74 clientTxnMgr.commit("lock"); 75 } 76 77 public void testDoIllegalReadChange() { 78 clientTxnMgr.begin("lock", LockLevel.READ); 79 80 try { 81 clientTxnMgr.fieldChanged(new MockTCObject(new ObjectID(1), new Object ()), null, null, null, -1); 82 assertFalse(true); 83 } catch (ReadOnlyException e) { 84 86 } 90 91 clientTxnMgr.commit("lock"); 92 } 93 94 private static class MyObject { 95 public int count = 0; 96 } 97 } 98 | Popular Tags |