KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > object > tx > GlobalTransactionIDTest


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

4 package com.tc.object.tx;
5
6 import com.tc.net.protocol.tcm.ChannelID;
7 import com.tc.objectserver.gtx.GlobalTransactionDescriptor;
8 import com.tc.test.TCTestCase;
9
10 import java.io.ObjectInputStream JavaDoc;
11 import java.io.ObjectOutputStream JavaDoc;
12 import java.io.PipedInputStream JavaDoc;
13 import java.io.PipedOutputStream JavaDoc;
14
15 public class GlobalTransactionIDTest extends TCTestCase {
16   
17   public void testSerialization() throws Exception JavaDoc {
18     long gtxID = 1;
19     ChannelID channel1 = new ChannelID(gtxID);
20     TransactionID tx1 = new TransactionID(gtxID);
21     ServerTransactionID stxID1 = new ServerTransactionID(channel1, tx1);
22     GlobalTransactionDescriptor gtx = new GlobalTransactionDescriptor(stxID1);
23     GlobalTransactionDescriptor gtx2 = serializeAndDeserialize(gtx);
24     
25     assertEquals(channel1, gtx2.getChannelID());
26     assertEquals(tx1, gtx2.getClientTransactionID());
27     assertEquals(gtx, gtx2);
28   }
29
30   private GlobalTransactionDescriptor serializeAndDeserialize(GlobalTransactionDescriptor gtx) throws Exception JavaDoc {
31     PipedInputStream JavaDoc sink = new PipedInputStream JavaDoc();
32     PipedOutputStream JavaDoc out = new PipedOutputStream JavaDoc(sink);
33     ObjectOutputStream JavaDoc oos = new ObjectOutputStream JavaDoc(out);
34     oos.writeObject(gtx);
35     oos.flush();
36     oos.close();
37     out.flush();
38     out.close();
39     ObjectInputStream JavaDoc ois = new ObjectInputStream JavaDoc(sink);
40     return (GlobalTransactionDescriptor) ois.readObject();
41   }
42
43   
44 }
45
Popular Tags