public void testCurrentSession() throws Throwable
{
InitialContext ctx = super.getInitialContext();
ITimersHome home = (ITimersHome) ctx.lookup("hib-timers/ITimersHome");
ITimers bean = null;
try
{
bean = home.create();
int initialCount = bean.listTimers().size();
TimersID id = new TimersID("testCurrentSession", "*:ejb=None");
Timers timer = new Timers(id);
Date now = new Date();
Long interval = new Long(5*1000);
Key key = new Key("key2", 123456789);
Info info = new Info(System.getProperties());
timer.setInitialDate(now);
timer.setInstancePK(serialize(key));
timer.setTimerInterval(interval);
timer.setInfo(serialize(info));
bean.persist(timer);
log.info("Timers created with id = " + id);
List timers = bean.listTimers();
assertNotNull(timers);
assertEquals("Incorrect result size", initialCount + 1, timers.size());
Timers found = null;
Iterator itr = timers.iterator();
while (itr.hasNext())
{
Timers t = (Timers) itr.next();
if (id.equals(t.getId()))
{
found = t;
}
}
assertNotNull("Saved timer found in list", found);
Date d = found.getInitialDate();
long t0 = (now.getTime() / 1000) * 1000;
long t1 = (d.getTime() / 1000) * 1000;
assertTrue("Timer.InitialDate("+t1+") == now("+t0+")", t0 == t1);
assertTrue("Timer.Id == id", found.getId().equals(id));
assertTrue("Timer.TimerInterval == interval", found.getTimerInterval().equals(interval));
Object tmp = deserialize(found.getInstancePK());
assertTrue("Timer.InstancePK == key", tmp.equals(key));
tmp = deserialize(found.getInfo());
log.info("Info: "+tmp);
assertTrue("Timer.Info == info", tmp.equals(info));
// Scott forgot to remove the timer
bean.delete(timer);
}
finally
{
if (bean != null)
{
try
{
bean.remove();
}
catch (Throwable t)
{
// ignore
}