[jboss-cvs] JBossAS SVN: r106313 - in projects/ejb3/trunk/testsuite: src/test/java/org/jboss/ejb3/test and 5 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jun 29 12:52:25 EDT 2010
Author: jaikiran
Date: 2010-06-29 12:52:24 -0400 (Tue, 29 Jun 2010)
New Revision: 106313
Added:
projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/
projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/BaseClassWithProtectedTimeoutMethod.java
projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/DummyEntity.java
projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/MDBTimerUtil.java
projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/MDBTimerUtilImpl.java
projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/MDBWithPrivateTimeoutMethod.java
projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/SLSBWithTimeoutMethodInBaseClass.java
projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/SimpleSLSBWithTimeout.java
projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/TimeoutInfo.java
projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/TimeoutTracker.java
projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/TimerUtil.java
projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/unit/
projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/unit/NonPublicTimeoutMethodTestCase.java
projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree2125/
projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree2125/META-INF/
projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree2125/META-INF/persistence.xml
Modified:
projects/ejb3/trunk/testsuite/build-test.xml
Log:
EJBTHREE-2125 Added a testcase to test non-public timer method invocations on beans
Modified: projects/ejb3/trunk/testsuite/build-test.xml
===================================================================
--- projects/ejb3/trunk/testsuite/build-test.xml 2010-06-29 16:46:05 UTC (rev 106312)
+++ projects/ejb3/trunk/testsuite/build-test.xml 2010-06-29 16:52:24 UTC (rev 106313)
@@ -4217,6 +4217,16 @@
<build-simple-jar name="ejbthree2095"/>
</target>
+ <target name="ejbthree2125">
+ <mkdir dir="${build.lib}" />
+ <jar jarfile="${build.lib}/ejbthree2125.jar">
+ <fileset dir="${build.classes}">
+ <include name="org/jboss/ejb3/test/ejbthree2125/*.class" />
+ </fileset>
+ <fileset dir="${resources}/test/ejbthree2125" />
+ </jar>
+ </target>
+
<target name="jars" depends="removedislocal, statelesscreation, defaultremotebindings, localfromremote, clusteredjms, concurrentnaming, propertyreplacement, persistenceunits, appclient, tck5sec, invalidtxmdb, descriptortypo, libdeployment, homeinterface, arjuna, mdbtransactions, unauthenticatedprincipal, clusteredservice, invoker, classloader,
concurrent,
circulardependency, jsp, timerdependency, servicedependency, stateless14, webservices, ear, ejbthree440,
@@ -4250,7 +4260,7 @@
composite, composite2, entitycallback, relationships, ssl, ssladvanced, clusteredsession, strictpool, jacc,
localcall, interceptors, interceptors2, interceptors3, iiop, clientinterceptor,
statelesscreation, changexml, externalrefscoped, ejbthree1671, ejbthree1677, ejbthree1629,
- ejbthree1807, ejbthree1346, ejbthree1823, ejbthree1858, ejbthree1876, ejbthree1926, ejbthree2038, ejbthree2061"/>
+ ejbthree1807, ejbthree1346, ejbthree1823, ejbthree1858, ejbthree1876, ejbthree1926, ejbthree2038, ejbthree2061, ejbthree2125"/>
<target name="test" depends="init" if="test"
description="Execute all tests in the given test directory.">
@@ -5079,6 +5089,9 @@
<antcall target="test" inheritRefs="true">
<param name="test" value="ejbthree2061"/>
</antcall>
+ <antcall target="test" inheritRefs="true">
+ <param name="test" value="ejbthree2125"/>
+ </antcall>
<antcall target="test" inheritRefs="true">
<param name="test" value="statelesscreation"/>
</antcall>
Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/BaseClassWithProtectedTimeoutMethod.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/BaseClassWithProtectedTimeoutMethod.java (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/BaseClassWithProtectedTimeoutMethod.java 2010-06-29 16:52:24 UTC (rev 106313)
@@ -0,0 +1,88 @@
+/*
+ * 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.test.ejbthree2125;
+
+import java.util.Date;
+
+import javax.annotation.Resource;
+import javax.ejb.Timeout;
+import javax.ejb.Timer;
+import javax.ejb.TimerService;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+import org.jboss.logging.Logger;
+
+/**
+ * BaseClassWithProtectedTimeoutMethod
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class BaseClassWithProtectedTimeoutMethod
+{
+ private static Logger logger = Logger.getLogger(BaseClassWithProtectedTimeoutMethod.class);
+
+ @Resource
+ protected TimerService timerService;
+
+ @PersistenceContext
+ protected EntityManager em;
+
+ @Timeout
+ protected void protectedAccessOnTimeoutMethod(Timer timer)
+ {
+ logger.info("protected timeout method invoked at: " + new Date());
+
+ TimeoutInfo timeoutInfo = new TimeoutInfo();
+ TimeoutTracker.getInstance().trackTimeout(timer, timeoutInfo);
+
+ this.checkInjectedResource(timeoutInfo);
+ this.checkTxAccess(timeoutInfo);
+ }
+
+ private void checkInjectedResource(TimeoutInfo timeoutInfo)
+ {
+ logger.info("Timerservice: " + this.timerService);
+ // just access the injected resources and do any tx related work
+ if (this.timerService != null)
+ {
+ timeoutInfo.setResourcesInjected(true);
+ }
+ else
+ {
+ timeoutInfo.setResourcesInjected(false);
+ }
+ }
+
+ private void checkTxAccess(TimeoutInfo timeoutInfo)
+ {
+ logger.info("Entitymanager: " + this.em);
+ DummyEntity dummyEntity = new DummyEntity();
+ dummyEntity.setName("EJBTHREE-2125");
+ this.em.persist(dummyEntity);
+ this.em.flush();
+ // success (i.e. entity manager did not throw a tx related exception)
+ timeoutInfo.setTransactional(true);
+ }
+
+}
Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/DummyEntity.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/DummyEntity.java (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/DummyEntity.java 2010-06-29 16:52:24 UTC (rev 106313)
@@ -0,0 +1,62 @@
+/*
+ * 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.test.ejbthree2125;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+
+/**
+ * DummyEntity
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ at Entity
+public class DummyEntity
+{
+
+ @Id
+ @GeneratedValue (strategy =GenerationType.AUTO)
+ private Integer id;
+
+ private String name;
+
+ public Integer getId()
+ {
+ return id;
+ }
+
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+
+}
Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/MDBTimerUtil.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/MDBTimerUtil.java (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/MDBTimerUtil.java 2010-06-29 16:52:24 UTC (rev 106313)
@@ -0,0 +1,39 @@
+/*
+ * 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.test.ejbthree2125;
+
+/**
+ * MDBTimerUtil
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public interface MDBTimerUtil
+{
+ void sendMessageForTimerCreation();
+
+ boolean wasTimeoutInvoked();
+
+ boolean wasResourceInjectedDuringTimeout();
+
+ boolean wasTxAvailableDuringTimeout();
+}
Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/MDBTimerUtilImpl.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/MDBTimerUtilImpl.java (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/MDBTimerUtilImpl.java 2010-06-29 16:52:24 UTC (rev 106313)
@@ -0,0 +1,131 @@
+/*
+ * 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.test.ejbthree2125;
+
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.jms.TextMessage;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.jboss.ejb3.annotation.RemoteBinding;
+import org.jboss.logging.Logger;
+
+/**
+ * MDBTimerUtil
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ at Stateless
+ at Remote(MDBTimerUtil.class)
+ at RemoteBinding(jndiBinding = MDBTimerUtilImpl.JNDI_NAME)
+public class MDBTimerUtilImpl implements MDBTimerUtil
+{
+
+ public static final String JNDI_NAME = "ejbthree-2125-MDBTimerUtilSLSB";
+
+ private static Logger logger = Logger.getLogger(MDBTimerUtilImpl.class);
+
+ @Override
+ public void sendMessageForTimerCreation()
+ {
+ QueueConnection queueConnection = null;
+ QueueSession queueSession = null;
+ try
+ {
+ Context ctx = new InitialContext();
+ //just drop a message in the queue
+ Queue queue = (Queue) ctx.lookup(MDBWithPrivateTimeoutMethod.QUEUE_JNDI_NAME);
+ QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("ConnectionFactory");
+ queueConnection = factory.createQueueConnection();
+ queueSession = queueConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+
+ TextMessage msg = queueSession.createTextMessage("Hello World");
+
+ QueueSender sender = queueSession.createSender(queue);
+ sender.send(msg);
+ logger.info("Sent a message to queue: " + MDBWithPrivateTimeoutMethod.QUEUE_JNDI_NAME);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ finally
+ {
+ try
+ {
+ if (queueSession != null)
+ {
+ queueSession.close();
+ }
+ if (queueConnection != null)
+ {
+ queueConnection.close();
+ }
+ }
+ catch (Exception e)
+ {
+ // ignore
+ }
+ }
+
+ }
+
+ @Override
+ public boolean wasResourceInjectedDuringTimeout()
+ {
+ TimeoutInfo timeoutInfo = TimeoutTracker.getInstance()
+ .getTimeoutInfo(MDBWithPrivateTimeoutMethod.class.getName());
+ if (timeoutInfo == null)
+ {
+ throw new RuntimeException("Timeout method was not invoked on MDB: "
+ + MDBWithPrivateTimeoutMethod.class.getName());
+ }
+ return timeoutInfo.isResourcesInjected();
+ }
+
+ @Override
+ public boolean wasTimeoutInvoked()
+ {
+ return TimeoutTracker.getInstance().getTimeoutInfo(MDBWithPrivateTimeoutMethod.class.getName()) != null;
+ }
+
+ @Override
+ public boolean wasTxAvailableDuringTimeout()
+ {
+ TimeoutInfo timeoutInfo = TimeoutTracker.getInstance()
+ .getTimeoutInfo(MDBWithPrivateTimeoutMethod.class.getName());
+ if (timeoutInfo == null)
+ {
+ throw new RuntimeException("Timeout method was not invoked on MDB: "
+ + MDBWithPrivateTimeoutMethod.class.getName());
+ }
+ return timeoutInfo.isTransactional();
+ }
+
+}
Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/MDBWithPrivateTimeoutMethod.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/MDBWithPrivateTimeoutMethod.java (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/MDBWithPrivateTimeoutMethod.java 2010-06-29 16:52:24 UTC (rev 106313)
@@ -0,0 +1,107 @@
+/*
+ * 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.test.ejbthree2125;
+
+import java.util.Date;
+
+import javax.annotation.Resource;
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.MessageDriven;
+import javax.ejb.Timeout;
+import javax.ejb.Timer;
+import javax.ejb.TimerService;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+import org.jboss.logging.Logger;
+
+/**
+ * MDBWithPrivateTimeoutMethod
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ at MessageDriven(activationConfig =
+{@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
+ @ActivationConfigProperty(propertyName = "destination", propertyValue = MDBWithPrivateTimeoutMethod.QUEUE_JNDI_NAME)})
+public class MDBWithPrivateTimeoutMethod implements MessageListener
+{
+
+ public static final String QUEUE_JNDI_NAME = "queue/ejbthree2125";
+
+ private static Logger logger = Logger.getLogger(MDBWithPrivateTimeoutMethod.class);
+
+ @Resource
+ private TimerService timerService;
+
+ @PersistenceContext
+ private EntityManager em;
+
+ @Override
+ public void onMessage(Message message)
+ {
+ logger.info("Message received at: " + new Date());
+ Date twoSecondsFromNow = new Date(System.currentTimeMillis() + 2000);
+ this.timerService.createTimer(twoSecondsFromNow, 0, this.getClass().getName());
+ logger.info("Timer created to fire at: " + twoSecondsFromNow);
+
+ }
+
+ @Timeout
+ private void onTimeout(Timer timer)
+ {
+ logger.info("private timeout method invoked on MDB, at: " + new Date());
+
+ TimeoutInfo timeoutInfo = new TimeoutInfo();
+ TimeoutTracker.getInstance().trackTimeout(timer, timeoutInfo);
+
+ this.checkInjectedResource(timeoutInfo);
+ this.checkTxAccess(timeoutInfo);
+ }
+
+ private void checkInjectedResource(TimeoutInfo timeoutInfo)
+ {
+ logger.info("Timerservice: " + this.timerService);
+ // just access the injected resources and do any tx related work
+ if (this.timerService != null)
+ {
+ timeoutInfo.setResourcesInjected(true);
+ }
+ else
+ {
+ timeoutInfo.setResourcesInjected(false);
+ }
+ }
+
+ private void checkTxAccess(TimeoutInfo timeoutInfo)
+ {
+ logger.info("Entitymanager: " + this.em);
+ DummyEntity dummyEntity = new DummyEntity();
+ dummyEntity.setName("EJBTHREE-2125-MDB");
+ this.em.persist(dummyEntity);
+ this.em.flush();
+ // success (i.e. entity manager did not throw a tx related exception)
+ timeoutInfo.setTransactional(true);
+ }
+}
Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/SLSBWithTimeoutMethodInBaseClass.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/SLSBWithTimeoutMethodInBaseClass.java (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/SLSBWithTimeoutMethodInBaseClass.java 2010-06-29 16:52:24 UTC (rev 106313)
@@ -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.test.ejbthree2125;
+
+import java.util.Date;
+
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+
+import org.jboss.ejb3.annotation.RemoteBinding;
+import org.jboss.logging.Logger;
+
+/**
+ * SLSBWithTimeoutMethodInBaseClass
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ at Stateless
+ at Remote (TimerUtil.class)
+ at RemoteBinding (jndiBinding = SLSBWithTimeoutMethodInBaseClass.JNDI_NAME)
+public class SLSBWithTimeoutMethodInBaseClass extends BaseClassWithProtectedTimeoutMethod implements TimerUtil
+{
+
+ public static final String JNDI_NAME = "Ejbthree-2125-SLSBWithTimeoutInBaseClass";
+
+ private static Logger logger = Logger.getLogger(SLSBWithTimeoutMethodInBaseClass.class);
+
+ @Override
+ public void createTimer(Date initialExpiry, int interval)
+ {
+ this.timerService.createTimer(initialExpiry, interval, this.getClass().getName());
+ logger.info("Timer created to fire at: " + initialExpiry);
+ }
+
+ @Override
+ public boolean wasTimeoutInvoked()
+ {
+ return TimeoutTracker.getInstance().getTimeoutInfo(this.getClass().getName()) != null;
+ }
+
+ @Override
+ public boolean wasResourceInjectedDuringTimeout()
+ {
+ TimeoutInfo timeoutInfo = TimeoutTracker.getInstance().getTimeoutInfo(this.getClass().getName());
+ return timeoutInfo.isResourcesInjected();
+ }
+
+ @Override
+ public boolean wasTxAvailableDuringTimeout()
+ {
+ TimeoutInfo timeoutInfo = TimeoutTracker.getInstance().getTimeoutInfo(this.getClass().getName());
+ return timeoutInfo.isTransactional();
+ }
+}
Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/SimpleSLSBWithTimeout.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/SimpleSLSBWithTimeout.java (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/SimpleSLSBWithTimeout.java 2010-06-29 16:52:24 UTC (rev 106313)
@@ -0,0 +1,121 @@
+/*
+ * 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.test.ejbthree2125;
+
+import java.util.Date;
+
+import javax.annotation.Resource;
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+import javax.ejb.Timeout;
+import javax.ejb.Timer;
+import javax.ejb.TimerService;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+import org.jboss.ejb3.annotation.RemoteBinding;
+import org.jboss.logging.Logger;
+
+/**
+ * SimpleSLSBWithTimeout
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ at Stateless
+ at Remote (TimerUtil.class)
+ at RemoteBinding (jndiBinding = SimpleSLSBWithTimeout.JNDI_NAME)
+public class SimpleSLSBWithTimeout implements TimerUtil
+{
+
+ public static final String JNDI_NAME = "ejbthree-2125-slsbean";
+
+ private static Logger logger = Logger.getLogger(SimpleSLSBWithTimeout.class);
+
+ @Resource
+ private TimerService timerService;
+
+ @PersistenceContext
+ private EntityManager em;
+
+ @Override
+ public void createTimer(Date initialExpiry, int interval)
+ {
+ this.timerService.createTimer(initialExpiry, interval, this.getClass().getName());
+ logger.info("Timer created to fire at: " + initialExpiry);
+ }
+
+ @Timeout
+ private void privateAccessOnTimeoutMethod(Timer timer)
+ {
+ logger.info("private timeout method invoked at: " + new Date());
+
+ TimeoutInfo timeoutInfo = new TimeoutInfo();
+ TimeoutTracker.getInstance().trackTimeout(timer, timeoutInfo);
+
+ this.checkInjectedResource(timeoutInfo);
+ this.checkTxAccess(timeoutInfo);
+ }
+
+ private void checkInjectedResource(TimeoutInfo timeoutInfo)
+ {
+ logger.info("Timerservice: " + this.timerService);
+ // just access the injected resources and do any tx related work
+ if (this.timerService != null)
+ {
+ timeoutInfo.setResourcesInjected(true);
+ }
+ else
+ {
+ timeoutInfo.setResourcesInjected(false);
+ }
+ }
+
+ private void checkTxAccess(TimeoutInfo timeoutInfo)
+ {
+ logger.info("Entitymanager: " + this.em);
+ DummyEntity dummyEntity = new DummyEntity();
+ dummyEntity.setName("EJBTHREE-2125");
+ this.em.persist(dummyEntity);
+ this.em.flush();
+ // success (i.e. entity manager did not throw a tx related exception)
+ timeoutInfo.setTransactional(true);
+ }
+
+ @Override
+ public boolean wasTimeoutInvoked()
+ {
+ return TimeoutTracker.getInstance().getTimeoutInfo(this.getClass().getName()) != null;
+ }
+
+ public boolean wasResourceInjectedDuringTimeout()
+ {
+ TimeoutInfo timeoutInfo = TimeoutTracker.getInstance().getTimeoutInfo(this.getClass().getName());
+ return timeoutInfo.isResourcesInjected();
+ }
+
+ public boolean wasTxAvailableDuringTimeout()
+ {
+ TimeoutInfo timeoutInfo = TimeoutTracker.getInstance().getTimeoutInfo(this.getClass().getName());
+ return timeoutInfo.isTransactional();
+ }
+}
Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/TimeoutInfo.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/TimeoutInfo.java (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/TimeoutInfo.java 2010-06-29 16:52:24 UTC (rev 106313)
@@ -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.test.ejbthree2125;
+
+/**
+ * TimeoutInfo
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class TimeoutInfo
+{
+
+ private boolean resourcesInjected;
+
+ private boolean transactional;
+
+ public boolean isResourcesInjected()
+ {
+ return resourcesInjected;
+ }
+
+ public void setResourcesInjected(boolean resourcesInjected)
+ {
+ this.resourcesInjected = resourcesInjected;
+ }
+
+ public boolean isTransactional()
+ {
+ return transactional;
+ }
+
+ public void setTransactional(boolean transactional)
+ {
+ this.transactional = transactional;
+ }
+
+
+}
Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/TimeoutTracker.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/TimeoutTracker.java (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/TimeoutTracker.java 2010-06-29 16:52:24 UTC (rev 106313)
@@ -0,0 +1,66 @@
+/*
+ * 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.test.ejbthree2125;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.ejb.Timer;
+
+/**
+ * TimeoutTracker
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class TimeoutTracker
+{
+
+ private static TimeoutTracker instance;
+
+ private Map<String, TimeoutInfo> timedoutBeans = new HashMap<String, TimeoutInfo>();
+
+ public static synchronized TimeoutTracker getInstance()
+ {
+ if (instance == null)
+ {
+ instance = new TimeoutTracker();
+ }
+ return instance;
+ }
+
+ public void trackTimeout(Timer timer, TimeoutInfo timeoutInfo)
+ {
+ String beanName = (String) timer.getInfo();
+ this.timedoutBeans.put(beanName, timeoutInfo);
+ }
+
+
+
+ public TimeoutInfo getTimeoutInfo(String fullyQualifiedBeanClassName)
+ {
+ return this.timedoutBeans.get(fullyQualifiedBeanClassName);
+ }
+
+
+}
Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/TimerUtil.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/TimerUtil.java (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/TimerUtil.java 2010-06-29 16:52:24 UTC (rev 106313)
@@ -0,0 +1,43 @@
+/*
+ * 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.test.ejbthree2125;
+
+import java.util.Date;
+
+/**
+ * TimerUtil
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public interface TimerUtil
+{
+
+ void createTimer(Date initialExpiry, int interval);
+
+ boolean wasTimeoutInvoked();
+
+ boolean wasResourceInjectedDuringTimeout();
+
+ boolean wasTxAvailableDuringTimeout();
+
+}
Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/unit/NonPublicTimeoutMethodTestCase.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/unit/NonPublicTimeoutMethodTestCase.java (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2125/unit/NonPublicTimeoutMethodTestCase.java 2010-06-29 16:52:24 UTC (rev 106313)
@@ -0,0 +1,157 @@
+/*
+ * 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.test.ejbthree2125.unit;
+
+import java.util.Date;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+
+import org.jboss.ejb3.test.common.EJB3TestCase;
+import org.jboss.ejb3.test.ejbthree2125.MDBTimerUtil;
+import org.jboss.ejb3.test.ejbthree2125.MDBTimerUtilImpl;
+import org.jboss.ejb3.test.ejbthree2125.MDBWithPrivateTimeoutMethod;
+import org.jboss.ejb3.test.ejbthree2125.SLSBWithTimeoutMethodInBaseClass;
+import org.jboss.ejb3.test.ejbthree2125.SimpleSLSBWithTimeout;
+import org.jboss.ejb3.test.ejbthree2125.TimerUtil;
+import org.jboss.logging.Logger;
+
+/**
+ * @see EJBTHREE-2125
+ *
+ * Tests to check that timeout methods which have private, protected, package access are invoked
+ * successfully on timeout. Additionally, transaction and resource injection availability is also checked
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class NonPublicTimeoutMethodTestCase extends EJB3TestCase
+{
+
+ private static Logger logger = Logger.getLogger(NonPublicTimeoutMethodTestCase.class);
+
+ public NonPublicTimeoutMethodTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite() throws Exception
+ {
+
+ return new TestSetup(getDeploySetup(NonPublicTimeoutMethodTestCase.class, "ejbthree2125.jar"))
+ {
+ @Override
+ protected void setUp() throws Exception
+ {
+ deployQueue("ejbthree2125");
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ undeployQueue("ejbthree2125");
+ }
+ };
+ }
+
+ /**
+ * Test that a private timeout method on SLSB is invoked correctly and has access to tx and
+ * resource injection.
+ * @throws Exception
+ */
+ public void testPrivateTimeoutMethodOnSLSB() throws Exception
+ {
+ Context ctx = new InitialContext();
+ TimerUtil slsbWithPrivateTimeoutMethod = (TimerUtil) ctx.lookup(SimpleSLSBWithTimeout.JNDI_NAME);
+ Date twoSecondsFromNow = new Date(System.currentTimeMillis() + 2000);
+ slsbWithPrivateTimeoutMethod.createTimer(twoSecondsFromNow, 0);
+ // wait a few seconds for timeout to fire
+ logger.info("Sleeping for 3 seconds, waiting for timeout to happen on bean: "
+ + SimpleSLSBWithTimeout.class.getSimpleName());
+ Thread.sleep(3000);
+ logger.info("Awake now");
+ // check timeout method invocation
+ assertTrue("(private) timeout method was not invoked on bean", slsbWithPrivateTimeoutMethod.wasTimeoutInvoked());
+ // check injection during invocation of timeout method
+ assertTrue("Resource not injected during call to (private) timeout method on bean", slsbWithPrivateTimeoutMethod
+ .wasResourceInjectedDuringTimeout());
+ assertTrue("Transaction was not available during (private) timeout method invocation on bean",
+ slsbWithPrivateTimeoutMethod.wasTxAvailableDuringTimeout());
+
+ }
+
+ /**
+ * Test that a protected timeout method on SLSB is invoked correctly and has access to tx and
+ * resource injection.
+ * @throws Exception
+ */
+ public void testProtectedTimeoutMethodOnSLSB() throws Exception
+ {
+ Context ctx = new InitialContext();
+ TimerUtil slsbWithTimeoutMethodInBaseClass = (TimerUtil) ctx.lookup(SLSBWithTimeoutMethodInBaseClass.JNDI_NAME);
+ Date twoSecondsFromNow = new Date(System.currentTimeMillis() + 2000);
+ slsbWithTimeoutMethodInBaseClass.createTimer(twoSecondsFromNow, 0);
+ // wait a few seconds for timeout to fire
+ logger.info("Sleeping for 3 seconds, waiting for timeout to happen on bean: "
+ + SLSBWithTimeoutMethodInBaseClass.class.getSimpleName());
+ Thread.sleep(3000);
+ logger.info("Awake now");
+ // check timeout method invocation
+ assertTrue("(private) timeout method was not invoked on bean", slsbWithTimeoutMethodInBaseClass
+ .wasTimeoutInvoked());
+ // check injection during invocation of timeout method
+ assertTrue("Resource not injected during call to (private) timeout method on bean",
+ slsbWithTimeoutMethodInBaseClass.wasResourceInjectedDuringTimeout());
+ assertTrue("Transaction was not available during (private) timeout method invocation on bean",
+ slsbWithTimeoutMethodInBaseClass.wasTxAvailableDuringTimeout());
+
+ }
+
+ /**
+ *
+ * @throws Exception
+ */
+ public void testPrivateTimeoutMethodOnMDB() throws Exception
+ {
+ Context ctx = new InitialContext();
+ MDBTimerUtil slsb = (MDBTimerUtil) ctx.lookup(MDBTimerUtilImpl.JNDI_NAME);
+ // let the slsb send a JMS message and then the MDB pick it up to create a timer
+ slsb.sendMessageForTimerCreation();
+ // wait a few seconds for the JMS message to be sent, then the MDB invoked, then the timer created and finally
+ // the timeout to fire
+ logger.info("Sleeping for 4 seconds, waiting for timeout to happen on bean: "
+ + MDBWithPrivateTimeoutMethod.class.getSimpleName());
+ Thread.sleep(4000);
+ logger.info("Awake now");
+ // check timeout method invocation
+ assertTrue("(private) timeout method was not invoked on bean: "
+ + MDBWithPrivateTimeoutMethod.class.getSimpleName(), slsb.wasTimeoutInvoked());
+ // check injection during invocation of timeout method
+ assertTrue("Resource not injected during call to (private) timeout method on bean: "
+ + MDBWithPrivateTimeoutMethod.class.getSimpleName(), slsb.wasResourceInjectedDuringTimeout());
+ assertTrue("Transaction was not available during (private) timeout method invocation on bean: "
+ + MDBWithPrivateTimeoutMethod.class.getSimpleName(), slsb.wasTxAvailableDuringTimeout());
+ }
+
+}
Added: projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree2125/META-INF/persistence.xml
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree2125/META-INF/persistence.xml (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree2125/META-INF/persistence.xml 2010-06-29 16:52:24 UTC (rev 106313)
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence xmlns="http://java.sun.com/xml/ns/persistence"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
+ http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
+ version="1.0">
+ <persistence-unit name="ejbthree-2125-tempdb">
+ <jta-data-source>java:/DefaultDS</jta-data-source>
+ <properties>
+ <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
+ </properties>
+ </persistence-unit>
+</persistence>
More information about the jboss-cvs-commits
mailing list