Add debug information
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/18204086 Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/18204086 Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/18204086 Branch: refs/heads/master Commit: 18204086c730d5504beccd76e501f4917ffa1a80 Parents: 9155773 Author: Jean-Louis Monteiro <jeano...@gmail.com> Authored: Tue Dec 18 16:18:03 2018 +0100 Committer: Jean-Louis Monteiro <jeano...@gmail.com> Committed: Tue Dec 18 16:18:03 2018 +0100 ---------------------------------------------------------------------- .../resource/AutoConnectionTrackerTest.java | 43 ++++++++++++++++---- 1 file changed, 36 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tomee/blob/18204086/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 6fb9859..e8f9598 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 @@ -17,6 +17,7 @@ */ package org.apache.openejb.resource; +import junit.framework.AssertionFailedError; import junit.framework.TestCase; import org.apache.geronimo.connector.outbound.AbstractConnectionManager; import org.apache.geronimo.connector.outbound.ConnectionTrackingInterceptor; @@ -167,8 +168,8 @@ public class AutoConnectionTrackerTest extends TestCase { System.gc(); cf.getConnection().close(); - assertEquals(0, logCapture.find("Transaction complete, but connection still has handles associated").size()); - assertEquals(0, logCapture.find("Detected abandoned connection").size()); + assertLogs(logCapture, 0, "Transaction complete, but connection still has handles associated"); + assertLogs(logCapture, 0, "Detected abandoned connection"); assertTrue(getConnectionCount((FakeConnectionFactoryImpl) cf) > 0); } { @@ -186,8 +187,8 @@ public class AutoConnectionTrackerTest extends TestCase { System.gc(); cf.getConnection().close(); - assertEquals(0, logCapture.find("Transaction complete, but connection still has handles associated").size()); - assertEquals(0, logCapture.find("Detected abandoned connection").size()); + assertLogs(logCapture, 0, "Transaction complete, but connection still has handles associated"); + assertLogs(logCapture, 0, "Detected abandoned connection"); assertTrue(getConnectionCount((FakeConnectionFactoryImpl) cf) > 0); } { @@ -197,8 +198,8 @@ public class AutoConnectionTrackerTest extends TestCase { 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()); + assertLogs(logCapture, 1, "Transaction complete, but connection still has handles associated"); + assertLogs(logCapture, 1, "Detected abandoned connection"); } { logCapture.clear(); @@ -207,10 +208,38 @@ public class AutoConnectionTrackerTest extends TestCase { final AutoConnectionTracker tracker = getAutoConnectionTracker((FakeConnectionFactoryImpl) cf); tracker.setEnvironment(null, null); - assertEquals(1, logCapture.find("Detected abandoned connection").size()); + assertLogs(logCapture, 1, "Detected abandoned connection"); } } + // this is a very quick and dirty hack for debugging purpose + private void assertLogs(final LogCaptureHandler logCapture, final int times, final String message) { + final int iteration = 5; + final int waitSeconds = 2; + + AssertionFailedError failure = null; + + for (int i = 0 ; i < iteration ; i++) { + try { + assertEquals(message, times, logCapture.find(message).size()); + return; + + } catch (final AssertionFailedError e) { + if (failure == null) { // keep the first issue + failure = e; + } + + try { + Thread.sleep(waitSeconds * 1000); + } catch (final InterruptedException e1) { + // no-op + } + } + } + + throw failure; + } + private AutoConnectionTracker getAutoConnectionTracker(final FakeConnectionFactoryImpl cf) throws Exception { final Field field = AbstractConnectionManager.class.getDeclaredField("interceptors"); field.setAccessible(true);