01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.objectserver.tx;
06:
07: import com.tc.net.groups.ClientID;
08: import com.tc.net.protocol.tcm.ChannelID;
09: import com.tc.object.gtx.GlobalTransactionID;
10: import com.tc.object.tx.ServerTransactionID;
11: import com.tc.object.tx.TransactionID;
12: import com.tc.objectserver.gtx.GlobalTransactionDescriptor;
13: import com.tc.test.TCTestCase;
14:
15: import java.util.Iterator;
16: import java.util.TreeMap;
17:
18: public class GlobalTransactionDescriptorTest extends TCTestCase {
19:
20: public void tests() throws Exception {
21: ClientID cid = new ClientID(new ChannelID(1));
22: TransactionID tx1 = new TransactionID(1);
23: ServerTransactionID stx1 = new ServerTransactionID(cid, tx1);
24:
25: GlobalTransactionDescriptor d1 = new GlobalTransactionDescriptor(
26: stx1, new GlobalTransactionID(1));
27: GlobalTransactionDescriptor d2 = new GlobalTransactionDescriptor(
28: new ServerTransactionID(cid, tx1),
29: new GlobalTransactionID(1));
30: GlobalTransactionDescriptor x1 = new GlobalTransactionDescriptor(
31: new ServerTransactionID(new ClientID(new ChannelID(4)),
32: tx1), new GlobalTransactionID(1));
33: GlobalTransactionDescriptor x2 = new GlobalTransactionDescriptor(
34: new ServerTransactionID(cid, tx1),
35: new GlobalTransactionID(2));
36:
37: assertEquals(d1, d2);
38: assertEquals(d1.hashCode(), d2.hashCode());
39: assertFalse(d1.equals(new Object()));
40: assertFalse(d1.equals(null));
41: assertFalse(d1.equals(x1));
42: assertFalse(d1.equals(x2));
43: }
44:
45: public void testGIDIsSorted() throws Exception {
46: TreeMap tm = new TreeMap();
47: tm.put(new GlobalTransactionID(9), new Object());
48: tm.put(new GlobalTransactionID(19), new Object());
49: tm.put(new GlobalTransactionID(1), new Object());
50: tm.put(new GlobalTransactionID(Long.MAX_VALUE), new Object());
51: tm.put(new GlobalTransactionID(Long.MIN_VALUE), new Object());
52: tm.put(new GlobalTransactionID(-256), new Object());
53: tm.put(new GlobalTransactionID(1), new Object());
54: tm.put(new GlobalTransactionID(70003), new Object());
55:
56: long min = Long.MIN_VALUE;
57: for (Iterator i = tm.keySet().iterator(); i.hasNext();) {
58: GlobalTransactionID gid = (GlobalTransactionID) i.next();
59: assertTrue(min <= gid.toLong());
60: min = gid.toLong();
61: }
62: }
63: }
|