[jboss-cvs] JBossAS SVN: r87566 - in trunk/testsuite: src/main/org/jboss/test/timer/ejb and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Apr 20 06:36:02 EDT 2009


Author: galder.zamarreno at jboss.com
Date: 2009-04-20 06:36:01 -0400 (Mon, 20 Apr 2009)
New Revision: 87566

Added:
   trunk/testsuite/src/main/org/jboss/test/timer/ejb/TimerEntityExtBean.java
   trunk/testsuite/src/main/org/jboss/test/timer/interfaces/TimerEntityExt.java
   trunk/testsuite/src/main/org/jboss/test/timer/interfaces/TimerEntityExtHome.java
   trunk/testsuite/src/main/org/jboss/test/timer/test/TimerCleanUpUnitTestCase.java
Modified:
   trunk/testsuite/imports/sections/timer.xml
   trunk/testsuite/src/resources/timer/ejb/ejb-jar.xml
   trunk/testsuite/src/resources/timer/ejb/jboss.xml
Log:
[JBAS-6677] Added unit test for both standard and instance per transaction containers. Fixed also deployment issue: servlet classes should go into WEB-INF/classes in war archive.

Modified: trunk/testsuite/imports/sections/timer.xml
===================================================================
--- trunk/testsuite/imports/sections/timer.xml	2009-04-20 10:33:48 UTC (rev 87565)
+++ trunk/testsuite/imports/sections/timer.xml	2009-04-20 10:36:01 UTC (rev 87566)
@@ -12,7 +12,7 @@
          </zipfileset>
       </zip>
       <zip destfile="${build.lib}/ejb-timer.war">
-         <zipfileset dir="${build.classes}">
+         <zipfileset dir="${build.classes}" prefix="WEB-INF/classes">
             <include name="org/jboss/test/timer/servlet/**"/>
          </zipfileset>
          <zipfileset dir="${build.resources}/timer/war" prefix="WEB-INF">

Added: trunk/testsuite/src/main/org/jboss/test/timer/ejb/TimerEntityExtBean.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/timer/ejb/TimerEntityExtBean.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/timer/ejb/TimerEntityExtBean.java	2009-04-20 10:36:01 UTC (rev 87566)
@@ -0,0 +1,65 @@
+/*
+ * 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.test.timer.ejb;
+
+import javax.ejb.EJBException;
+import javax.ejb.EntityContext;
+import javax.management.ObjectName;
+
+import org.jboss.ejb.Container;
+import org.jboss.ejb.txtimer.EJBTimerService;
+import org.jboss.ejb.txtimer.EJBTimerServiceLocator;
+import org.jboss.mx.util.ObjectNameConverter;
+
+/**
+ * TimerEntityExtBean.
+ * 
+ * @author Galder Zamarreño
+ */
+public class TimerEntityExtBean extends TimerEntityBean
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = -7428841333866106621L;
+   
+   private EntityContext ctx;
+   
+   public boolean hasTimerService(String jndi)
+   {
+      try
+      {
+         EJBTimerService service = EJBTimerServiceLocator.getEjbTimerService();
+         String name = Container.BASE_EJB_CONTAINER_NAME + ",jndiName=" + jndi;
+         ObjectName containerId = ObjectNameConverter.convert(name);
+         return service.getTimerService(containerId, ctx.getPrimaryKey()) != null;         
+      }
+      catch(Exception e)
+      {
+         throw new EJBException("Unable to verify whether entity bean has a timer service associated", e);
+      }
+   }
+   
+   public void setEntityContext(EntityContext ctx)
+   {
+      super.setEntityContext(ctx);
+      this.ctx = ctx;
+   }
+}

Added: trunk/testsuite/src/main/org/jboss/test/timer/interfaces/TimerEntityExt.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/timer/interfaces/TimerEntityExt.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/timer/interfaces/TimerEntityExt.java	2009-04-20 10:36:01 UTC (rev 87566)
@@ -0,0 +1,32 @@
+/*
+ * 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.test.timer.interfaces;
+
+/**
+ * TimerEntityExt.
+ * 
+ * @author Galder Zamarreño
+ */
+public interface TimerEntityExt extends TimerEntity
+{
+   boolean hasTimerService(String jndi) throws java.rmi.RemoteException;
+}

Added: trunk/testsuite/src/main/org/jboss/test/timer/interfaces/TimerEntityExtHome.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/timer/interfaces/TimerEntityExtHome.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/timer/interfaces/TimerEntityExtHome.java	2009-04-20 10:36:01 UTC (rev 87566)
@@ -0,0 +1,36 @@
+/*
+ * 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.test.timer.interfaces;
+
+/**
+ * TimerEntityExt.
+ * 
+ * @author Galder Zamarreño
+ */
+public interface TimerEntityExtHome extends javax.ejb.EJBHome
+{
+   public org.jboss.test.timer.interfaces.TimerEntityExt create(java.lang.Integer pk)
+   throws javax.ejb.CreateException,java.rmi.RemoteException;
+
+   public org.jboss.test.timer.interfaces.TimerEntityExt findByPrimaryKey(java.lang.Integer pk)
+   throws javax.ejb.FinderException,java.rmi.RemoteException;
+}

