KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > testbeancluster > test > PackagedSessionImplUnitTestCase


1 package org.jboss.test.testbeancluster.test;
2
3 import java.io.ByteArrayInputStream JavaDoc;
4 import java.io.ByteArrayOutputStream JavaDoc;
5 import java.io.ObjectInputStream JavaDoc;
6 import java.io.ObjectOutputStream JavaDoc;
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 JavaDoc name)
15    {
16       super(name);
17    }
18    
19    public void testUnmodifiedExistenceInVM() throws Exception JavaDoc
20    {
21       long oldTimestamp = System.currentTimeMillis();
22       
23       sleep(15); // make sure the system clock changes
24

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); // make sure the system clock changes
34

35       ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
36       ObjectOutputStream JavaDoc oos = new ObjectOutputStream JavaDoc(baos);
37       oos.writeObject(psi);
38       oos.close();
39       
40       ByteArrayInputStream JavaDoc bais = new ByteArrayInputStream JavaDoc(baos.toByteArray());
41       ObjectInputStream JavaDoc ois = new ObjectInputStream JavaDoc(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); // make sure the system clock changes
51

52       psi.setState(state); // use the same state to confirm that the timestamp updates anyway
53

54       oldTimestamp = newTimestamp;
55       newTimestamp = psi.unmodifiedExistenceInVM();
56       
57       assertTrue("Valid timestamp after setState()", newTimestamp > oldTimestamp);
58       
59       sleep(15); // make sure the system clock changes
60

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