long oldTimestamp = System.currentTimeMillis();
sleep(15); // make sure the system clock changes
byte[] state = new byte[1];
PackagedSessionImpl psi = new PackagedSessionImpl("Test", state, "Test");
long newTimestamp = psi.unmodifiedExistenceInVM();
assertTrue("Valid initial timestamp", newTimestamp > oldTimestamp);
sleep(15); // make sure the system clock changes
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(psi);
oos.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bais);
psi = (PackagedSessionImpl) ois.readObject();
ois.close();
oldTimestamp = newTimestamp;
newTimestamp = psi.unmodifiedExistenceInVM();
assertTrue("Valid timestamp after deserialization", newTimestamp > oldTimestamp);
sleep(15); // make sure the system clock changes
psi.setState(state); // use the same state to confirm that the timestamp updates anyway
oldTimestamp = newTimestamp;
newTimestamp = psi.unmodifiedExistenceInVM();
assertTrue("Valid timestamp after setState()", newTimestamp > oldTimestamp);
sleep(15); // make sure the system clock changes
PackagedSessionImpl psi2 = new PackagedSessionImpl("Test", state, "Test");
psi.update(psi2);
oldTimestamp = newTimestamp;
newTimestamp = psi.unmodifiedExistenceInVM();