Added: trunk/testsuite/src/main/org/jboss/test/timer/test/TimerCleanUpUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/timer/test/TimerCleanUpUnitTestCase.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/timer/test/TimerCleanUpUnitTestCase.java	2009-04-20 10:36:01 UTC (rev 87566)
@@ -0,0 +1,141 @@
+/*
+ * 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.test.timer.test;
+
+import javax.ejb.EJBHome;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import junit.framework.Test;
+
+import org.jboss.test.JBossTestCase;
+import org.jboss.test.timer.interfaces.TimerEntityExt;
+import org.jboss.test.timer.interfaces.TimerEntityExtHome;
+
+/**
+ * RemovalAfterPassivationTimerUnitTestCase.
+ * 
+ * @author Galder Zamarreño
+ */
+public class TimerCleanUpUnitTestCase extends JBossTestCase
+{
+   private static final String EJB_TIMER_XAR = "ejb-timer.ear";
+
+   private static final int SHORT_PERIOD = 1 * 1000; // 1s
+
+   public TimerCleanUpUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   /**
+    * Setup the test suite.
+    */
+   public static Test suite() throws Exception
+   {
+      return JBossTestCase.getDeploySetup(TimerCleanUpUnitTestCase.class, EJB_TIMER_XAR);
+   }
+   
+   public void testEntityBeanTimerHasTimerServiceAfterCancellationStd() throws Exception
+   {
+      String jndi = "ejb/test/timer/TimerEntityExtStd";
+      TimerEntityExtHome home = (TimerEntityExtHome) getEJBHome("ejb/test/timer/TimerEntityExtStd");
+      TimerEntityExt entity = home.create(new Integer(333));
+      entity.startTimer(SHORT_PERIOD);
+      Thread.sleep(12 * SHORT_PERIOD);
+      assertTrue("Timer service should be associated with bean." , entity.hasTimerService(jndi));
+      entity.stopTimer();
+      int lCount = entity.getTimeoutCount();
+      assertTrue("Timeout was expected to be called at least 10 times but was "
+         + "only called: " + lCount + " times",
+         lCount >= 10);
+      Thread.sleep(5 * SHORT_PERIOD);
+      int lCount2 = entity.getTimeoutCount();
+      assertTrue("After the timer was stopped no timeout should happen but "
+         + "it was called " + (lCount2 - lCount) + " more times",
+         lCount == lCount2);
+      assertFalse("Timer service should have been passivated and timer service association removed." 
+            , entity.hasTimerService(jndi));
+      entity.remove();
+   }
+   
+   public void testEntityBeanSingleTimerHasTimerServiceAfterExpirationStd() throws Exception
+   {
+      String jndi = "ejb/test/timer/TimerEntityExtStd";
+      TimerEntityExtHome home = (TimerEntityExtHome) getEJBHome("ejb/test/timer/TimerEntityExtStd");
+      TimerEntityExt entity = home.create(new Integer(444));
+      entity.startSingleTimer(SHORT_PERIOD);
+      Thread.sleep(5 * SHORT_PERIOD);
+      assertFalse("Timer service should be associated with bean." , entity.hasTimerService(jndi));
+      int lCount = entity.getTimeoutCount();
+      assertTrue("Timeout was expected to be called only once but was called: "
+         + lCount + " times",
+         lCount == 1);
+      entity.remove();
+   }
+
+   public void testEntityBeanTimerHasTimerServiceAfterCancellationInstPerTx() throws Exception
+   {
+      String jndi = "ejb/test/timer/TimerEntityExtInstPerTx";
+      TimerEntityExtHome home = (TimerEntityExtHome) getEJBHome(jndi);
+      TimerEntityExt entity = home.create(new Integer(555));
+      entity.startTimer(SHORT_PERIOD);
+      Thread.sleep(12 * SHORT_PERIOD);
+      assertTrue("Timer service should be associated with bean." , entity.hasTimerService(jndi));
+      entity.stopTimer();
+      int lCount = entity.getTimeoutCount();
+      assertTrue("Timeout was expected to be called at least 10 times but was "
+         + "only called: " + lCount + " times",
+         lCount >= 10);
+      Thread.sleep(5 * SHORT_PERIOD);
+      int lCount2 = entity.getTimeoutCount();
+      assertTrue("After the timer was stopped no timeout should happen but "
+         + "it was called " + (lCount2 - lCount) + " more times",
+         lCount == lCount2);
+      assertFalse("Timer service should have been passivated and timer service association removed." 
+            , entity.hasTimerService(jndi));
+      entity.remove();
+   }
+   
+   public void testEntityBeanSingleTimerHasTimerServiceAfterExpirationInstPerTx() throws Exception
+   {
+      String jndi = "ejb/test/timer/TimerEntityExtInstPerTx";
+      TimerEntityExtHome home = (TimerEntityExtHome) getEJBHome(jndi);
+      TimerEntityExt entity = home.create(new Integer(666));
+      entity.startSingleTimer(SHORT_PERIOD);
+      Thread.sleep(5 * SHORT_PERIOD);
+      assertFalse("Timer service should be associated with bean." , entity.hasTimerService(jndi));
+      int lCount = entity.getTimeoutCount();
+      assertTrue("Timeout was expected to be called only once but was called: "
+         + lCount + " times",
+         lCount == 1);
+      assertFalse("Timer service should have been passivated and timer service association removed." 
+            , entity.hasTimerService(jndi));
+      entity.remove();
+   }   
+   
+   private EJBHome getEJBHome(String pJNDIName) throws NamingException
+   {
+      InitialContext lContext = new InitialContext();
+      return (EJBHome) lContext.lookup(pJNDIName);
+   }
+}

