// Get our bean's Session ID
Serializable sessionId = this.getSessionId(bean1);
// Get the Cache
ForceEventsCache cache = (ForceEventsCache) container.getCache();
// Get the lock to block the PM, now
boolean gotLock = BlockingPersistenceManager.PASSIVATION_LOCK.tryLock();
// Once PM lock is acquired, everything is in "try" so we release in "finally"
try
{
// Ensure we got the PM lock, else fail the test
TestCase.assertTrue("Test was not able to immediately get the lock to block the PersistenceManager", gotLock);
log.info("Locked " + BlockingPersistenceManager.class.getSimpleName());
/*
* Mark our session as expired
*/
// Mark
cache.makeSessionEligibleForPassivation(sessionId);
/*
* Passivate
*/
// Trigger Passivation
ForceEventsCache.forcePassivation();
log.info("Passivation forced, carrying out test");
ForceEventsCache.PRE_PASSIVATE_BARRIER.await(5, TimeUnit.SECONDS);
// Block until the PM is ready to passivate
log.info("Waiting on common barrier for PM to run...");
BlockingPersistenceManager.BARRIER.await(5, TimeUnit.SECONDS);
log.info("PM and test have met barrier, passivation running (but will be blocked to complete by test)");
/*
* At this point, we've told the passivation Thread to start, and have
* locked it from completing. So let's try our test in another Thread
* so we can detect a deadlock or permanent blocking after a timeout
*/
ExecutorService executor = Executors.newFixedThreadPool(1);
Future<Boolean> futureResult = executor.submit(testThread);
boolean result = futureResult.get(5, TimeUnit.SECONDS);
/*
* Assert on the result
*/
// If the test has not succeeded
if (!result)
{
// Fail
TestCase.fail("The test has completed without success");
}
// If the test has been successful
else
{
log.info("Test Succeeded");
testSucceeded = true;
}
}
finally
{
// Allow the Persistence Manager to finish up
log.info("Letting the PM perform passivation...");
BlockingPersistenceManager.PASSIVATION_LOCK.unlock();
}
// We need to allow time to let the Cache finish passivation, so block until it's done
log.info("Waiting on Cache to tell us passivation is completed...");
ForceEventsCache.POST_PASSIVATE_BARRIER.await(5, TimeUnit.SECONDS);
log.info("Test sees Cache reports passivation completed.");
/*
* Here we ensure that the session was removed from the internal cacheMap
*/
boolean beanIsInCache = cache.doesCacheMapContainKey(sessionId);
assertFalse("bean " + sessionId + " was not removed from cache", beanIsInCache);
// Ensure we're good
TestCase.assertTrue("The test did not succeed", testSucceeded);
}