1 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 ; 30 import java.util.Collection ; 31 import java.util.HashMap ; 32 import java.util.HashSet ; 33 import java.util.LinkedList ; 34 import java.util.List ; 35 import java.util.Set ; 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 { 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 { 54 List changes = new LinkedList (); 55 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 notified = new LinkedList (); 67 Set lookupObjectIDs = new HashSet (); 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 (), 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 ())); 89 assertEquals(lookupObjectIDs, msg.getLookupObjectIDs()); 90 } 91 92 } 93 | Popular Tags |