Modified: trunk/testsuite/src/resources/timer/ejb/ejb-jar.xml
===================================================================
--- trunk/testsuite/src/resources/timer/ejb/ejb-jar.xml	2009-04-20 10:33:48 UTC (rev 87565)
+++ trunk/testsuite/src/resources/timer/ejb/ejb-jar.xml	2009-04-20 10:36:01 UTC (rev 87566)
@@ -35,6 +35,28 @@
          <prim-key-class>java.lang.Integer</prim-key-class>
          <reentrant>false</reentrant>
       </entity>
+      <entity>
+         <description>Extended Entity Bean Timer Standard Container</description>
+         <display-name>Timer in Extended Entity Bean Standard Container</display-name>
+         <ejb-name>TimerEntityExtStd</ejb-name>
+         <home>org.jboss.test.timer.interfaces.TimerEntityExtHome</home>
+         <remote>org.jboss.test.timer.interfaces.TimerEntityExt</remote>
+         <ejb-class>org.jboss.test.timer.ejb.TimerEntityExtBean</ejb-class>
+         <persistence-type>Bean</persistence-type>
+         <prim-key-class>java.lang.Integer</prim-key-class>
+         <reentrant>false</reentrant>
+      </entity>
+      <entity>
+         <description>Extended Entity Bean Timer Instance Per Tx</description>
+         <display-name>Timer in Extended Entity Bean Instance Per Tx</display-name>
+         <ejb-name>TimerEntityExtInstPerTx</ejb-name>
+         <home>org.jboss.test.timer.interfaces.TimerEntityExtHome</home>
+         <remote>org.jboss.test.timer.interfaces.TimerEntityExt</remote>
+         <ejb-class>org.jboss.test.timer.ejb.TimerEntityExtBean</ejb-class>
+         <persistence-type>Bean</persistence-type>
+         <prim-key-class>java.lang.Integer</prim-key-class>
+         <reentrant>false</reentrant>
+      </entity>
 
       <session>
          <description>Secured Stateless Session Bean Timer Test</description>

Modified: trunk/testsuite/src/resources/timer/ejb/jboss.xml
===================================================================
--- trunk/testsuite/src/resources/timer/ejb/jboss.xml	2009-04-20 10:33:48 UTC (rev 87565)
+++ trunk/testsuite/src/resources/timer/ejb/jboss.xml	2009-04-20 10:36:01 UTC (rev 87566)
@@ -15,6 +15,17 @@
          <jndi-name>ejb/test/timer/TimerEntity</jndi-name>
          <timer-persistence>false</timer-persistence>         
       </entity>
+      <entity>
+         <ejb-name>TimerEntityExtStd</ejb-name>
+         <jndi-name>ejb/test/timer/TimerEntityExtStd</jndi-name>
+         <timer-persistence>false</timer-persistence>         
+      </entity>
+      <entity>
+         <ejb-name>TimerEntityExtInstPerTx</ejb-name>
+         <jndi-name>ejb/test/timer/TimerEntityExtInstPerTx</jndi-name>
+         <timer-persistence>false</timer-persistence> 
+         <configuration-name>Instance Per Transaction BMP EntityBean</configuration-name>        
+      </entity>      
       <session>
          <ejb-name>TimerSLSB</ejb-name>
          <jndi-name>ejb/test/timer/TimerSLSB</jndi-name>




More information about the jboss-cvs-commits mailing list