001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package com.tc.object.msg;
006:
007: import com.tc.bytes.TCByteBuffer;
008: import com.tc.io.TCByteBufferOutput;
009: import com.tc.io.TCByteBufferOutputStream;
010: import com.tc.net.groups.ClientID;
011: import com.tc.net.protocol.tcm.ChannelID;
012: import com.tc.net.protocol.tcm.MessageChannel;
013: import com.tc.net.protocol.tcm.MessageMonitor;
014: import com.tc.net.protocol.tcm.NullMessageMonitor;
015: import com.tc.net.protocol.tcm.TCMessageHeader;
016: import com.tc.net.protocol.tcm.TCMessageType;
017: import com.tc.net.protocol.tcm.TestMessageChannel;
018: import com.tc.object.ObjectID;
019: import com.tc.object.dmi.DmiDescriptor;
020: import com.tc.object.dna.impl.ObjectStringSerializer;
021: import com.tc.object.gtx.GlobalTransactionID;
022: import com.tc.object.lockmanager.api.LockContext;
023: import com.tc.object.lockmanager.api.LockID;
024: import com.tc.object.lockmanager.api.LockLevel;
025: import com.tc.object.lockmanager.api.ThreadID;
026: import com.tc.object.session.SessionID;
027: import com.tc.object.tx.TransactionID;
028: import com.tc.object.tx.TxnType;
029:
030: import java.util.Arrays;
031: import java.util.Collection;
032: import java.util.HashMap;
033: import java.util.HashSet;
034: import java.util.LinkedList;
035: import java.util.List;
036: import java.util.Set;
037:
038: import junit.framework.TestCase;
039:
040: public class BroadcastTransactionMessageTest extends TestCase {
041:
042: private BroadcastTransactionMessageImpl msg;
043: private TCByteBufferOutput out;
044: private MessageMonitor monitor;
045: private MessageChannel channel;
046:
047: public void setUp() throws Exception {
048: monitor = new NullMessageMonitor();
049: channel = new TestMessageChannel();
050: out = new TCByteBufferOutputStream(4, 4096, false);
051: msg = new BroadcastTransactionMessageImpl(new SessionID(0),
052: monitor, out, channel,
053: TCMessageType.BROADCAST_TRANSACTION_MESSAGE);
054: }
055:
056: public void testBasics() throws Exception {
057: List changes = new LinkedList();
058: // / XXX: TODO: Add changes to test.
059:
060: ObjectStringSerializer serializer = new ObjectStringSerializer();
061: LockID[] lockIDs = new LockID[] { new LockID("1") };
062: long cid = 10;
063: TransactionID txID = new TransactionID(1);
064: ClientID clientID = new ClientID(new ChannelID(1));
065: GlobalTransactionID gtx = new GlobalTransactionID(2);
066: TxnType txnType = TxnType.NORMAL;
067: GlobalTransactionID lowGlobalTransactionIDWatermark = new GlobalTransactionID(
068: 1);
069:
070: Collection notified = new LinkedList();
071: Set lookupObjectIDs = new HashSet();
072: for (int i = 0; i < 100; i++) {
073: notified.add(new LockContext(new LockID("" + (i + 1)),
074: clientID, new ThreadID(i + 1), LockLevel.WRITE));
075: lookupObjectIDs.add(new ObjectID(i));
076: }
077: msg.initialize(changes, lookupObjectIDs, serializer, lockIDs,
078: cid, txID, clientID, gtx, txnType,
079: lowGlobalTransactionIDWatermark, notified,
080: new HashMap(), DmiDescriptor.EMPTY_ARRAY);
081: msg.dehydrate();
082:
083: TCByteBuffer[] data = out.toArray();
084: TCMessageHeader header = (TCMessageHeader) msg.getHeader();
085: msg = new BroadcastTransactionMessageImpl(SessionID.NULL_ID,
086: monitor, channel, header, data);
087: msg.hydrate();
088:
089: assertEquals(changes, msg.getObjectChanges());
090: assertEquals(Arrays.asList(lockIDs), msg.getLockIDs());
091: assertEquals(cid, msg.getChangeID());
092: assertEquals(txID, msg.getTransactionID());
093: assertEquals(gtx, msg.getGlobalTransactionID());
094: assertEquals(txnType, msg.getTransactionType());
095: assertEquals(lowGlobalTransactionIDWatermark, msg
096: .getLowGlobalTransactionIDWatermark());
097: assertEquals(notified, msg.addNotifiesTo(new LinkedList()));
098: assertEquals(lookupObjectIDs, msg.getLookupObjectIDs());
099: }
100:
101: }
|