[jboss-cvs] JBossAS SVN: r75070 - in branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca: interfaces and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jun 25 12:23:53 EDT 2008


Author: adrian at jboss.org
Date: 2008-06-25 12:23:53 -0400 (Wed, 25 Jun 2008)
New Revision: 75070

Modified:
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/ejb/JDBCStatementTestsConnectionSessionBean.java
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/interfaces/JDBCStatementTestsConnectionSession.java
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/jdbc/TestConnection.java
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/test/JDBCStatementTestsConnectionUnitTestCase.java
Log:
[JBAS-5678] - Tests for making sure rollback is always invoked during close when not autocommit

Modified: branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/ejb/JDBCStatementTestsConnectionSessionBean.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/ejb/JDBCStatementTestsConnectionSessionBean.java	2008-06-25 16:23:37 UTC (rev 75069)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/ejb/JDBCStatementTestsConnectionSessionBean.java	2008-06-25 16:23:53 UTC (rev 75070)
@@ -273,7 +273,102 @@
          throw new EJBException(e);
       }
    }
+   
+   public void testRollbackOnCloseNoTx()
+   {
+      TestConnection tc = null;
+      try
+      {
+         DataSource ds = (DataSource) new InitialContext().lookup("java:NoTxStatementTestsConnectionDS");
+         Connection c = ds.getConnection();
+         try
+         {
+            c.setAutoCommit(false);
+            WrappedConnection wc = (WrappedConnection) c;
+            Connection uc = wc.getUnderlyingConnection();
+            tc = (TestConnection) uc;
 
+            try
+            {
+               c.nativeSQL("ERROR");
+            }
+            catch (SQLException expected)
+            {
+            }
+         }
+         finally
+         {
+            try
+            {
+               c.close();
+            }
+            catch (SQLException ignored)
+            {
+            }
+         }
+         
+         if (tc.isClosed() == false)
+            throw new RuntimeException("Connection was not closed");
+         if (tc.isRolledBack() == false)
+            throw new RuntimeException("Connection was not rolled back");
+      }
+      catch (SQLException e)
+      {
+         throw new EJBException(e);
+      }
+      catch (NamingException e)
+      {
+         throw new EJBException(e);
+      }
+   }
+   
+   public void testRollbackOnCloseManagedTx()
+   {
+      TestConnection tc = null;
+      try
+      {
+         DataSource ds = (DataSource) new InitialContext().lookup("java:StatementTestsConnectionDS");
+         Connection c = ds.getConnection();
+         try
+         {
+            WrappedConnection wc = (WrappedConnection) c;
+            Connection uc = wc.getUnderlyingConnection();
+            tc = (TestConnection) uc;
+
+            try
+            {
+               c.nativeSQL("ERROR");
+            }
+            catch (SQLException expected)
+            {
+            }
+         }
+         finally
+         {
+            try
+            {
+               c.close();
+            }
+            catch (SQLException ignored)
+            {
+            }
+         }
+         
+         if (tc.isClosed() == false)
+            throw new RuntimeException("Connection was not closed");
+         if (tc.isRolledBack() == false)
+            throw new RuntimeException("Connection was not rolled back");
+      }
+      catch (SQLException e)
+      {
+         throw new EJBException(e);
+      }
+      catch (NamingException e)
+      {
+         throw new EJBException(e);
+      }
+   }
+
    public void ejbCreate()
    {
    }

Modified: branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/interfaces/JDBCStatementTestsConnectionSession.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/interfaces/JDBCStatementTestsConnectionSession.java	2008-06-25 16:23:37 UTC (rev 75069)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/interfaces/JDBCStatementTestsConnectionSession.java	2008-06-25 16:23:53 UTC (rev 75070)
@@ -39,4 +39,8 @@
 
    public void testLazyAutoCommit() throws java.rmi.RemoteException;
 
+   public void testRollbackOnCloseNoTx() throws java.rmi.RemoteException;
+
+   public void testRollbackOnCloseManagedTx() throws java.rmi.RemoteException;
+
 }

Modified: branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/jdbc/TestConnection.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/jdbc/TestConnection.java	2008-06-25 16:23:37 UTC (rev 75069)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/jdbc/TestConnection.java	2008-06-25 16:23:53 UTC (rev 75070)
@@ -50,6 +50,8 @@
 
    private boolean closed;
 
+   private boolean rolledBack;
+   
    public TestConnection(TestDriver driver)
    {
       this.driver = driver;
@@ -65,6 +67,11 @@
       return driver.getClosedCount();
    }
 
+   public boolean isRolledBack()
+   {
+      return rolledBack;
+   }
+
    // Implementation of java.sql.Connection
 
    public Statement createStatement(int n, int n1, int n2) throws SQLException {
@@ -142,6 +149,11 @@
 
    public String nativeSQL(String sql)
    {
+      if ("ERROR".equals(sql))
+      {
+         rolledBack = false;
+         throw new RuntimeException(sql);
+      }
       return sql;
    }
 
@@ -207,6 +219,7 @@
 
    public void rollback()
    {
+      rolledBack = true;
    }
 
    public void setCatalog(String cat)

Modified: branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/test/JDBCStatementTestsConnectionUnitTestCase.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/test/JDBCStatementTestsConnectionUnitTestCase.java	2008-06-25 16:23:37 UTC (rev 75069)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/test/JDBCStatementTestsConnectionUnitTestCase.java	2008-06-25 16:23:53 UTC (rev 75070)
@@ -97,4 +97,20 @@
       s.testLazyAutoCommit();
    }
 
+   public void testRollbackOnCloseNoTx() throws Exception
+   {
+      JDBCStatementTestsConnectionSessionHome home =
+         (JDBCStatementTestsConnectionSessionHome)getInitialContext().lookup("JDBCStatementTestsConnectionSession");
+      JDBCStatementTestsConnectionSession s = home.create();
+      s.testRollbackOnCloseNoTx();
+   }
+
+   public void testRollbackOnCloseManagedTx() throws Exception
+   {
+      JDBCStatementTestsConnectionSessionHome home =
+         (JDBCStatementTestsConnectionSessionHome)getInitialContext().lookup("JDBCStatementTestsConnectionSession");
+      JDBCStatementTestsConnectionSession s = home.create();
+      s.testRollbackOnCloseManagedTx();
+   }
+
 }




More information about the jboss-cvs-commits mailing list