KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > object > msg > BroadcastTransactionMessageTest


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
3  * notice. All rights reserved.
4  */

5 package com.tc.object.msg;
6
7 import com.tc.bytes.TCByteBuffer;
8 import com.tc.io.TCByteBufferOutput;
9 import com.tc.io.TCByteBufferOutputStream;
10 import com.tc.net.protocol.tcm.ChannelID;
11 import com.tc.net.protocol.tcm.MessageChannel;
12 import com.tc.net.protocol.tcm.MessageMonitor;
13 import com.tc.net.protocol.tcm.NullMessageMonitor;
14 import com.tc.net.protocol.tcm.TCMessageHeader;
15 import com.tc.net.protocol.tcm.TCMessageType;
16 import com.tc.net.protocol.tcm.TestMessageChannel;
17 import com.tc.object.ObjectID;
18 import com.tc.object.dmi.DmiDescriptor;
19 import com.tc.object.dna.impl.ObjectStringSerializer;
20 import com.tc.object.gtx.GlobalTransactionID;
21 import com.tc.object.lockmanager.api.LockContext;
22 import com.tc.object.lockmanager.api.LockID;
23 import com.tc.object.lockmanager.api.LockLevel;
24 import com.tc.object.lockmanager.api.ThreadID;
25 import com.tc.object.session.SessionID;
26 import com.tc.object.tx.TransactionID;
27 import com.tc.object.tx.TxnType;
28
29 import java.util.Arrays JavaDoc;
30 import java.util.Collection JavaDoc;
31 import java.util.HashMap JavaDoc;
32 import java.util.HashSet JavaDoc;
33 import java.util.LinkedList JavaDoc;
34 import java.util.List JavaDoc;
35 import java.util.Set JavaDoc;
36
37 import junit.framework.TestCase;
38
39 public class BroadcastTransactionMessageTest extends TestCase {
40
41   private BroadcastTransactionMessageImpl msg;
42   private TCByteBufferOutput out;
43   private MessageMonitor monitor;
44   private MessageChannel channel;
45
46   public void setUp() throws Exception JavaDoc {
47     monitor = new NullMessageMonitor();
48     channel = new TestMessageChannel();
49     out = new TCByteBufferOutputStream(4, 4096, false);
50     msg = new BroadcastTransactionMessageImpl(monitor, out, channel, TCMessageType.BROADCAST_TRANSACTION_MESSAGE);
51   }
52
53   public void testBasics() throws Exception JavaDoc {
54     List JavaDoc changes = new LinkedList JavaDoc();
55     // / XXX: TODO: Add changes to test.
56

57     ObjectStringSerializer serializer = new ObjectStringSerializer();
58     LockID[] lockIDs = new LockID[] { new LockID("1") };
59     long cid = 10;
60     TransactionID txID = new TransactionID(1);
61     ChannelID channelID = new ChannelID(1);
62     GlobalTransactionID gtx = new GlobalTransactionID(2);
63     TxnType txnType = TxnType.NORMAL;
64     GlobalTransactionID lowGlobalTransactionIDWatermark = new GlobalTransactionID(1);
65
66     Collection JavaDoc notified = new LinkedList JavaDoc();
67     Set JavaDoc lookupObjectIDs = new HashSet JavaDoc();
68     for (int i = 0; i < 100; i++) {
69       notified.add(new LockContext(new LockID("" + (i + 1)), channelID, new ThreadID(i + 1), LockLevel.WRITE));
70       lookupObjectIDs.add(new ObjectID(i));
71     }
72     msg.initialize(changes, lookupObjectIDs, serializer, lockIDs, cid, txID, channelID, gtx, txnType,
73                    lowGlobalTransactionIDWatermark, notified, new HashMap JavaDoc(), DmiDescriptor.EMPTY_ARRAY);
74     msg.dehydrate();
75
76     TCByteBuffer[] data = out.toArray();
77     TCMessageHeader header = (TCMessageHeader) msg.getHeader();
78     msg = new BroadcastTransactionMessageImpl(SessionID.NULL_ID, monitor, channel, header, data);
79     msg.hydrate();
80
81     assertEquals(changes, msg.getObjectChanges());
82     assertEquals(Arrays.asList(lockIDs), Arrays.asList(msg.getLockIDs()));
83     assertEquals(cid, msg.getChangeID());
84     assertEquals(txID, msg.getTransactionID());
85     assertEquals(gtx, msg.getGlobalTransactionID());
86     assertEquals(txnType, msg.getTransactionType());
87     assertEquals(lowGlobalTransactionIDWatermark, msg.getLowGlobalTransactionIDWatermark());
88     assertEquals(notified, msg.addNotifiesTo(new LinkedList JavaDoc()));
89     assertEquals(lookupObjectIDs, msg.getLookupObjectIDs());
90   }
91
92 }
93
Popular Tags