tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgallim...@apache.org
Subject tomee git commit: TOMEE-1900 expanding test
Date Thu, 11 Aug 2016 14:20:06 GMT
Repository: tomee
Updated Branches:
  refs/heads/tomee-1.7.x 1f11cc3d2 -> 31a3491ae


TOMEE-1900 expanding test


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/31a3491a
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/31a3491a
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/31a3491a

Branch: refs/heads/tomee-1.7.x
Commit: 31a3491ae42e9d1819746682727c843b9e2612e0
Parents: 1f11cc3
Author: Jonathan Gallimore <jon@jrg.me.uk>
Authored: Thu Aug 11 15:18:50 2016 +0100
Committer: Jonathan Gallimore <jon@jrg.me.uk>
Committed: Thu Aug 11 15:18:50 2016 +0100

----------------------------------------------------------------------
 .../tomee/jdbc/TomcatXADataSourceTest.java      | 71 ++++++++++++++++++++
 1 file changed, 71 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/31a3491a/tomee/tomee-jdbc/src/test/java/org/apache/tomee/jdbc/TomcatXADataSourceTest.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-jdbc/src/test/java/org/apache/tomee/jdbc/TomcatXADataSourceTest.java
b/tomee/tomee-jdbc/src/test/java/org/apache/tomee/jdbc/TomcatXADataSourceTest.java
index 56a95ce..fdf151d 100644
--- a/tomee/tomee-jdbc/src/test/java/org/apache/tomee/jdbc/TomcatXADataSourceTest.java
+++ b/tomee/tomee-jdbc/src/test/java/org/apache/tomee/jdbc/TomcatXADataSourceTest.java
@@ -33,7 +33,9 @@ import javax.annotation.Resource;
 import javax.ejb.EJB;
 import javax.ejb.Singleton;
 import javax.sql.DataSource;
+import javax.sql.XAConnection;
 import javax.transaction.Synchronization;
+import javax.transaction.Transaction;
 import java.sql.Connection;
 import java.sql.SQLException;
 import java.util.ArrayList;
@@ -53,6 +55,9 @@ public class TomcatXADataSourceTest {
     @Resource(name = "xadb")
     private DataSource ds;
 
+    @Resource(name = "xadb2")
+    private DataSource badDs;
+
     @EJB
     private TxP tx;
 
@@ -86,6 +91,20 @@ public class TomcatXADataSourceTest {
             .p("xadb.MaxActive", "25")
             .p("xadb.InitialSize", "3")
 
+            .p("xa2", "new://Resource?class-name=" + BadDataSource.class.getName())
+            .p("xa2.url", "jdbc:hsqldb:mem:tomcat-xa")
+            .p("xa2.user", "sa")
+            .p("xa2.password", "")
+            .p("xa2.SkipImplicitAttributes", "true")
+            .p("xa2.SkipPropertiesFallback", "true") // otherwise goes to connection properties
+
+            .p("xadb2", "new://Resource?type=DataSource")
+            .p("xadb2.xaDataSource", "xa2")
+            .p("xadb2.JtaManaged", "true")
+            .p("xadb2.MaxIdle", "25")
+            .p("xadb2.MaxActive", "25")
+            .p("xadb2.InitialSize", "3")
+
             .build();
     }
 
@@ -221,6 +240,42 @@ public class TomcatXADataSourceTest {
             assertEquals(0, tds.getActive());
             assertEquals(25, tds.getIdle());
         }
+
+        // underlying connection closed when fetch from pool
+        for (int it = 0; it < 5; it++) { // ensures it always works and not only the first
time
+            for (int i = 0; i < 25; i++) {
+                tx.run(new Runnable() {
+                    @Override
+                    public void run() {
+                        try {
+                            final Connection ref = badDs.getConnection();
+                            final Transaction transaction = OpenEJB.getTransactionManager().getTransaction();
+
+                            transaction.registerSynchronization(new Synchronization() {
+                                @Override
+                                public void beforeCompletion() {
+                                    // no-op
+                                }
+
+                                @Override
+                                public void afterCompletion(final int status) { // JPA does
it
+                                    try {
+                                        ref.close();
+                                    } catch (final SQLException e) {
+                                        fail(e.getMessage());
+                                    }
+                                }
+                            });
+                            ref.getMetaData();
+                        } catch (final Exception sql) {
+                            // we expect this
+                        }
+                    }
+                });
+            }
+            assertEquals(0, tds.getActive());
+            assertEquals(25, tds.getIdle());
+        }
     }
 	
     @Singleton
@@ -229,4 +284,20 @@ public class TomcatXADataSourceTest {
             r.run();
         }
     }
+
+    public static class BadDataSource extends JDBCXADataSource {
+
+        public BadDataSource() throws SQLException {
+        }
+
+        @Override
+        public XAConnection getXAConnection() throws SQLException {
+
+            // this closes the underlying connection - which should cause enlist to fail
+            final XAConnection xaConnection = super.getXAConnection();
+            final Connection connection = xaConnection.getConnection();
+            connection.close();
+            return xaConnection;
+        }
+    }
 }


Mime
View raw message