1 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 ; 11 import java.io.ObjectOutputStream ; 12 import java.io.PipedInputStream ; 13 import java.io.PipedOutputStream ; 14 15 public class GlobalTransactionIDTest extends TCTestCase { 16 17 public void testSerialization() throws Exception { 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 { 31 PipedInputStream sink = new PipedInputStream (); 32 PipedOutputStream out = new PipedOutputStream (sink); 33 ObjectOutputStream oos = new ObjectOutputStream (out); 34 oos.writeObject(gtx); 35 oos.flush(); 36 oos.close(); 37 out.flush(); 38 out.close(); 39 ObjectInputStream ois = new ObjectInputStream (sink); 40 return (GlobalTransactionDescriptor) ois.readObject(); 41 } 42 43 44 } 45 | Popular Tags |