[jboss-cvs] JBossAS SVN: r64393 - in branches/JBoss_4_0_3_SP1_CP/testsuite: src/main/org/jboss/test/timer/ejb and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jul 31 21:52:37 EDT 2007
Author: jhowell at redhat.com
Date: 2007-07-31 21:52:36 -0400 (Tue, 31 Jul 2007)
New Revision: 64393
Added:
branches/JBoss_4_0_3_SP1_CP/testsuite/src/main/org/jboss/test/timer/ejb/TimerTestBean.java
branches/JBoss_4_0_3_SP1_CP/testsuite/src/main/org/jboss/test/timer/interfaces/TimerTest.java
branches/JBoss_4_0_3_SP1_CP/testsuite/src/main/org/jboss/test/timer/interfaces/TimerTestHome.java
branches/JBoss_4_0_3_SP1_CP/testsuite/src/main/org/jboss/test/timer/test/CancelTimerUnitTestCase.java
branches/JBoss_4_0_3_SP1_CP/testsuite/src/resources/timer/jbas4201/
branches/JBoss_4_0_3_SP1_CP/testsuite/src/resources/timer/jbas4201/ejb-jar.xml
branches/JBoss_4_0_3_SP1_CP/testsuite/src/resources/timer/jbas4201/jboss.xml
Modified:
branches/JBoss_4_0_3_SP1_CP/testsuite/imports/test-jars.xml
Log:
[ASPATCH-249] ported tests over to test the functionality for the timer cancels.
Modified: branches/JBoss_4_0_3_SP1_CP/testsuite/imports/test-jars.xml
===================================================================
--- branches/JBoss_4_0_3_SP1_CP/testsuite/imports/test-jars.xml 2007-08-01 01:50:15 UTC (rev 64392)
+++ branches/JBoss_4_0_3_SP1_CP/testsuite/imports/test-jars.xml 2007-08-01 01:52:36 UTC (rev 64393)
@@ -4724,6 +4724,16 @@
<include name="ejb-timer.war"/>
</zipfileset>
</zip>
+ <!-- build jbas4201.jar -->
+ <zip destfile="${build.lib}/jbas4201.jar">
+ <fileset dir="${build.classes}">
+ <include name="org/jboss/test/timer/ejb/TimerTestBean.class"/>
+ <include name="org/jboss/test/timer/interfaces/TimerTest*"/>
+ </fileset>
+ <zipfileset dir="${build.resources}/timer/jbas4201" prefix="META-INF">
+ <include name="*.xml"/>
+ </zipfileset>
+ </zip>
</target>
<!-- transaction test -->
Added: branches/JBoss_4_0_3_SP1_CP/testsuite/src/main/org/jboss/test/timer/ejb/TimerTestBean.java
===================================================================
--- branches/JBoss_4_0_3_SP1_CP/testsuite/src/main/org/jboss/test/timer/ejb/TimerTestBean.java (rev 0)
+++ branches/JBoss_4_0_3_SP1_CP/testsuite/src/main/org/jboss/test/timer/ejb/TimerTestBean.java 2007-08-01 01:52:36 UTC (rev 64393)
@@ -0,0 +1,252 @@
+package org.jboss.test.timer.ejb;
+
+/**
+ * @Package: com.scap.servers.scapserver.ejb
+ * @CreateDate Apr 15, 2005
+ * @Creator eha
+ *
+ * TODO Add more info
+ */
+
+import java.io.Serializable;
+import java.rmi.RemoteException;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.logging.Logger;
+
+import javax.ejb.CreateException;
+import javax.ejb.EJBException;
+import javax.ejb.SessionBean;
+import javax.ejb.SessionContext;
+import javax.ejb.TimedObject;
+import javax.ejb.Timer;
+
+/**
+ * XDoclet-based session bean. The class must be declared
+ * public according to the EJB specification.
+ *
+ * To generate the EJB related files to this EJB:
+ * - Add Standard EJB module to XDoclet project properties
+ * - Customize XDoclet configuration for your appserver
+ * - Run XDoclet
+ *
+ * Below are the xdoclet-related tags needed for this EJB.
+ *
+ * @ejb.bean name="TimerTest"
+ * display-name="Name for TimerTest"
+ * description="Description for TimerTest"
+ * jndi-name="ejb/TimerTest"
+ * type="Stateless"
+ * view-type="both"
+ *
+ * @ejb.transaction type = "NotSupported"
+ */
+public class TimerTestBean implements SessionBean, TimedObject
+{
+
+ /** The session context */
+ private SessionContext m_context;
+ private Logger m_log = Logger.getLogger(TimerTestBean.class.getName());
+
+ /**
+ *
+ */
+ public TimerTestBean()
+ {
+ super();
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * Set the associated session context. The container calls this method
+ * after the instance creation.
+ *
+ * The enterprise bean instance should store the reference to the context
+ * object in an instance variable.
+ *
+ * This method is called with no transaction context.
+ *
+ * @throws EJBException Thrown if method fails due to system-level error.
+ */
+ public void setSessionContext(SessionContext newContext) throws EJBException
+ {
+ m_context = newContext;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.ejb.SessionBean#ejbRemove()
+ */
+ public void ejbRemove() throws EJBException, RemoteException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.ejb.SessionBean#ejbActivate()
+ */
+ public void ejbActivate() throws EJBException, RemoteException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.ejb.SessionBean#ejbPassivate()
+ */
+ public void ejbPassivate() throws EJBException, RemoteException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * An ejbCreate method as required by the EJB specification.
+ *
+ * The container calls the instance?s <code>ejbCreate</code> method whose
+ * signature matches the signature of the <code>create</code> method invoked
+ * by the client. The input parameters sent from the client are passed to
+ * the <code>ejbCreate</code> method. Each session bean class must have at
+ * least one <code>ejbCreate</code> method. The number and signatures
+ * of a session bean?s <code>create</code> methods are specific to each
+ * session bean class.
+ *
+ * @throws CreateException Thrown if method fails due to system-level error.
+ *
+ * @ejb.create-method
+ *
+ */
+ public void ejbCreate() throws CreateException
+ {
+ // TODO Add ejbCreate method implementation
+ }
+
+ private void startTimer(Serializable info)
+ {
+ m_log.info("Starting timer. Info="+info);
+ m_context.getTimerService().createTimer(10000,info);
+ }
+
+ /**
+ * @ejb.interface-method
+ * @ejb.transaction type = "Required"
+ * @throws EJBException Thrown if method fails due to system-level error.
+ */
+ public void startTimerInTxRequired() throws EJBException
+ {
+ startTimer("Required");
+ }
+
+ /**
+ * @ejb.interface-method
+ * @ejb.transaction type = "RequiresNew"
+ * @throws EJBException Thrown if method fails due to system-level error.
+ */
+ public void startTimerInTxRequiresNew() throws EJBException
+ {
+ startTimer("Required");
+ }
+ /**
+ * @ejb.interface-method
+ * @ejb.transaction type = "Never"
+ * @throws EJBException Thrown if method fails due to system-level error.
+ */
+ public void startTimerInTxNever() throws EJBException
+ {
+ startTimer("Never");
+ }
+
+ /**
+ * @ejb.interface-method
+ * @ejb.transaction type = "NotSupported"
+ * @throws EJBException Thrown if method fails due to system-level error.
+ */
+ public void startTimerInTxNotSupported() throws EJBException
+ {
+ startTimer("NotSupported");
+ }
+
+ private void cancelTimers()
+ {
+ Collection timers = m_context.getTimerService().getTimers();
+ for (Iterator it = timers.iterator();it.hasNext();)
+ {
+ Timer t = (Timer)it.next();
+ m_log.info("Cancelling timer"+t+" "+t.getInfo());
+ t.cancel();
+ m_log.info("Timer is now"+t);
+ }
+ }
+
+ /**
+ * @ejb.interface-method
+ */
+ public int listAllTimers()
+ {
+ Collection timers = m_context.getTimerService().getTimers();
+ String s="Timers:";
+ for (Iterator it = timers.iterator();it.hasNext();)
+ {
+ Timer t = (Timer)it.next();
+ s = s +t.toString() + " ";
+ try
+ {
+ s += t.getInfo();
+ }
+ catch (Exception e)
+ {
+
+ }
+ s+="\n";
+ }
+ m_log.info(s);
+ return timers.size();
+ }
+ /**
+ * @ejb.interface-method
+ * @ejb.transaction type = "Required"
+ * @throws EJBException Thrown if method fails due to system-level error.
+ */
+ public void cancelTimerInTxRequired() throws EJBException
+ {
+ cancelTimers();
+ }
+
+ /**
+ * @ejb.interface-method
+ * @ejb.transaction type = "RequiresNew"
+ * @throws EJBException Thrown if method fails due to system-level error.
+ */
+ public void cancelTimerInTxRequiresNew() throws EJBException
+ {
+ cancelTimers();
+ }
+ /**
+ * @ejb.interface-method
+ * @ejb.transaction type = "Never"
+ * @throws EJBException Thrown if method fails due to system-level error.
+ */
+ public void cancelTimerInTxNever() throws EJBException
+ {
+ cancelTimers();
+ }
+
+ /**
+ * @ejb.interface-method
+ * @ejb.transaction type = "NotSupported"
+ * @throws EJBException Thrown if method fails due to system-level error.
+ */
+ public void cancelTimerInTxNotSupported() throws EJBException
+ {
+ cancelTimers();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.ejb.TimedObject#ejbTimeout(javax.ejb.Timer)
+ */
+ public void ejbTimeout(Timer timer)
+ {
+ m_log.info("ejbTimeout:"+timer);
+ }
+
+}
Property changes on: branches/JBoss_4_0_3_SP1_CP/testsuite/src/main/org/jboss/test/timer/ejb/TimerTestBean.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/JBoss_4_0_3_SP1_CP/testsuite/src/main/org/jboss/test/timer/interfaces/TimerTest.java
===================================================================
--- branches/JBoss_4_0_3_SP1_CP/testsuite/src/main/org/jboss/test/timer/interfaces/TimerTest.java (rev 0)
+++ branches/JBoss_4_0_3_SP1_CP/testsuite/src/main/org/jboss/test/timer/interfaces/TimerTest.java 2007-08-01 01:52:36 UTC (rev 64393)
@@ -0,0 +1,26 @@
+package org.jboss.test.timer.interfaces;
+
+import java.rmi.RemoteException;
+import javax.ejb.EJBObject;
+
+public interface TimerTest extends EJBObject
+{
+ public int listAllTimers() throws RemoteException;
+
+ public void startTimerInTxRequired() throws RemoteException;
+
+ public void startTimerInTxRequiresNew() throws RemoteException;
+
+ public void startTimerInTxNotSupported() throws RemoteException;
+
+ public void startTimerInTxNever() throws RemoteException;
+
+ public void cancelTimerInTxRequired() throws RemoteException;
+
+ public void cancelTimerInTxRequiresNew() throws RemoteException;
+
+ public void cancelTimerInTxNotSupported() throws RemoteException;
+
+ public void cancelTimerInTxNever() throws RemoteException;
+
+}
Property changes on: branches/JBoss_4_0_3_SP1_CP/testsuite/src/main/org/jboss/test/timer/interfaces/TimerTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/JBoss_4_0_3_SP1_CP/testsuite/src/main/org/jboss/test/timer/interfaces/TimerTestHome.java
===================================================================
--- branches/JBoss_4_0_3_SP1_CP/testsuite/src/main/org/jboss/test/timer/interfaces/TimerTestHome.java (rev 0)
+++ branches/JBoss_4_0_3_SP1_CP/testsuite/src/main/org/jboss/test/timer/interfaces/TimerTestHome.java 2007-08-01 01:52:36 UTC (rev 64393)
@@ -0,0 +1,11 @@
+package org.jboss.test.timer.interfaces;
+
+import java.rmi.RemoteException;
+
+import javax.ejb.CreateException;
+import javax.ejb.EJBHome;
+
+public interface TimerTestHome extends EJBHome
+{
+ TimerTest create() throws CreateException, RemoteException;
+}
Property changes on: branches/JBoss_4_0_3_SP1_CP/testsuite/src/main/org/jboss/test/timer/interfaces/TimerTestHome.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/JBoss_4_0_3_SP1_CP/testsuite/src/main/org/jboss/test/timer/test/CancelTimerUnitTestCase.java
===================================================================
--- branches/JBoss_4_0_3_SP1_CP/testsuite/src/main/org/jboss/test/timer/test/CancelTimerUnitTestCase.java (rev 0)
+++ branches/JBoss_4_0_3_SP1_CP/testsuite/src/main/org/jboss/test/timer/test/CancelTimerUnitTestCase.java 2007-08-01 01:52:36 UTC (rev 64393)
@@ -0,0 +1,160 @@
+package org.jboss.test.timer.test;
+
+/**
+ * @Package: com.scap.servers.scapserver.ejb
+ * @CreateDate Apr 15, 2005
+ * @Creator eha
+ *
+ * TODO Add more info
+ */
+
+import java.rmi.RemoteException;
+
+import javax.naming.Context;
+import javax.rmi.PortableRemoteObject;
+
+import org.jboss.test.JBossTestCase;
+import org.jboss.test.timer.interfaces.TimerTest;
+import org.jboss.test.timer.interfaces.TimerTestHome;
+
+import junit.framework.Test;
+
+/**
+ * EJB Test Client
+ */
+public class CancelTimerUnitTestCase extends JBossTestCase
+{
+ private static final String EJB_TIMER_XAR = "jbas4201.jar";
+
+ /**
+ * Setup the test suite.
+ */
+ public static Test suite() throws Exception
+ {
+ return JBossTestCase.getDeploySetup(CancelTimerUnitTestCase.class, EJB_TIMER_XAR);
+ }
+
+ /**
+ * @param name
+ */
+ public CancelTimerUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ /** Home interface */
+ protected TimerTestHome home;
+ private static final int REQUIRED = 0;
+ private static final int REQUIRES_NEW = 1;
+ private static final int NOT_SUPPORTED = 2;
+ private static final int NEVER = 3;
+ private static final int FIRST = REQUIRED;
+ private static final int LAST = NEVER;
+ private static final String[] TRANSTYPE =
+ { "Required", "RequiresNew", "NotSupported", "Never" };
+
+ /**
+ * Get the home interface
+ */
+ protected TimerTestHome getHome() throws Exception
+ {
+ Context ctx = this.getInitialContext();
+ Object o = ctx.lookup("ejb/TimerTest");
+ TimerTestHome intf = (TimerTestHome) PortableRemoteObject.narrow(o, TimerTestHome.class);
+ return intf;
+ }
+
+ /**
+ * Set up the test case
+ */
+ protected void setUp() throws Exception
+ {
+ this.home = this.getHome();
+ System.out.println("setting up");
+ }
+
+ private void startTimer(TimerTest instance, int transType) throws RemoteException
+ {
+ int timersBefore = instance.listAllTimers();
+ switch (transType)
+ {
+ case REQUIRED:
+ instance.startTimerInTxRequired();
+ break;
+ case REQUIRES_NEW:
+ instance.startTimerInTxRequiresNew();
+ break;
+ case NOT_SUPPORTED:
+ instance.startTimerInTxNotSupported();
+ break;
+ case NEVER:
+ instance.startTimerInTxNever();
+ break;
+ }
+ int timersAfter = instance.listAllTimers();
+ if (timersAfter != timersBefore + 1)
+ {
+ fail("Did not delete timer!\nBefore:" + timersBefore + "\nAfter:" + timersAfter);
+ }
+ }
+
+ private void cancelTimer(TimerTest instance, int transType)
+ {
+ try
+ {
+ int timersBefore = instance.listAllTimers();
+ switch (transType)
+ {
+ case REQUIRED:
+ instance.cancelTimerInTxRequired();
+ break;
+ case REQUIRES_NEW:
+ instance.cancelTimerInTxRequiresNew();
+ break;
+ case NOT_SUPPORTED:
+ instance.cancelTimerInTxNotSupported();
+ break;
+ case NEVER:
+ instance.cancelTimerInTxNever();
+ break;
+ }
+ int timersAfter = instance.listAllTimers();
+ if (timersBefore != timersAfter + 1)
+ {
+ fail("Did not delete timer!\nBefore:" + timersBefore + "\nAfter:" + timersAfter);
+ }
+ }
+ catch (Exception e)
+ {
+ System.out.println("Failed to cancel timer:" + e);
+ }
+ }
+
+ /**
+ * Test for com.scap.servers.scapserver.interfaces.TimerTest.startTimerInTxRequired()
+ */
+ public void testTimer() throws Exception
+ {
+
+ TimerTest instance;
+
+ // Parameters
+
+ // Instance creation
+ instance = this.home.create();
+
+ for(int run=0;run<5;run++)
+ {
+ for (int start = FIRST; start <= LAST; start++)
+ {
+ for (int cancel = FIRST; cancel <= LAST; cancel++)
+ {
+ log.debug("Run " + run + " start:" + TRANSTYPE[start] + " cancel:" + TRANSTYPE[cancel]);
+ startTimer(instance, start);
+ cancelTimer(instance, cancel);
+ }
+
+ }
+ }
+ }
+}
Property changes on: branches/JBoss_4_0_3_SP1_CP/testsuite/src/main/org/jboss/test/timer/test/CancelTimerUnitTestCase.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/JBoss_4_0_3_SP1_CP/testsuite/src/resources/timer/jbas4201/ejb-jar.xml
===================================================================
--- branches/JBoss_4_0_3_SP1_CP/testsuite/src/resources/timer/jbas4201/ejb-jar.xml (rev 0)
+++ branches/JBoss_4_0_3_SP1_CP/testsuite/src/resources/timer/jbas4201/ejb-jar.xml 2007-08-01 01:52:36 UTC (rev 64393)
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ejb-jar xmlns="http://java.sun.com/xml/ns/j2ee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd" version="2.1">
+ <description>EJB Timer Tests</description>
+ <enterprise-beans>
+ <session>
+ <description>Stateless Session Bean Timer Test</description>
+ <display-name>Timer in Stateless Session Bean</display-name>
+ <ejb-name>TimerTest</ejb-name>
+ <home>org.jboss.test.timer.interfaces.TimerTestHome</home>
+ <remote>org.jboss.test.timer.interfaces.TimerTest</remote>
+ <ejb-class>org.jboss.test.timer.ejb.TimerTestBean</ejb-class>
+ <session-type>Stateless</session-type>
+ <transaction-type>Container</transaction-type>
+ </session>
+ </enterprise-beans>
+
+ <assembly-descriptor>
+ <container-transaction>
+ <method>
+ <ejb-name>TimerTest</ejb-name>
+ <method-name>startTimerInTxRequired</method-name>
+ </method>
+ <method>
+ <ejb-name>TimerTest</ejb-name>
+ <method-name>startTimerInTxRequired</method-name>
+ </method>
+ <trans-attribute>Required</trans-attribute>
+ </container-transaction>
+ <container-transaction>
+ <method>
+ <ejb-name>TimerTest</ejb-name>
+ <method-name>startTimerInTxRequiresNew</method-name>
+ </method>
+ <method>
+ <ejb-name>TimerTest</ejb-name>
+ <method-name>cancelTimerInTxRequiresNew</method-name>
+ </method>
+ <trans-attribute>RequiresNew</trans-attribute>
+ </container-transaction>
+ <container-transaction>
+ <method>
+ <ejb-name>TimerTest</ejb-name>
+ <method-name>startTimerInTxNotSupported</method-name>
+ </method>
+ <method>
+ <ejb-name>TimerTest</ejb-name>
+ <method-name>cancelTimerInTxNotSupported</method-name>
+ </method>
+ <trans-attribute>NotSupported</trans-attribute>
+ </container-transaction>
+ <container-transaction>
+ <method>
+ <ejb-name>TimerTest</ejb-name>
+ <method-name>startTimerInTxNever</method-name>
+ </method>
+ <method>
+ <ejb-name>TimerTest</ejb-name>
+ <method-name>cancelTimerInTxNever</method-name>
+ </method>
+ <trans-attribute>Never</trans-attribute>
+ </container-transaction>
+ </assembly-descriptor>
+</ejb-jar>
Property changes on: branches/JBoss_4_0_3_SP1_CP/testsuite/src/resources/timer/jbas4201/ejb-jar.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/JBoss_4_0_3_SP1_CP/testsuite/src/resources/timer/jbas4201/jboss.xml
===================================================================
--- branches/JBoss_4_0_3_SP1_CP/testsuite/src/resources/timer/jbas4201/jboss.xml (rev 0)
+++ branches/JBoss_4_0_3_SP1_CP/testsuite/src/resources/timer/jbas4201/jboss.xml 2007-08-01 01:52:36 UTC (rev 64393)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE jboss PUBLIC
+ "-//JBoss//DTD JBOSS 4.0//EN"
+ "http://www.jboss.org/j2ee/dtd/jboss_4_0.dtd">
+
+<jboss>
+
+ <enterprise-beans>
+
+ <session>
+ <ejb-name>TimerTest</ejb-name>
+ <jndi-name>ejb/TimerTest</jndi-name>
+ </session>
+
+ </enterprise-beans>
+
+</jboss>
Property changes on: branches/JBoss_4_0_3_SP1_CP/testsuite/src/resources/timer/jbas4201/jboss.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
More information about the jboss-cvs-commits
mailing list