[jboss-cvs] JBossAS SVN: r80122 - in projects/ejb3/trunk/core/src: test/java/org/jboss/ejb3/core/test/ejbthree1549 and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Oct 27 17:22:06 EDT 2008
Author: ALRubinger
Date: 2008-10-27 17:22:06 -0400 (Mon, 27 Oct 2008)
New Revision: 80122
Modified:
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/cache/simple/SimpleStatefulCache.java
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1549/ForcePassivationCache.java
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1549/unit/PassivationDoesNotPreventNewActivityUnitTestCase.java
Log:
[EJBTHREE-1549] Ensure that the SFSB is removed from the internal cacheMap, not just the copy. Also correct the tests to check for this case
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/cache/simple/SimpleStatefulCache.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/cache/simple/SimpleStatefulCache.java 2008-10-27 20:49:26 UTC (rev 80121)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/cache/simple/SimpleStatefulCache.java 2008-10-27 21:22:06 UTC (rev 80122)
@@ -63,7 +63,7 @@
private int passivatedCount = 0;
private int removeCount = 0;
- private class CacheMap extends LinkedHashMap
+ protected class CacheMap extends LinkedHashMap
{
private static final long serialVersionUID = 4514182777643616159L;
@@ -250,9 +250,36 @@
centry.markedForPassivation = true;
assert centry.isInUse() : centry + " is not in use, and thus will never be passivated";
}
+
+
// its ok to evict because it will be passivated
// or we determined above that we can remove it
+
+ // Remove from the copy
it.remove();
+
+ /*
+ * EJBTHREE-1549
+ */
+
+ // Remove from the internal cacheMap
+
+ Object removed = null;
+ Object key = entry.getKey();
+ synchronized (cacheMap)
+ {
+ removed = cacheMap.remove(key);
+ }
+
+ // Perform some assertions
+ assert removed != null : "Could not remove key " + key
+ + " from internal cacheMap as there was no corresponding entry";
+ assert removed == centry : "Removed " + removed
+ + " from internal cacheMap did not match the object we were expecting: " + centry;
+
+ /*
+ * End EJBTHREE-1549
+ */
}
}
else if (trace)
Modified: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1549/ForcePassivationCache.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1549/ForcePassivationCache.java 2008-10-27 20:49:26 UTC (rev 80121)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1549/ForcePassivationCache.java 2008-10-27 21:22:06 UTC (rev 80122)
@@ -21,6 +21,8 @@
*/
package org.jboss.ejb3.core.test.ejbthree1549;
+import java.io.Serializable;
+
import org.jboss.ejb3.cache.simple.SimpleStatefulCache;
import org.jboss.logging.Logger;
@@ -62,6 +64,27 @@
}
}
+ /**
+ * Exposed for testing only
+ *
+ * Returns whether or not the internal cacheMap contains
+ * the specified key
+ *
+ * @return
+ */
+ public boolean doesCacheMapContainKey(Serializable sessionId)
+ {
+ // Get the cacheMap
+ CacheMap cm = this.cacheMap;
+
+ // Synchronize on it
+ synchronized(cm)
+ {
+ // Return whether the specified key was found
+ return cm.containsKey(sessionId);
+ }
+ }
+
// --------------------------------------------------------------------------------||
// Overridden Implementations -----------------------------------------------------||
// --------------------------------------------------------------------------------||
@@ -103,7 +126,7 @@
log.info("Waiting to be notified to run passivation...");
PASSIVATION_LOCK.wait();
}
-
+
// Log that we've been notified
log.info("Notified to run passivation");
}
Modified: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1549/unit/PassivationDoesNotPreventNewActivityUnitTestCase.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1549/unit/PassivationDoesNotPreventNewActivityUnitTestCase.java 2008-10-27 20:49:26 UTC (rev 80121)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1549/unit/PassivationDoesNotPreventNewActivityUnitTestCase.java 2008-10-27 21:22:06 UTC (rev 80122)
@@ -24,15 +24,12 @@
import static org.junit.Assert.assertFalse;
import java.io.Serializable;
-import java.lang.reflect.Field;
import java.lang.reflect.Proxy;
-import java.util.Map;
import junit.framework.TestCase;
import org.jboss.ejb3.cache.CacheFactoryRegistry;
import org.jboss.ejb3.cache.persistence.PersistenceManagerFactoryRegistry;
-import org.jboss.ejb3.cache.simple.SimpleStatefulCache;
import org.jboss.ejb3.common.registrar.spi.Ejb3RegistrarLocator;
import org.jboss.ejb3.core.test.common.AbstractEJB3TestCase;
import org.jboss.ejb3.core.test.ejbthree1549.BlockingPersistenceManager;
@@ -68,32 +65,6 @@
private static final Logger log = Logger.getLogger(PassivationDoesNotPreventNewActivityUnitTestCase.class);
- private static Map getCacheMap(SimpleStatefulCache cache)
- {
- try
- {
- Field f = SimpleStatefulCache.class.getDeclaredField("cacheMap");
- f.setAccessible(true);
- return (Map) f.get(cache);
- }
- catch(SecurityException e)
- {
- throw new RuntimeException(e);
- }
- catch(NoSuchFieldException e)
- {
- throw new RuntimeException(e);
- }
- catch (IllegalArgumentException e)
- {
- throw new RuntimeException(e);
- }
- catch (IllegalAccessException e)
- {
- throw new RuntimeException(e);
- }
- }
-
// --------------------------------------------------------------------------------||
// Tests --------------------------------------------------------------------------||
// --------------------------------------------------------------------------------||
@@ -247,10 +218,6 @@
// Wait to allow passivation to actually start
Thread.sleep(2000);
- StatefulLocalProxyInvocationHandler handler = (StatefulLocalProxyInvocationHandler) Proxy.getInvocationHandler(bean1);
- Serializable sessionId = handler.getSessionId();
- assertFalse("bean was not removed from cache", getCacheMap((SimpleStatefulCache) ((StatefulContainer) container).getCache()).containsKey(sessionId));
-
/*
* 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
@@ -293,7 +260,23 @@
// Allow the Persistence Manager to finish up
BlockingPersistenceManager.LOCK.unlock();
+
+ // We need to allow time to let PM do its thing, so use the lock to block then release
+ Thread.sleep(150); // Just to make sure the PM gets the lock back first
+ BlockingPersistenceManager.LOCK.lock(); // Block until PM is done
+ BlockingPersistenceManager.LOCK.unlock(); // PM must be done, we don't really need the lock, release it
}
+
+
+ /*
+ * Here we ensure that the session was removed from the internal cacheMap
+ */
+ StatefulLocalProxyInvocationHandler handler = (StatefulLocalProxyInvocationHandler) Proxy
+ .getInvocationHandler(bean1);
+ Serializable sessionId = handler.getSessionId();
+ boolean beanIsInCache = ((ForcePassivationCache) ((StatefulContainer) container).getCache())
+ .doesCacheMapContainKey(sessionId);
+ assertFalse("bean was not removed from cache", beanIsInCache);
// Ensure we're good
TestCase.assertTrue("The test did not succeed", testSucceeded);
More information about the jboss-cvs-commits
mailing list