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.object.msg;
06:
07: import com.tc.io.TCByteBufferInputStream;
08: import com.tc.io.TCByteBufferOutputStream;
09: import com.tc.net.protocol.tcm.NullMessageMonitor;
10: import com.tc.net.protocol.tcm.TCMessageHeader;
11: import com.tc.net.protocol.tcm.TCMessageType;
12: import com.tc.object.dna.impl.ObjectStringSerializer;
13: import com.tc.object.session.SessionID;
14: import com.tc.object.tx.TransactionBatch;
15: import com.tc.test.TCTestCase;
16:
17: import java.util.Arrays;
18: import java.util.Random;
19:
20: /**
21: * @author steve
22: */
23: public class CommitTransactionMessageTest extends TCTestCase {
24:
25: public void testMessage() throws Exception {
26: Random rnd = new Random();
27:
28: for (int i = 0; i < 100; i++) {
29: int len = rnd.nextInt(40960);
30:
31: byte orig[] = new byte[len];
32: rnd.nextBytes(orig);
33:
34: TCByteBufferOutputStream bbos = new TCByteBufferOutputStream();
35: bbos.write(orig);
36:
37: TransactionBatch batch = new TestTransactionBatch(bbos
38: .toArray());
39:
40: CommitTransactionMessageImpl msg = new CommitTransactionMessageImpl(
41: new SessionID(0), new NullMessageMonitor(),
42: new TCByteBufferOutputStream(4, 4096, false), null,
43: TCMessageType.COMMIT_TRANSACTION_MESSAGE);
44: ObjectStringSerializer serializer = new ObjectStringSerializer();
45: msg.setBatch(batch, serializer);
46: msg.dehydrate();
47:
48: CommitTransactionMessageImpl msg2 = new CommitTransactionMessageImpl(
49: SessionID.NULL_ID, new NullMessageMonitor(), null,
50: (TCMessageHeader) msg.getHeader(), msg.getPayload());
51: msg2.hydrate();
52:
53: TCByteBufferInputStream bbis = new TCByteBufferInputStream(
54: msg2.getBatchData());
55: byte[] compare = new byte[orig.length];
56: int read = bbis.read(compare);
57: assertEquals(compare.length, read);
58: assertTrue(Arrays.equals(orig, compare));
59: }
60:
61: }
62:
63: }
|