public void testPassivationByTime() throws Exception
{
Context ctx = new InitialContext();
getLog().debug("+++ testPassivationByTime");
StatefulSessionHome sessionHome = ( StatefulSessionHome ) ctx.lookup("ejbcts/StatefulSessionBean");
StatefulSession sessionBean1 = sessionHome.create("testPassivationByTime");
sessionBean1.method1("hello");
getLog().debug("Retrieving handle for object");
Handle handle = sessionBean1.getHandle();
getLog().debug("Waiting 41 seconds for passivation...");
Thread.sleep(41*1000);
// Validate that sessionBean1 was passivated and activated
boolean passivated = sessionBean1.getWasPassivated();
assertTrue("sessionBean1 WasPassivated", passivated);
boolean activated = sessionBean1.getWasActivated();
assertTrue("sessionBean1 WasActivated", activated);
getLog().debug("Waiting 90 seconds for removal due to age...");
Thread.sleep(90*1000);
try
{
handle.getEJBObject();
fail("Was able to get the remote interface for a removed session");
}
catch (RemoteException expected)
{
getLog().debug("Handle access failed as expected", expected);
}
try
{
passivated = sessionBean1.getWasPassivated();
fail("Was able to invoke getWasPassivated after bean should have been removed");
}
catch(Exception e)
{
getLog().debug("Bean access failed as expected", e);