[jboss-cvs] JBossAS SVN: r92192 - in projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test: jbpapp1561 and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Aug 10 06:32:56 EDT 2009


Author: wolfc
Date: 2009-08-10 06:32:56 -0400 (Mon, 10 Aug 2009)
New Revision: 92192

Added:
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/jbpapp1561/
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/jbpapp1561/PassivatingStatefulBean.java
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/jbpapp1561/PassivatingStatefulLocal.java
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/jbpapp1561/TestCache.java
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/jbpapp1561/TestCacheFactory.java
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/jbpapp1561/unit/
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/jbpapp1561/unit/PassivationTestCase.java
Log:
JBPAPP-1561: unit test

Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/jbpapp1561/PassivatingStatefulBean.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/jbpapp1561/PassivatingStatefulBean.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/jbpapp1561/PassivatingStatefulBean.java	2009-08-10 10:32:56 UTC (rev 92192)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.core.test.jbpapp1561;
+
+import java.util.concurrent.BrokenBarrierException;
+import java.util.concurrent.CyclicBarrier;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import javax.ejb.PrePassivate;
+import javax.ejb.Stateful;
+
+import org.jboss.ejb3.annotation.Cache;
+import org.jboss.ejb3.annotation.CacheConfig;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Stateful
+ at CacheConfig(idleTimeoutSeconds=1)
+ at Cache(TestCacheFactory.NAME)
+public class PassivatingStatefulBean implements PassivatingStatefulLocal
+{
+   public static final CyclicBarrier barrier = new CyclicBarrier(2);
+   
+   public static boolean finalized = false;
+   
+   @Override
+   protected void finalize() throws Throwable
+   {
+      finalized = true;
+   }
+   
+   @PrePassivate
+   public void prePassivate()
+   {
+      try
+      {
+         barrier.await(10, TimeUnit.SECONDS);
+      }
+      catch(BrokenBarrierException e)
+      {
+         throw new RuntimeException(e);
+      }
+      catch (InterruptedException e)
+      {
+         throw new RuntimeException(e);
+      }
+      catch (TimeoutException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+}

Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/jbpapp1561/PassivatingStatefulLocal.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/jbpapp1561/PassivatingStatefulLocal.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/jbpapp1561/PassivatingStatefulLocal.java	2009-08-10 10:32:56 UTC (rev 92192)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.core.test.jbpapp1561;
+
+import javax.ejb.Local;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Local
+public interface PassivatingStatefulLocal
+{
+
+}

Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/jbpapp1561/TestCache.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/jbpapp1561/TestCache.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/jbpapp1561/TestCache.java	2009-08-10 10:32:56 UTC (rev 92192)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.core.test.jbpapp1561;
+
+import org.jboss.ejb3.EJBContainer;
+import org.jboss.ejb3.cache.StatefulCache;
+import org.jboss.ejb3.cache.simple.SimpleStatefulCache;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at SuppressWarnings("deprecation")
+public class TestCache extends SimpleStatefulCache implements StatefulCache
+{
+   public static final Object passivationCompleteNotification = new Object();
+   
+   @Override
+   public void initialize(EJBContainer container) throws Exception
+   {
+      super.initialize(container);
+      
+      setTimeoutTask(new SessionTimeoutTask("SFSB Passivation Thread - " + container.getObjectName().getCanonicalName()) {
+         @Override
+         protected void passivationCompleted()
+         {
+            TestCache.this.passivationCompleted();
+         }
+      });
+   }
+
+   protected void passivationCompleted()
+   {
+      synchronized (passivationCompleteNotification)
+      {
+         passivationCompleteNotification.notifyAll();
+      }
+   }
+}

Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/jbpapp1561/TestCacheFactory.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/jbpapp1561/TestCacheFactory.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/jbpapp1561/TestCacheFactory.java	2009-08-10 10:32:56 UTC (rev 92192)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.core.test.jbpapp1561;
+
+import org.jboss.ejb3.cache.Ejb3CacheFactory;
+import org.jboss.ejb3.cache.StatefulCache;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at SuppressWarnings("deprecation")
+public class TestCacheFactory implements Ejb3CacheFactory
+{
+   public static final String NAME = "TestCacheFactory";
+   
+   public StatefulCache createCache()
+   {
+      return new TestCache();
+   }
+
+}

Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/jbpapp1561/unit/PassivationTestCase.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/jbpapp1561/unit/PassivationTestCase.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/jbpapp1561/unit/PassivationTestCase.java	2009-08-10 10:32:56 UTC (rev 92192)
@@ -0,0 +1,96 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.core.test.jbpapp1561.unit;
+
+import java.util.concurrent.TimeUnit;
+
+import junit.framework.Assert;
+
+import org.jboss.ejb3.cache.CacheFactoryRegistry;
+import org.jboss.ejb3.common.registrar.spi.Ejb3RegistrarLocator;
+import org.jboss.ejb3.core.test.common.AbstractEJB3TestCase;
+import org.jboss.ejb3.core.test.jbpapp1561.PassivatingStatefulBean;
+import org.jboss.ejb3.core.test.jbpapp1561.PassivatingStatefulLocal;
+import org.jboss.ejb3.core.test.jbpapp1561.TestCache;
+import org.jboss.ejb3.core.test.jbpapp1561.TestCacheFactory;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class PassivationTestCase extends AbstractEJB3TestCase
+{
+   @After
+   public void after()
+   {
+      PassivatingStatefulBean.barrier.reset();
+      PassivatingStatefulBean.finalized = false;
+   }
+   
+   @AfterClass
+   public static void afterClass() throws Exception
+   {
+      CacheFactoryRegistry cacheFactoryRegistry = Ejb3RegistrarLocator.locateRegistrar().lookup("EJB3CacheFactoryRegistry", CacheFactoryRegistry.class);
+      cacheFactoryRegistry.getFactories().remove(TestCacheFactory.NAME);
+      
+      AbstractEJB3TestCase.afterClass();
+   }
+   
+   @BeforeClass
+   public static void beforeClass() throws Exception
+   {
+      AbstractEJB3TestCase.beforeClass();
+      
+      // Add the Force Passivation Cache
+      CacheFactoryRegistry cacheFactoryRegistry = Ejb3RegistrarLocator.locateRegistrar().lookup("EJB3CacheFactoryRegistry", CacheFactoryRegistry.class);
+      cacheFactoryRegistry.getFactories().put(TestCacheFactory.NAME, TestCacheFactory.class);
+      //log.info("Added " + forcePassivationCacheRegistryName);
+
+      deploySessionEjb(PassivatingStatefulBean.class);
+   }
+   
+   @Test
+   public void test1() throws Exception
+   {
+      PassivatingStatefulLocal bean = lookup("PassivatingStatefulBean/local", PassivatingStatefulLocal.class);
+      Assert.assertNotNull(bean);
+      
+      PassivatingStatefulBean.barrier.await(10, TimeUnit.SECONDS);
+      
+      synchronized (TestCache.passivationCompleteNotification)
+      {
+         TestCache.passivationCompleteNotification.wait(10000);
+      }
+      
+      for(int i = 0; i < 3; i++)
+      {
+         System.gc();
+         Runtime.getRuntime().runFinalization();
+      }
+      
+      Assert.assertTrue("bean should have been purged from memory", PassivatingStatefulBean.finalized);
+   }
+}




More information about the jboss-cvs-commits mailing list