[jboss-cvs] JBossAS SVN: r78745 - in branches/JBPAPP_4_2_0_GA_CP/ejb3: src/test/org/jboss/ejb3/test and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Sep 22 07:05:48 EDT 2008
Author: wolfc
Date: 2008-09-22 07:05:48 -0400 (Mon, 22 Sep 2008)
New Revision: 78745
Added:
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1186/
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1186/AnInterface.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1186/AnInterfaceImpl.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1186/ControlImpl.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1186/ControlInterface.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1186/Register.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1186/unit/
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1186/unit/MultiplePreDestroyUnitTestCase.java
Modified:
branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml
Log:
JBPAPP-1186: unit test
Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml 2008-09-22 08:56:22 UTC (rev 78744)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml 2008-09-22 11:05:48 UTC (rev 78745)
@@ -2097,6 +2097,13 @@
</ear>
</target>
+ <target name="jbpapp1186"
+ description="Builds a simple jar files."
+ depends="compile-classes">
+
+ <build-simple-jar name="jbpapp1186"/>
+ </target>
+
<target name="jaxws"
description="Builds a simple jar."
depends="compile-classes">
@@ -3787,6 +3794,7 @@
ejbthree1109,
ejbthree1239,
jbpapp999,
+ jbpapp1186,
jbas4489, epcpropagation, jaccpropagation,
aspectdomain, ejbcontext, schema, mail, scopedclassloader, dependency, jaxws,
pkg, securitydomain, enventry, externalpersistenceunit,
@@ -4419,6 +4427,9 @@
<antcall target="test" inheritRefs="true">
<param name="test" value="jbpapp999"/>
</antcall>
+ <antcall target="test" inheritRefs="true">
+ <param name="test" value="jbpapp1186"/>
+ </antcall>
</target>
<target name="entity-tests" depends="init" description="Execute all tests">
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1186/AnInterface.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1186/AnInterface.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1186/AnInterface.java 2008-09-22 11:05:48 UTC (rev 78745)
@@ -0,0 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.jbpapp1186;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface AnInterface
+{
+ AnInterface getAnInterface();
+
+ void discard();
+}
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1186/AnInterfaceImpl.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1186/AnInterfaceImpl.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1186/AnInterfaceImpl.java 2008-09-22 11:05:48 UTC (rev 78745)
@@ -0,0 +1,106 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.jbpapp1186;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.ejb.PostActivate;
+import javax.ejb.PrePassivate;
+import javax.ejb.Remote;
+import javax.ejb.Remove;
+import javax.ejb.Stateful;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.apache.log4j.Logger;
+import org.jboss.annotation.ejb.cache.simple.CacheConfig;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Stateful
+ at Remote(AnInterface.class)
+ at CacheConfig(idleTimeoutSeconds = 30, maxSize = 2, removalTimeoutSeconds = 60)
+public class AnInterfaceImpl implements AnInterface
+{
+ private static final Logger log = Logger.getLogger(AnInterfaceImpl.class);
+
+ private Exception destroyed = null;
+
+ protected static int failures = 0;
+
+ @PostActivate
+ public void activate()
+ {
+ log.info("Called activate on " + this);
+ }
+
+ @PostConstruct
+ public void construct()
+ {
+ log.info("Called construct on " + this);
+ }
+
+ @PreDestroy
+ public void destroy()
+ {
+ if(destroyed != null)
+ {
+ log.error("Bean " + this + " was already destroyed here", destroyed);
+ failures++;
+ // Note that it's actually useless to throw an exception from pre destroy
+ // because if it's used in a SessionSynchronization, the TM will ignore it.
+ throw new IllegalStateException("Bean " + this + " was already destroyed");
+ }
+ log.info("Called destroy on " + this);
+ destroyed = new Exception("destroy");
+ }
+
+ @Remove
+ public void discard()
+ {
+ log.info("Called discard on " + this);
+ }
+
+ public AnInterface getAnInterface()
+ {
+ try
+ {
+ InitialContext ctx = new InitialContext();
+ AnInterface intf = (AnInterface) ctx.lookup("AnInterfaceImpl/remote");
+ Register.register(intf);
+ return intf;
+ }
+ catch (NamingException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @PrePassivate
+ public void passivate()
+ {
+ log.info("Called passivate on " + this);
+ }
+
+}
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1186/ControlImpl.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1186/ControlImpl.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1186/ControlImpl.java 2008-09-22 11:05:48 UTC (rev 78745)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.jbpapp1186;
+
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Stateless
+ at Remote(ControlInterface.class)
+public class ControlImpl implements ControlInterface
+{
+
+ public int count()
+ {
+ return Register.all.size();
+ }
+
+ public void clearAll()
+ {
+ Register.clear();
+ }
+
+ public AnInterface initialInterface()
+ {
+ try
+ {
+ InitialContext ctx = new InitialContext();
+ AnInterface intImpl = (AnInterface) ctx.lookup("AnInterfaceImpl/remote");
+ Register.register(intImpl);
+ return intImpl;
+ }
+ catch (NamingException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void discardAll()
+ {
+ Register.removeAll();
+ }
+
+ public int failures()
+ {
+ return AnInterfaceImpl.failures;
+ }
+
+ public void resetFailures()
+ {
+ AnInterfaceImpl.failures = 0;
+ }
+}
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1186/ControlInterface.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1186/ControlInterface.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1186/ControlInterface.java 2008-09-22 11:05:48 UTC (rev 78745)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.jbpapp1186;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface ControlInterface
+{
+ AnInterface initialInterface();
+
+ int count();
+
+ void discardAll();
+
+ void clearAll();
+
+ int failures();
+
+ void resetFailures();
+}
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1186/Register.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1186/Register.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1186/Register.java 2008-09-22 11:05:48 UTC (rev 78745)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.jbpapp1186;
+
+import java.util.ArrayList;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class Register
+{
+ public static ArrayList<AnInterface> all = new ArrayList<AnInterface>();
+
+ public static void register(AnInterface besta)
+ {
+ all.add(besta);
+ }
+
+ public static void removeAll()
+ {
+ for (AnInterface cada : all)
+ {
+ cada.discard();
+ }
+ }
+
+ public static void clear()
+ {
+ all.clear();
+ }
+}
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1186/unit/MultiplePreDestroyUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1186/unit/MultiplePreDestroyUnitTestCase.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1186/unit/MultiplePreDestroyUnitTestCase.java 2008-09-22 11:05:48 UTC (rev 78745)
@@ -0,0 +1,86 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.jbpapp1186.unit;
+
+import javax.naming.NamingException;
+
+import junit.framework.Test;
+
+import org.jboss.ejb3.test.jbpapp1186.AnInterface;
+import org.jboss.ejb3.test.jbpapp1186.ControlInterface;
+import org.jboss.test.JBossTestCase;
+
+/**
+ * Calling a remove method withing a transaction must not result
+ * in multiple pre-destroy calls.
+ *
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class MultiplePreDestroyUnitTestCase extends JBossTestCase
+{
+ private ControlInterface control;
+
+ public MultiplePreDestroyUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void test1() throws NamingException
+ {
+ assertEquals(0, control.count());
+ AnInterface intf1 = control.initialInterface();
+ intf1.getAnInterface();
+ assertEquals(2, control.count());
+ control.discardAll();
+ control.clearAll();
+
+ assertEquals(0, control.failures());
+ }
+
+ public void test2()
+ {
+ assertEquals(0, control.count());
+ AnInterface intf1 = control.initialInterface();
+ AnInterface intf2 = intf1.getAnInterface();
+ assertEquals(2, control.count());
+ intf1.discard();
+ intf2.discard();
+ control.clearAll();
+
+ assertEquals(0, control.failures());
+ }
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ control = (ControlInterface) getInitialContext().lookup("ControlImpl/remote");
+ control.resetFailures();
+ }
+
+ public static Test suite() throws Exception
+ {
+ return getDeploySetup(MultiplePreDestroyUnitTestCase.class, "jbpapp1186.jar");
+ }
+}
More information about the jboss-cvs-commits
mailing list