tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgallim...@apache.org
Subject tomee git commit: Attempt to make this more robust
Date Wed, 10 Oct 2018 22:16:21 GMT
Repository: tomee
Updated Branches:
  refs/heads/master be9f45e6e -> 1e775fca0


Attempt to make this more robust


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

Branch: refs/heads/master
Commit: 1e775fca06de998572819b07c3f9ae3b84b25bb0
Parents: be9f45e
Author: Jonathan Gallimore <jon@jrg.me.uk>
Authored: Wed Oct 10 23:13:12 2018 +0100
Committer: Jonathan Gallimore <jon@jrg.me.uk>
Committed: Wed Oct 10 23:16:04 2018 +0100

----------------------------------------------------------------------
 .../resource/AutoConnectionTrackerTest.java     | 27 +++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/1e775fca/container/openejb-core/src/test/java/org/apache/openejb/resource/AutoConnectionTrackerTest.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/test/java/org/apache/openejb/resource/AutoConnectionTrackerTest.java
b/container/openejb-core/src/test/java/org/apache/openejb/resource/AutoConnectionTrackerTest.java
index 6c2e455..598a4bc 100644
--- a/container/openejb-core/src/test/java/org/apache/openejb/resource/AutoConnectionTrackerTest.java
+++ b/container/openejb-core/src/test/java/org/apache/openejb/resource/AutoConnectionTrackerTest.java
@@ -18,6 +18,8 @@
 package org.apache.openejb.resource;
 
 import junit.framework.TestCase;
+import org.apache.geronimo.connector.outbound.AbstractConnectionManager;
+import org.apache.geronimo.connector.outbound.ConnectionTrackingInterceptor;
 import org.apache.geronimo.connector.outbound.GenericConnectionManager;
 import org.apache.geronimo.connector.outbound.connectionmanagerconfig.PoolingSupport;
 import org.apache.openejb.assembler.classic.Assembler;
@@ -30,6 +32,7 @@ import org.apache.openejb.assembler.classic.SecurityServiceInfo;
 import org.apache.openejb.assembler.classic.TransactionServiceInfo;
 import org.apache.openejb.config.ConfigurationFactory;
 import org.apache.openejb.config.EjbModule;
+import org.apache.openejb.core.ConnectorReference;
 import org.apache.openejb.jee.EjbJar;
 import org.apache.openejb.jee.StatelessBean;
 import org.apache.openejb.loader.SystemInstance;
@@ -61,6 +64,7 @@ import javax.security.auth.Subject;
 import javax.transaction.xa.XAResource;
 import java.io.PrintWriter;
 import java.lang.SecurityException;
+import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Iterator;
@@ -186,20 +190,37 @@ public class AutoConnectionTrackerTest extends TestCase {
         {
             logCapture.clear();
             bean.leakyTxMethod();
-
             System.gc();
-            cf.getConnection().close();
+
+            final AutoConnectionTracker tracker = getAutoConnectionTracker((FakeConnectionFactoryImpl)
cf);
+            tracker.setEnvironment(null, null);
             assertEquals(1, logCapture.find("Transaction complete, but connection still has
handles associated").size());
+            assertEquals(1, logCapture.find("Detected abandoned connection").size());
         }
         {
             logCapture.clear();
             bean.leakyNonTxMethod();
             System.gc();
-            cf.getConnection().close();
+
+            final AutoConnectionTracker tracker = getAutoConnectionTracker((FakeConnectionFactoryImpl)
cf);
+            tracker.setEnvironment(null, null);
             assertEquals(1, logCapture.find("Detected abandoned connection").size());
         }
     }
 
+    private AutoConnectionTracker getAutoConnectionTracker(final FakeConnectionFactoryImpl
cf) throws Exception {
+        final Field field = AbstractConnectionManager.class.getDeclaredField("interceptors");
+        field.setAccessible(true);
+        final Object o = field.get(cf.connectionManager);
+        final Field stackField = o.getClass().getDeclaredField("stack");
+        stackField.setAccessible(true);
+        final ConnectionTrackingInterceptor cti = (ConnectionTrackingInterceptor) stackField.get(o);
+        final Field connectionTrackerField = ConnectionTrackingInterceptor.class.getDeclaredField("connectionTracker");
+        connectionTrackerField.setAccessible(true);
+        AutoConnectionTracker tracker = (AutoConnectionTracker) connectionTrackerField.get(cti);
+        return tracker;
+    }
+
     private int getConnectionCount(FakeConnectionFactoryImpl cf) {
         final PoolingSupport pooling = ((GenericConnectionManager) cf.connectionManager).getPooling();
         return pooling.getConnectionCount();


Mime
View raw message