[jboss-cvs] JBossAS SVN: r66008 - in projects/ejb3/trunk/ejb3-cache/src: test/java/org/jboss/ejb3/test and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Oct 10 09:46:11 EDT 2007
Author: wolfc
Date: 2007-10-10 09:46:11 -0400 (Wed, 10 Oct 2007)
New Revision: 66008
Added:
projects/ejb3/trunk/ejb3-cache/src/test/java/org/jboss/ejb3/test/cache/
projects/ejb3/trunk/ejb3-cache/src/test/java/org/jboss/ejb3/test/cache/common/
projects/ejb3/trunk/ejb3-cache/src/test/java/org/jboss/ejb3/test/cache/common/CacheTestCase.java
Modified:
projects/ejb3/trunk/ejb3-cache/src/main/java/org/jboss/ejb3/cache/impl/SimplePassivatingCache.java
projects/ejb3/trunk/ejb3-cache/src/test/java/org/jboss/ejb3/test/passivation/PassivationUnitTestCase.java
Log:
Fixed removing of passivated object
Modified: projects/ejb3/trunk/ejb3-cache/src/main/java/org/jboss/ejb3/cache/impl/SimplePassivatingCache.java
===================================================================
--- projects/ejb3/trunk/ejb3-cache/src/main/java/org/jboss/ejb3/cache/impl/SimplePassivatingCache.java 2007-10-10 11:53:35 UTC (rev 66007)
+++ projects/ejb3/trunk/ejb3-cache/src/main/java/org/jboss/ejb3/cache/impl/SimplePassivatingCache.java 2007-10-10 13:46:11 UTC (rev 66008)
@@ -39,7 +39,7 @@
* Comment
*
* @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
- * @version $Revision: $
+ * @version $Revision$
*/
public class SimplePassivatingCache<T extends Identifiable & Serializable> implements PassivatingCache<T>
{
@@ -140,6 +140,27 @@
this.cache = new HashMap<Object, Entry>();
}
+ /**
+ * Activate an entry and put it back in the cache.
+ *
+ * This method is not thread safe.
+ *
+ * @param key the indentifier of the object
+ * @return the entry or null if not found
+ */
+ protected Entry activate(Object key)
+ {
+ T obj = store.load(key);
+ if(obj == null)
+ return null;
+
+ passivationManager.postActivate(obj);
+
+ Entry entry = new Entry(obj);
+ cache.put(key, entry);
+ return entry;
+ }
+
public T create(Class<?>[] initTypes, Object[] initValues)
{
T obj = factory.create(initTypes, initValues);
@@ -158,15 +179,9 @@
Entry entry = cache.get(key);
if(entry == null)
{
- T obj = store.load(key);
- if(obj != null)
- {
- passivationManager.postActivate(obj);
-
- entry = new Entry(obj);
- cache.put(key, entry);
+ entry = activate(key);
+ if(entry != null)
return entry.obj;
- }
}
if(entry == null)
throw new NoSuchEJBException(String.valueOf(key));
@@ -206,15 +221,11 @@
Entry entry = cache.get(key);
if(entry == null)
{
- T obj = store.load(key);
- if(obj != null)
- {
- passivationManager.postActivate(obj);
-
- entry = new Entry(obj);
- cache.put(key, entry);
+ entry = activate(key);
+ // We're only peeking so the entry is not in use,
+ // since it's just activated it couldn't have been in use as well.
+ if(entry != null)
entry.state = EntryState.READY;
- }
}
if(entry == null)
throw new NoSuchEJBException(String.valueOf(key));
@@ -247,6 +258,14 @@
synchronized (cache)
{
entry = cache.remove(key);
+ if(entry == null)
+ {
+ entry = activate(key);
+ if(entry == null)
+ throw new NoSuchEJBException(String.valueOf(key));
+ // The entry was not in use, so it must be ready
+ entry.state = EntryState.READY;
+ }
if(entry.state != EntryState.READY)
throw new IllegalStateException("entry " + entry + " is not ready");
}
Added: projects/ejb3/trunk/ejb3-cache/src/test/java/org/jboss/ejb3/test/cache/common/CacheTestCase.java
===================================================================
--- projects/ejb3/trunk/ejb3-cache/src/test/java/org/jboss/ejb3/test/cache/common/CacheTestCase.java (rev 0)
+++ projects/ejb3/trunk/ejb3-cache/src/test/java/org/jboss/ejb3/test/cache/common/CacheTestCase.java 2007-10-10 13:46:11 UTC (rev 66008)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.cache.common;
+
+import junit.framework.TestCase;
+
+/**
+ * A TestCase helper.
+ *
+ * You can either extend it or call the static helper methods directly.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public abstract class CacheTestCase extends TestCase
+{
+ /**
+ * Sleep for the specified number of milliseconds, ignoring
+ * any resulting InterruptedException. The method execution
+ * is cut short if an InterruptedException occurs.
+ *
+ * @param micros the length of time to sleep in milliseconds.
+ */
+ public static void sleep(long millis)
+ {
+ try
+ {
+ Thread.sleep(millis);
+ }
+ catch (InterruptedException e)
+ {
+ // ignore
+ }
+ }
+
+ /**
+ * Wait for notification on the object for 5 seconds.
+ *
+ * @param obj the object to wait on.
+ * @throws InterruptedException if the wait is interrupted.
+ */
+ public static void wait(Object obj) throws InterruptedException
+ {
+ synchronized (obj)
+ {
+ obj.wait(5000);
+ }
+ }
+}
Property changes on: projects/ejb3/trunk/ejb3-cache/src/test/java/org/jboss/ejb3/test/cache/common/CacheTestCase.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Modified: projects/ejb3/trunk/ejb3-cache/src/test/java/org/jboss/ejb3/test/passivation/PassivationUnitTestCase.java
===================================================================
--- projects/ejb3/trunk/ejb3-cache/src/test/java/org/jboss/ejb3/test/passivation/PassivationUnitTestCase.java 2007-10-10 11:53:35 UTC (rev 66007)
+++ projects/ejb3/trunk/ejb3-cache/src/test/java/org/jboss/ejb3/test/passivation/PassivationUnitTestCase.java 2007-10-10 13:46:11 UTC (rev 66008)
@@ -23,29 +23,16 @@
import org.jboss.ejb3.cache.impl.FileObjectStore;
import org.jboss.ejb3.cache.impl.SimplePassivatingCache;
+import org.jboss.ejb3.test.cache.common.CacheTestCase;
-import junit.framework.TestCase;
-
/**
* Comment
*
* @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
- * @version $Revision: $
+ * @version $Revision$
*/
-public class PassivationUnitTestCase extends TestCase
+public class PassivationUnitTestCase extends CacheTestCase
{
- private static void sleep(long micros)
- {
- try
- {
- Thread.sleep(micros);
- }
- catch (InterruptedException e)
- {
- // ignore
- }
- }
-
public void test1() throws InterruptedException
{
MockBeanContainer container = new MockBeanContainer();
@@ -106,11 +93,30 @@
obj = null;
}
- private static void wait(Object obj) throws InterruptedException
+ /**
+ * Test the remove of a passivated object.
+ */
+ public void testRemotePassivated() throws Exception
{
- synchronized (obj)
- {
- obj.wait(5000);
- }
+ MockBeanContainer container = new MockBeanContainer();
+ FileObjectStore<MockBeanContext> store = new FileObjectStore<MockBeanContext>();
+ store.setStorageDirectory("./target/tmp/passivation");
+ store.start();
+ SimplePassivatingCache<MockBeanContext> cache = new SimplePassivatingCache<MockBeanContext>(container, container, store);
+ cache.setName("MockBeanContainer");
+ cache.setSessionTimeout(1);
+ cache.start();
+
+ MockBeanContext obj = cache.create(null, null);
+ Object key = obj.getId();
+
+ cache.release(obj);
+ obj = null;
+
+ wait(container);
+
+ assertEquals("MockBeanContext should have been passivated", 1, container.passivations);
+
+ cache.remove(key);
}
}
More information about the jboss-cvs-commits
mailing list