[jboss-cvs] JBossAS SVN: r71786 - in trunk/testsuite: src/main/org/jboss/test/jca/ejb and 6 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Apr 8 06:52:04 EDT 2008
Author: adrian at jboss.org
Date: 2008-04-08 06:52:04 -0400 (Tue, 08 Apr 2008)
New Revision: 71786
Added:
trunk/testsuite/src/main/org/jboss/test/jca/ejb/TransactionActiveBean.java
trunk/testsuite/src/main/org/jboss/test/jca/interfaces/TransactionActiveHome.java
trunk/testsuite/src/main/org/jboss/test/jca/interfaces/TransactionActiveRemote.java
trunk/testsuite/src/main/org/jboss/test/jca/test/ExecuteJMSDuringRollbackStressTestCase.java
trunk/testsuite/src/main/org/jboss/test/jca/test/ExecuteSQLDuringRollbackStressTestCase.java
trunk/testsuite/src/main/org/jboss/test/jca/test/TransactionActiveUnitTestCase.java
trunk/testsuite/src/resources/jca/executejmsrollback/
trunk/testsuite/src/resources/jca/executejmsrollback/test-jms-local-ds.xml
trunk/testsuite/src/resources/jca/txactive/
trunk/testsuite/src/resources/jca/txactive/META-INF/
trunk/testsuite/src/resources/jca/txactive/META-INF/ejb-jar.xml
trunk/testsuite/src/resources/jca/txactive/META-INF/jboss.xml
Modified:
trunk/testsuite/imports/sections/jca.xml
Log:
[JBAS-5278] - Port tests from jboss-4.2
Modified: trunk/testsuite/imports/sections/jca.xml
===================================================================
--- trunk/testsuite/imports/sections/jca.xml 2008-04-08 10:00:24 UTC (rev 71785)
+++ trunk/testsuite/imports/sections/jca.xml 2008-04-08 10:52:04 UTC (rev 71786)
@@ -221,6 +221,44 @@
</jar>
+ <jar destfile="${build.lib}/jca-txactive-ejb.jar">
+ <fileset dir="${build.classes}">
+ <include name="org/jboss/test/jca/interfaces/TransactionActive*"/>
+ </fileset>
+ <fileset dir="${build.classes}">
+ <include name="org/jboss/test/jca/ejb/TransactionActive*"/>
+ </fileset>
+ <fileset dir="${build.resources}/jca/txactive">
+ <include name="**/*.xml"/>
+ </fileset>
+ <fileset dir="${build.resources}/messaging">
+ <include name="test-destinations-service.xml"/>
+ </fileset>
+ </jar>
+
+ <jar destfile="${build.lib}/jcaexecutejmsrollback.jar">
+ <fileset dir="${build.classes}">
+ <patternset refid="common.test.client.classes"/>
+ <include name="org/jboss/test/jca/test/ExecuteJMS*"/>
+ <include name="org/jboss/test/util/ejb/*"/>
+ </fileset>
+ <fileset dir="${build.resources}/jca/test">
+ <include name="**/*.*"/>
+ </fileset>
+ <fileset dir="${build.resources}/messaging">
+ <include name="test-destinations-service.xml"/>
+ </fileset>
+ <fileset dir="${build.resources}/jca/executejmsrollback">
+ <include name="**/*.*"/>
+ </fileset>
+ <zipfileset src="${junit.junit.lib}/junit.jar">
+ <patternset refid="ejbrunner.set"/>
+ </zipfileset>
+ <zipfileset src="${jboss.test.lib}/jboss-test.jar">
+ <patternset refid="jboss.test.set"/>
+ </zipfileset>
+ </jar>
+
<jar destfile="${build.lib}/jca-tests.jar">
<fileset dir="${build.classes}">
<patternset refid="common.test.client.classes"/>
Added: trunk/testsuite/src/main/org/jboss/test/jca/ejb/TransactionActiveBean.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/jca/ejb/TransactionActiveBean.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/jca/ejb/TransactionActiveBean.java 2008-04-08 10:52:04 UTC (rev 71786)
@@ -0,0 +1,423 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.jca.ejb;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import javax.ejb.SessionBean;
+import javax.ejb.SessionContext;
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.naming.InitialContext;
+import javax.sql.DataSource;
+import javax.transaction.UserTransaction;
+
+import org.jboss.logging.Logger;
+
+/**
+ * TransactionActiveBean.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TransactionActiveBean implements SessionBean
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 1L;
+ private SessionContext sessionCtx;
+ private static final Logger log = Logger.getLogger(TransactionActiveBean.class);
+
+ public void setupDatabase()
+ {
+ try
+ {
+ InitialContext ctx = new InitialContext();
+ DataSource ds = (DataSource) ctx.lookup("java:DefaultDS");
+ Connection c = ds.getConnection();
+ try
+ {
+ Statement stmt = c.createStatement();
+ try
+ {
+ stmt.executeUpdate("create table JCA_TRANSACTION_ACTIVE (name varchar(100))");
+ }
+ catch (SQLException ignored)
+ {
+ }
+ stmt.executeUpdate("delete from JCA_TRANSACTION_ACTIVE");
+ stmt.executeUpdate("insert into JCA_TRANSACTION_ACTIVE values ('100')");
+ }
+ finally
+ {
+ c.close();
+ }
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Unexpected Error: ", e);
+ }
+ }
+
+ public void changeDatabase()
+ {
+ try
+ {
+ InitialContext ctx = new InitialContext();
+ UserTransaction ut = sessionCtx.getUserTransaction();
+ ut.setTransactionTimeout(5);
+ ut.begin();
+ try
+ {
+ DataSource ds = (DataSource) ctx.lookup("java:DefaultDS");
+ Connection c = ds.getConnection();
+ try
+ {
+ Statement stmt = c.createStatement();
+ stmt.executeUpdate("insert into JCA_TRANSACTION_ACTIVE values ('101')");
+ try
+ {
+ Thread.sleep(10000);
+ }
+ catch (InterruptedException ignored)
+ {
+ }
+ try
+ {
+ stmt.executeUpdate("delete from JCA_TRANSACTION_ACTIVE where name='100'");
+ }
+ catch (SQLException expected)
+ {
+ log.debug("Got expected exception: " + expected);
+ }
+ }
+ finally
+ {
+ try
+ {
+ c.close();
+ }
+ catch (Exception ignored)
+ {
+ }
+ }
+ }
+ finally
+ {
+ try
+ {
+ ut.rollback();
+ }
+ catch (Exception ignored)
+ {
+ }
+ }
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Unexpected Error: ", e);
+ }
+ }
+
+ public void checkDatabase()
+ {
+ try
+ {
+ InitialContext ctx = new InitialContext();
+ UserTransaction ut = sessionCtx.getUserTransaction();
+ ut.begin();
+ try
+ {
+ DataSource ds = (DataSource) ctx.lookup("java:DefaultDS");
+ Connection c = ds.getConnection();
+ try
+ {
+ Statement stmt = c.createStatement();
+ ResultSet rs = stmt.executeQuery("select name from JCA_TRANSACTION_ACTIVE");
+ if (rs.next() == false)
+ throw new RuntimeException("Expected a first row");
+ String value = rs.getString(1);
+ if ("100".equals(value) == false)
+ throw new RuntimeException("Expected first row to be 100 got " + value);
+ if (rs.next())
+ throw new RuntimeException("Expected only one row");
+ }
+ finally
+ {
+ try
+ {
+ c.close();
+ }
+ catch (Exception ignored)
+ {
+ }
+ }
+ }
+ finally
+ {
+ try
+ {
+ ut.commit();
+ }
+ catch (Exception ignored)
+ {
+ }
+ }
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Unexpected Error: ", e);
+ }
+ }
+
+ public void setupQueue()
+ {
+ try
+ {
+ InitialContext ctx = new InitialContext();
+ Queue queue = (Queue) ctx.lookup("queue/testQueue");
+ UserTransaction ut = sessionCtx.getUserTransaction();
+ ut.begin();
+ try
+ {
+ ConnectionFactory cf = (ConnectionFactory) ctx.lookup("java:JmsXA");
+ javax.jms.Connection c = cf.createConnection();
+ try
+ {
+ c.start();
+ Session s = c.createSession(true, Session.SESSION_TRANSACTED);
+ MessageConsumer mc = s.createConsumer(queue);
+ while (mc.receive(1000) != null);
+ mc.close();
+
+ MessageProducer p = s.createProducer(queue);
+ Message m = s.createTextMessage("101");
+ p.send(m);
+ }
+ finally
+ {
+ try
+ {
+ c.close();
+ }
+ catch (Exception ignored)
+ {
+ }
+ }
+ }
+ finally
+ {
+ try
+ {
+ ut.commit();
+ }
+ catch (Exception ignored)
+ {
+ }
+ }
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Unexpected Error: ", e);
+ }
+ }
+
+ public void changeQueue()
+ {
+ try
+ {
+ InitialContext ctx = new InitialContext();
+ Queue queue = (Queue) ctx.lookup("queue/testQueue");
+ UserTransaction ut = sessionCtx.getUserTransaction();
+ ut.setTransactionTimeout(5);
+ ut.begin();
+ try
+ {
+ ConnectionFactory cf = (ConnectionFactory) ctx.lookup("java:JmsXA");
+ javax.jms.Connection c = cf.createConnection();
+ try
+ {
+ c.start();
+ Session s = c.createSession(true, Session.SESSION_TRANSACTED);
+ MessageConsumer mc = s.createConsumer(queue);
+ mc.receive(1000);
+ mc.close();
+
+ try
+ {
+ Thread.sleep(10000);
+ }
+ catch (InterruptedException ignored)
+ {
+ }
+
+ try
+ {
+ MessageProducer p = s.createProducer(queue);
+ Message m = s.createTextMessage("100");
+ p.send(m);
+ }
+ catch (JMSException expected)
+ {
+ }
+ }
+ finally
+ {
+ try
+ {
+ c.close();
+ }
+ catch (Exception ignored)
+ {
+ }
+ }
+ }
+ finally
+ {
+ try
+ {
+ ut.commit();
+ }
+ catch (Exception ignored)
+ {
+ }
+ }
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Unexpected Error: ", e);
+ }
+ }
+
+ public void checkQueue()
+ {
+ try
+ {
+ InitialContext ctx = new InitialContext();
+ Queue queue = (Queue) ctx.lookup("queue/testQueue");
+ UserTransaction ut = sessionCtx.getUserTransaction();
+ ut.begin();
+ try
+ {
+ ConnectionFactory cf = (ConnectionFactory) ctx.lookup("java:JmsXA");
+ javax.jms.Connection c = cf.createConnection();
+ try
+ {
+ c.start();
+ Session s = c.createSession(true, Session.SESSION_TRANSACTED);
+ MessageConsumer mc = s.createConsumer(queue);
+ Message m = mc.receive(1000);
+ if (m == null || m instanceof TextMessage == false)
+ throw new RuntimeException("Expected one text message: " + m);
+ String value = ((TextMessage) m).getText();
+ if ("101".equals(value) == false)
+ throw new RuntimeException("Message should have text 101 got: " + value);
+ if (mc.receive(1000) != null)
+ throw new RuntimeException("Did not expect two messages");
+ }
+ finally
+ {
+ try
+ {
+ c.close();
+ }
+ catch (Exception ignored)
+ {
+ }
+ }
+ }
+ finally
+ {
+ try
+ {
+ ut.commit();
+ }
+ catch (Exception ignored)
+ {
+ }
+ }
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Unexpected Error: ", e);
+ }
+ }
+
+ public void ejbCreate()
+ {
+ }
+
+ public void ejbActivate()
+ {
+ }
+
+ public void ejbPassivate()
+ {
+ }
+
+ public void ejbRemove()
+ {
+ }
+
+ public void setSessionContext(SessionContext ctx)
+ {
+ this.sessionCtx = ctx;
+ }
+
+ public void unsetSessionContext()
+ {
+ this.sessionCtx = null;
+ }
+
+}
Added: trunk/testsuite/src/main/org/jboss/test/jca/interfaces/TransactionActiveHome.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/jca/interfaces/TransactionActiveHome.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/jca/interfaces/TransactionActiveHome.java 2008-04-08 10:52:04 UTC (rev 71786)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.jca.interfaces;
+
+import java.rmi.RemoteException;
+
+import javax.ejb.CreateException;
+import javax.ejb.EJBHome;
+
+/**
+ * TransactionActiveHome.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public interface TransactionActiveHome extends EJBHome
+{
+ TransactionActiveRemote create() throws CreateException, RemoteException;
+
+}
Added: trunk/testsuite/src/main/org/jboss/test/jca/interfaces/TransactionActiveRemote.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/jca/interfaces/TransactionActiveRemote.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/jca/interfaces/TransactionActiveRemote.java 2008-04-08 10:52:04 UTC (rev 71786)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.jca.interfaces;
+
+import java.rmi.RemoteException;
+
+import javax.ejb.EJBObject;
+
+/**
+ * TransactionActiveRemote.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public interface TransactionActiveRemote extends EJBObject
+{
+ void setupDatabase() throws RemoteException;
+ void changeDatabase() throws RemoteException;
+ void checkDatabase() throws RemoteException;
+ void setupQueue() throws RemoteException;
+ void changeQueue() throws RemoteException;
+ void checkQueue() throws RemoteException;
+}
Added: trunk/testsuite/src/main/org/jboss/test/jca/test/ExecuteJMSDuringRollbackStressTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/jca/test/ExecuteJMSDuringRollbackStressTestCase.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/jca/test/ExecuteJMSDuringRollbackStressTestCase.java 2008-04-08 10:52:04 UTC (rev 71786)
@@ -0,0 +1,367 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.jca.test;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.atomic.AtomicReference;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.naming.InitialContext;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
+import junit.framework.Test;
+
+import org.jboss.logging.Logger;
+import org.jboss.test.JBossTestCase;
+import org.jboss.test.util.ejb.EJBTestCase;
+import org.jboss.tm.TransactionManagerLocator;
+import org.jboss.tm.TxUtils;
+
+/**
+ * ExecuteJMSDuringRollbackStressTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ExecuteJMSDuringRollbackStressTestCase extends EJBTestCase
+{
+ protected final Logger log = Logger.getLogger(getClass());
+
+ private ConnectionFactory cf;
+
+ private Queue queue;
+
+ private CountDownLatch latch;
+
+ private TransactionManager tm;
+
+ private AtomicReference<Transaction> transaction = new AtomicReference<Transaction>();
+
+ public void testExecuteJMSDuringRollback() throws Throwable
+ {
+ queue = (Queue) new InitialContext().lookup("queue/testQueue");
+ cf = (ConnectionFactory) new InitialContext().lookup("java:TestJmsLocal");
+ setupQueue();
+ // This test takes too long to iterate 100 times because of the sleeps
+ for (int i = 0; i < getIterationCount()/10; ++i)
+ {
+ log.info("Running " + getName() + " iteration=" + i);
+ latch = new CountDownLatch(2);
+
+ ExecuteJMS executeJMS = new ExecuteJMS();
+ Thread thread1 = new Thread(executeJMS);
+ thread1.start();
+
+ Rollback rollback = new Rollback();
+ Thread thread2 = new Thread(rollback);
+ thread2.start();
+
+ thread1.join();
+ thread2.join();
+ if (executeJMS.error != null)
+ {
+ log.error(executeJMS.error);
+ throw executeJMS.error;
+ }
+ if (rollback.error != null)
+ {
+ log.error(rollback.error);
+ throw rollback.error;
+ }
+ checkQueue();
+ }
+ }
+
+ public class ExecuteJMS extends TestRunnable
+ {
+ private Connection c;
+ private MessageProducer p;
+ private Message m;
+
+ public void setup() throws Throwable
+ {
+ tm.begin();
+ transaction.set(tm.getTransaction());
+
+ try
+ {
+ c = cf.createConnection();
+ c.start();
+ Session s = c.createSession(true, Session.SESSION_TRANSACTED);
+ MessageConsumer r = s.createConsumer(queue);
+ r.receive(1000);
+ r.close();
+ p = s.createProducer(queue);
+ m = s.createTextMessage("100");
+ }
+ catch (Throwable t)
+ {
+ try
+ {
+ if (c != null)
+ c.close();
+ }
+ catch (Exception ignored)
+ {
+ }
+ try
+ {
+ tm.rollback();
+ }
+ catch (Exception ignored)
+ {
+ log.warn("Ignored", ignored);
+ }
+ throw t;
+ }
+ }
+
+ public void test() throws Throwable
+ {
+ try
+ {
+ p.send(m);
+ }
+ catch (JMSException expected)
+ {
+ }
+ finally
+ {
+ try
+ {
+ if (c != null)
+ c.close();
+ }
+ catch (Exception ignored)
+ {
+ }
+ try
+ {
+ synchronized (transaction)
+ {
+ if (TxUtils.isActive(tm))
+ tm.rollback();
+ else
+ tm.suspend();
+ }
+ }
+ catch (Exception ignored)
+ {
+ }
+ }
+
+ tm.begin();
+ try
+ {
+ Connection c = cf.createConnection();
+ try
+ {
+ c.start();
+ c.createSession(true, Session.SESSION_TRANSACTED);
+ }
+ finally
+ {
+ try
+ {
+ c.close();
+ }
+ catch (Exception ignored)
+ {
+ }
+ }
+ }
+ finally
+ {
+ tm.commit();
+ }
+ }
+ }
+
+ public class Rollback extends TestRunnable
+ {
+ public void test() throws Throwable
+ {
+ Transaction tx = transaction.get();
+ if (tx != null)
+ {
+ try
+ {
+ synchronized (transaction)
+ {
+ if (TxUtils.isActive(tx))
+ tx.rollback();
+ }
+ }
+ catch (Exception ignored)
+ {
+ }
+ }
+ }
+ }
+
+ protected void setupQueue() throws Throwable
+ {
+ log.info("setupQueue");
+ tm.begin();
+ try
+ {
+ Connection c = cf.createConnection();
+ try
+ {
+ c.start();
+ Session s = c.createSession(true, Session.SESSION_TRANSACTED);
+ MessageConsumer mc = s.createConsumer(queue);
+ while (mc.receive(1000) != null);
+ mc.close();
+
+ MessageProducer p = s.createProducer(queue);
+ Message m = s.createTextMessage("101");
+ p.send(m);
+ }
+ finally
+ {
+ try
+ {
+ c.close();
+ }
+ catch (Exception ignored)
+ {
+ }
+ }
+ }
+ finally
+ {
+ tm.commit();
+ }
+ }
+
+ protected void checkQueue() throws Throwable
+ {
+ log.info("checking queue");
+ tm.begin();
+ try
+ {
+ Connection c = cf.createConnection();
+ try
+ {
+ c.start();
+ Session s = c.createSession(true, Session.SESSION_TRANSACTED);
+ MessageConsumer mc = s.createConsumer(queue);
+ Message m = mc.receive(1000);
+ if (m == null || m instanceof TextMessage == false)
+ throw new RuntimeException("Expected one text message: " + m);
+ String value = ((TextMessage) m).getText();
+ if ("101".equals(value) == false)
+ throw new RuntimeException("Message should have text 101 got: " + value);
+ if (mc.receive(1000) != null)
+ throw new RuntimeException("Did not expect two messages");
+ }
+ catch (Throwable t)
+ {
+ log.error("Error checking queue", t);
+ throw t;
+ }
+ finally
+ {
+ try
+ {
+ c.close();
+ }
+ catch (Exception ignored)
+ {
+ }
+ }
+ }
+ finally
+ {
+ tm.rollback();
+ }
+ }
+
+ public class TestRunnable implements Runnable
+ {
+ public Throwable error;
+
+ public void setup() throws Throwable
+ {
+ }
+
+ public void test() throws Throwable
+ {
+ }
+
+ public void run()
+ {
+ try
+ {
+ setup();
+ }
+ catch (Throwable t)
+ {
+ error = t;
+ latch.countDown();
+ return;
+ }
+ latch.countDown();
+ try
+ {
+ latch.await();
+ }
+ catch (InterruptedException e)
+ {
+ log.warn("Ignored", e);
+ }
+ try
+ {
+ test();
+ }
+ catch (Throwable t)
+ {
+ error = t;
+ }
+ }
+ }
+
+ protected void setUp() throws Exception
+ {
+ tm = TransactionManagerLocator.getInstance().locate();
+ }
+
+ public ExecuteJMSDuringRollbackStressTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite() throws Exception
+ {
+ return JBossTestCase.getDeploySetup(ExecuteJMSDuringRollbackStressTestCase.class, "jcaexecutejmsrollback.jar");
+ }
+}
Added: trunk/testsuite/src/main/org/jboss/test/jca/test/ExecuteSQLDuringRollbackStressTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/jca/test/ExecuteSQLDuringRollbackStressTestCase.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/jca/test/ExecuteSQLDuringRollbackStressTestCase.java 2008-04-08 10:52:04 UTC (rev 71786)
@@ -0,0 +1,327 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.jca.test;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.atomic.AtomicReference;
+
+import javax.naming.InitialContext;
+import javax.sql.DataSource;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
+import junit.framework.Test;
+
+import org.jboss.logging.Logger;
+import org.jboss.test.JBossTestCase;
+import org.jboss.test.util.ejb.EJBTestCase;
+import org.jboss.tm.TransactionManagerLocator;
+import org.jboss.tm.TxUtils;
+
+/**
+ * Abstract concurrent stress test.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 65495 $
+ */
+public class ExecuteSQLDuringRollbackStressTestCase extends EJBTestCase
+{
+ protected final Logger log = Logger.getLogger(getClass());
+
+ private DataSource dataSource;
+
+ private CountDownLatch latch;
+
+ private TransactionManager tm;
+
+ private AtomicReference<Transaction> transaction = new AtomicReference<Transaction>();
+
+ public void testExecuteSQLDuringRollback() throws Throwable
+ {
+ dataSource = (DataSource) new InitialContext().lookup("java:DefaultDS");
+ createDatabase();
+ for (int i = 0; i < getIterationCount(); ++i)
+ {
+ latch = new CountDownLatch(2);
+
+ ExecuteSQL executeSQL = new ExecuteSQL();
+ Thread thread1 = new Thread(executeSQL);
+ thread1.start();
+
+ Rollback rollback = new Rollback();
+ Thread thread2 = new Thread(rollback);
+ thread2.start();
+
+ thread1.join();
+ thread2.join();
+ if (executeSQL.error != null)
+ throw executeSQL.error;
+ if (rollback.error != null)
+ throw rollback.error;
+ checkDatabase();
+ }
+ }
+
+ public class ExecuteSQL extends TestRunnable
+ {
+ private Connection c;
+ private Statement stmt;
+
+ public void setup() throws Throwable
+ {
+ tm.begin();
+ transaction.set(tm.getTransaction());
+
+ try
+ {
+ c = dataSource.getConnection();
+ stmt = c.createStatement();
+ stmt.executeUpdate("insert into JCA_EXECUTE_ROLLBACK values ('101')");
+ }
+ catch (Throwable t)
+ {
+ try
+ {
+ if (c != null)
+ c.close();
+ }
+ catch (Exception ignored)
+ {
+ }
+ try
+ {
+ tm.rollback();
+ }
+ catch (Exception ignored)
+ {
+ log.warn("Ignored", ignored);
+ }
+ throw t;
+ }
+ }
+
+ public void test() throws Throwable
+ {
+ try
+ {
+ stmt.executeUpdate("delete from JCA_EXECUTE_ROLLBACK where name='100'");
+ }
+ catch (SQLException expected)
+ {
+ }
+ finally
+ {
+ try
+ {
+ if (c != null)
+ c.close();
+ }
+ catch (Exception ignored)
+ {
+ }
+ try
+ {
+ synchronized (transaction)
+ {
+ if (TxUtils.isActive(tm))
+ tm.rollback();
+ else
+ tm.suspend();
+ }
+ }
+ catch (Exception ignored)
+ {
+ }
+ }
+
+ tm.begin();
+ try
+ {
+ Connection c = dataSource.getConnection();
+ try
+ {
+ Statement s = c.createStatement();
+ s.executeQuery("select * from JCA_EXECUTE_ROLLBACK");
+ }
+ finally
+ {
+ try
+ {
+ c.close();
+ }
+ catch (Exception ignored)
+ {
+ }
+ }
+ }
+ finally
+ {
+ tm.commit();
+ }
+ }
+ }
+
+ public class Rollback extends TestRunnable
+ {
+ public void test() throws Throwable
+ {
+ Transaction tx = transaction.get();
+ if (tx != null)
+ {
+ try
+ {
+ synchronized (transaction)
+ {
+ if (TxUtils.isActive(tx))
+ tx.rollback();
+ }
+ }
+ catch (Exception ignored)
+ {
+ }
+ }
+ }
+ }
+
+ protected void createDatabase() throws Throwable
+ {
+ Connection c = dataSource.getConnection();
+ try
+ {
+ Statement stmt = c.createStatement();
+ try
+ {
+ stmt.executeUpdate("create table JCA_EXECUTE_ROLLBACK (name varchar(100))");
+ }
+ catch (SQLException ignored)
+ {
+ }
+ stmt.executeUpdate("delete from JCA_EXECUTE_ROLLBACK");
+ stmt.executeUpdate("insert into JCA_EXECUTE_ROLLBACK values ('100')");
+ }
+ finally
+ {
+ try
+ {
+ c.close();
+ }
+ catch (Exception ignored)
+ {
+ }
+ }
+ }
+
+ protected void checkDatabase() throws Throwable
+ {
+ Connection c = dataSource.getConnection();
+ try
+ {
+ Statement stmt = c.createStatement();
+ ResultSet rs = stmt.executeQuery("select name from JCA_EXECUTE_ROLLBACK");
+ if (rs.next() == false)
+ throw new RuntimeException("Expected a first row");
+ String value = rs.getString(1);
+ if ("100".equals(value) == false)
+ throw new RuntimeException("Expected first row to be 100 got " + value);
+ if (rs.next())
+ throw new RuntimeException("Expected only one row");
+ }
+ catch (Throwable t)
+ {
+ log.error("Error checking database", t);
+ throw t;
+ }
+ finally
+ {
+ try
+ {
+ c.close();
+ }
+ catch (Exception ignored)
+ {
+ }
+ }
+ }
+
+ public class TestRunnable implements Runnable
+ {
+ public Throwable error;
+
+ public void setup() throws Throwable
+ {
+ }
+
+ public void test() throws Throwable
+ {
+ }
+
+ public void run()
+ {
+ try
+ {
+ setup();
+ }
+ catch (Throwable t)
+ {
+ error = t;
+ latch.countDown();
+ return;
+ }
+ latch.countDown();
+ try
+ {
+ latch.await();
+ }
+ catch (InterruptedException e)
+ {
+ log.warn("Ignored", e);
+ }
+ try
+ {
+ test();
+ }
+ catch (Throwable t)
+ {
+ error = t;
+ }
+ }
+ }
+
+ protected void setUp() throws Exception
+ {
+ tm = TransactionManagerLocator.getInstance().locate();
+ }
+
+ public ExecuteSQLDuringRollbackStressTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite() throws Exception
+ {
+ return JBossTestCase.getDeploySetup(ExecuteSQLDuringRollbackStressTestCase.class, "jca-tests.jar");
+ }
+}
Added: trunk/testsuite/src/main/org/jboss/test/jca/test/TransactionActiveUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/jca/test/TransactionActiveUnitTestCase.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/jca/test/TransactionActiveUnitTestCase.java 2008-04-08 10:52:04 UTC (rev 71786)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.jca.test;
+
+import junit.framework.Test;
+
+import org.jboss.test.JBossTestCase;
+import org.jboss.test.jca.interfaces.TransactionActiveHome;
+import org.jboss.test.jca.interfaces.TransactionActiveRemote;
+
+/**
+ * TransactionActiveUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TransactionActiveUnitTestCase extends JBossTestCase
+{
+ public TransactionActiveUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite() throws Exception
+ {
+ return getDeploySetup(TransactionActiveUnitTestCase.class, "jca-txactive-ejb.jar");
+ }
+
+ public void testJDBCTransactionActive() throws Exception
+ {
+ TransactionActiveHome home = (TransactionActiveHome) getInitialContext().lookup("test/ejbs/TxActiveBean");
+ TransactionActiveRemote remote = home.create();
+ remote.setupDatabase();
+ remote.changeDatabase();
+ remote.checkDatabase();
+ }
+
+ public void testJMSTransactionActive() throws Exception
+ {
+ TransactionActiveHome home = (TransactionActiveHome) getInitialContext().lookup("test/ejbs/TxActiveBean");
+ TransactionActiveRemote remote = home.create();
+ remote.setupQueue();
+ remote.changeQueue();
+ remote.checkQueue();
+ }
+}
Added: trunk/testsuite/src/resources/jca/executejmsrollback/test-jms-local-ds.xml
===================================================================
--- trunk/testsuite/src/resources/jca/executejmsrollback/test-jms-local-ds.xml (rev 0)
+++ trunk/testsuite/src/resources/jca/executejmsrollback/test-jms-local-ds.xml 2008-04-08 10:52:04 UTC (rev 71786)
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<connection-factories>
+
+ <mbean code="org.jboss.jms.jndi.JMSProviderLoader"
+ name="jboss.mq:service=JMSProviderLoader,name=TestJMSLocalProvider">
+ <attribute name="ProviderName">TestJMSLocalProvider</attribute>
+ <attribute name="ProviderAdapterClass">
+ org.jboss.jms.jndi.JNDIProviderAdapter
+ </attribute>
+ <!-- The combined connection factory -->
+ <attribute name="FactoryRef">java:/ConnectionFactory</attribute>
+ <!-- The queue connection factory -->
+ <attribute name="QueueFactoryRef">java:/ConnectionFactory</attribute>
+ <!-- The topic factory -->
+ <attribute name="TopicFactoryRef">java:/ConnectionFactory</attribute>
+ </mbean>
+
+ <tx-connection-factory>
+ <jndi-name>TestJmsLocal</jndi-name>
+ <rar-name>jms-ra.rar</rar-name>
+ <connection-definition>org.jboss.resource.adapter.jms.JmsConnectionFactory</connection-definition>
+ <config-property name="SessionDefaultType" type="java.lang.String">javax.jms.Topic</config-property>
+ <config-property name="JmsProviderAdapterJNDI" type="java.lang.String">java:/TestJMSLocalProvider</config-property>
+ <max-pool-size>20</max-pool-size>
+ <application-managed-security/>
+ </tx-connection-factory>
+
+</connection-factories>
Added: trunk/testsuite/src/resources/jca/txactive/META-INF/ejb-jar.xml
===================================================================
--- trunk/testsuite/src/resources/jca/txactive/META-INF/ejb-jar.xml (rev 0)
+++ trunk/testsuite/src/resources/jca/txactive/META-INF/ejb-jar.xml 2008-04-08 10:52:04 UTC (rev 71786)
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE ejb-jar
+ PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"
+ "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
+
+<ejb-jar>
+ <enterprise-beans>
+ <session>
+ <ejb-name>TxActiveBean</ejb-name>
+ <home>org.jboss.test.jca.interfaces.TransactionActiveHome</home>
+ <remote>org.jboss.test.jca.interfaces.TransactionActiveRemote</remote>
+ <ejb-class>org.jboss.test.jca.ejb.TransactionActiveBean</ejb-class>
+ <session-type>Stateless</session-type>
+ <transaction-type>Bean</transaction-type>
+ </session>
+ </enterprise-beans>
+ <assembly-descriptor>
+ <container-transaction>
+ <method>
+ <ejb-name>TxActiveBean</ejb-name>
+ <method-name>*</method-name>
+ </method>
+ <trans-attribute>Required</trans-attribute>
+ </container-transaction>
+ </assembly-descriptor>
+</ejb-jar>
Added: trunk/testsuite/src/resources/jca/txactive/META-INF/jboss.xml
===================================================================
--- trunk/testsuite/src/resources/jca/txactive/META-INF/jboss.xml (rev 0)
+++ trunk/testsuite/src/resources/jca/txactive/META-INF/jboss.xml 2008-04-08 10:52:04 UTC (rev 71786)
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE jboss PUBLIC
+ "-//JBoss//DTD JBOSS 3.2//EN"
+ "http://www.jboss.org/j2ee/dtd/jboss_3_2.dtd">
+
+<jboss>
+ <enterprise-beans>
+ <session>
+ <ejb-name>TxActiveBean</ejb-name>
+ <jndi-name>test/ejbs/TxActiveBean</jndi-name>
+ </session>
+ </enterprise-beans>
+
+</jboss>
More information about the jboss-cvs-commits
mailing list