1 package org.jboss.test.testbeancluster.test; 2 3 import java.io.ByteArrayInputStream ; 4 import java.io.ByteArrayOutputStream ; 5 import java.io.ObjectInputStream ; 6 import java.io.ObjectOutputStream ; 7 8 import org.jboss.ha.hasessionstate.server.PackagedSessionImpl; 9 import org.jboss.test.JBossTestCase; 10 11 public class PackagedSessionImplUnitTestCase extends JBossTestCase 12 { 13 14 public PackagedSessionImplUnitTestCase(String name) 15 { 16 super(name); 17 } 18 19 public void testUnmodifiedExistenceInVM() throws Exception 20 { 21 long oldTimestamp = System.currentTimeMillis(); 22 23 sleep(15); 25 byte[] state = new byte[1]; 26 PackagedSessionImpl psi = new PackagedSessionImpl("Test", state, "Test"); 27 28 long newTimestamp = psi.unmodifiedExistenceInVM(); 29 30 assertTrue("Valid initial timestamp", newTimestamp > oldTimestamp); 31 32 33 sleep(15); 35 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 36 ObjectOutputStream oos = new ObjectOutputStream (baos); 37 oos.writeObject(psi); 38 oos.close(); 39 40 ByteArrayInputStream bais = new ByteArrayInputStream (baos.toByteArray()); 41 ObjectInputStream ois = new ObjectInputStream (bais); 42 psi = (PackagedSessionImpl) ois.readObject(); 43 ois.close(); 44 45 oldTimestamp = newTimestamp; 46 newTimestamp = psi.unmodifiedExistenceInVM(); 47 48 assertTrue("Valid timestamp after deserialization", newTimestamp > oldTimestamp); 49 50 sleep(15); 52 psi.setState(state); 54 oldTimestamp = newTimestamp; 55 newTimestamp = psi.unmodifiedExistenceInVM(); 56 57 assertTrue("Valid timestamp after setState()", newTimestamp > oldTimestamp); 58 59 sleep(15); 61 PackagedSessionImpl psi2 = new PackagedSessionImpl("Test", state, "Test"); 62 63 psi.update(psi2); 64 65 oldTimestamp = newTimestamp; 66 newTimestamp = psi.unmodifiedExistenceInVM(); 67 68 assertTrue("Valid timestamp after update()", newTimestamp > oldTimestamp); 69 } 70 71 } 72 | Popular Tags |