1 4 package com.tc.object.gtx; 5 6 import com.tc.net.protocol.tcm.ChannelID; 7 import com.tc.object.tx.TestRemoteTransactionManager; 8 import com.tc.object.tx.TransactionID; 9 10 import junit.framework.TestCase; 11 12 public class ClientGlobalTransactionManagerTest extends TestCase { 13 14 private ClientGlobalTransactionManagerImpl mgr; 15 16 public void setUp() { 17 mgr = new ClientGlobalTransactionManagerImpl(new TestRemoteTransactionManager()); 18 } 19 20 public void testBasics() throws Exception { 21 int max = 5; 22 for (int i = 100; i <= max; i++) { 23 GlobalTransactionID gtx1 = new GlobalTransactionID(i); 24 ChannelID channelID = new ChannelID(i); 25 TransactionID transactionID = new TransactionID(i); 26 assertTrue(mgr.startApply(channelID, transactionID, gtx1)); 28 assertFalse(mgr.startApply(channelID, transactionID, gtx1)); 30 31 if (i > 2) { 32 GlobalTransactionID lowWatermark = new GlobalTransactionID(i - 1); 33 ChannelID chIDBelowWatermark = new ChannelID(i - 2); 34 TransactionID txIDBelowWatermark = new TransactionID(i - 2); 35 GlobalTransactionID belowLowWatermark = new GlobalTransactionID(i - mgr.getAllowedLowWaterMarkDelta()); 36 mgr.setLowWatermark(lowWatermark); 37 38 try { 39 mgr.startApply(chIDBelowWatermark, txIDBelowWatermark, belowLowWatermark); 40 fail("Should have thrown an UnknownTransactionError"); 41 } catch (UnknownTransactionError e) { 42 } 44 } 45 } 46 } 47 48 public void testCleanup() throws Exception { 49 ChannelID channelID = new ChannelID(1); 50 TransactionID txID = new TransactionID(1); 51 GlobalTransactionID gtxID1 = new GlobalTransactionID(1); 52 GlobalTransactionID gtxID2 = new GlobalTransactionID(2); 53 GlobalTransactionID gtxID3 = new GlobalTransactionID(3 + mgr.getAllowedLowWaterMarkDelta()); 54 55 assertEquals(0, mgr.size()); 56 assertTrue(mgr.startApply(channelID, txID, gtxID1)); 57 assertEquals(1, mgr.size()); 58 59 assertFalse(mgr.startApply(channelID, txID, gtxID1)); 62 assertFalse(mgr.startApply(channelID, txID, gtxID2)); 63 assertEquals(1, mgr.size()); 64 65 mgr.setLowWatermark(gtxID1); 67 assertFalse(mgr.startApply(channelID, txID, gtxID2)); 68 assertEquals(1, mgr.size()); 69 70 mgr.setLowWatermark(gtxID3); 76 assertEquals(0, mgr.size()); 77 78 assertTrue(mgr.startApply(channelID, txID, gtxID3)); 83 } 84 } 85 | Popular Tags |