activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtu...@apache.org
Subject activemq git commit: TrapMessageInJDBCStoreTest - intermittent ci failure. Avoid contention on datasource, use long lived connection for assertions
Date Fri, 02 Sep 2016 10:27:28 GMT
Repository: activemq
Updated Branches:
  refs/heads/master 508df5359 -> a3f1aa0bd


TrapMessageInJDBCStoreTest - intermittent ci failure. Avoid contention on datasource, use
long lived connection for assertions


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

Branch: refs/heads/master
Commit: a3f1aa0bdad56cd896b3fb3d5b99137a0978f215
Parents: 508df53
Author: gtully <gary.tully@gmail.com>
Authored: Fri Sep 2 11:27:12 2016 +0100
Committer: gtully <gary.tully@gmail.com>
Committed: Fri Sep 2 11:27:12 2016 +0100

----------------------------------------------------------------------
 .../bugs/TrapMessageInJDBCStoreTest.java        | 55 +++++++++++---------
 1 file changed, 29 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/a3f1aa0b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/TrapMessageInJDBCStoreTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/TrapMessageInJDBCStoreTest.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/TrapMessageInJDBCStoreTest.java
index 3bf4bbd..18b7c21 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/TrapMessageInJDBCStoreTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/TrapMessageInJDBCStoreTest.java
@@ -22,9 +22,6 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
 import javax.jms.Connection;
 import javax.jms.DeliveryMode;
 import javax.jms.Destination;
@@ -47,7 +44,6 @@ import org.apache.derby.jdbc.EmbeddedDataSource;
 import org.apache.log4j.Level;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.slf4j.impl.Log4jLoggerAdapter;
 
 /**
  * Test to demostrate a message trapped in the JDBC store and not
@@ -69,6 +65,7 @@ public class TrapMessageInJDBCStoreTest extends TestCase {
     private BrokerService broker;
     private TestTransactionContext testTransactionContext;
     private TestJDBCPersistenceAdapter jdbc;
+    private java.sql.Connection checkOnStoreConnection;
 
     protected BrokerService createBroker(boolean withJMX) throws Exception {
         BrokerService broker = new BrokerService();
@@ -76,6 +73,8 @@ public class TrapMessageInJDBCStoreTest extends TestCase {
         broker.setUseJmx(withJMX);
 
         EmbeddedDataSource embeddedDataSource = (EmbeddedDataSource) DataSourceServiceSupport.createDataSource(IOHelper.getDefaultDataDirectory());
+        checkOnStoreConnection = embeddedDataSource.getConnection();
+
 
         //wire in a TestTransactionContext (wrapper to TransactionContext) that has an executeBatch()
         // method that can be configured to throw a SQL exception on demand
@@ -118,31 +117,37 @@ public class TrapMessageInJDBCStoreTest extends TestCase {
         broker.start();
         broker.waitUntilStarted();
 
-        LOG.info("***Broker started...");
+        try {
+            LOG.info("***Broker started...");
 
-        // failover but timeout in 5 seconds so the test does not hang
-        String failoverTransportURL = "failover:(" + transportUrl
-                + ")?timeout=5000";
+            // failover but timeout in 5 seconds so the test does not hang
+            String failoverTransportURL = "failover:(" + transportUrl
+                    + ")?timeout=5000";
 
 
-        sendMessage(MY_TEST_Q, failoverTransportURL);
+            sendMessage(MY_TEST_Q, failoverTransportURL);
 
-        //check db contents
-        ArrayList<Long> dbSeq = dbMessageCount();
-        LOG.info("*** after send: db contains message seq " +dbSeq );
+            //check db contents
+            ArrayList<Long> dbSeq = dbMessageCount(checkOnStoreConnection);
+            LOG.info("*** after send: db contains message seq " + dbSeq);
 
-        List<TextMessage> consumedMessages = consumeMessages(MY_TEST_Q,failoverTransportURL);
+            List<TextMessage> consumedMessages = consumeMessages(MY_TEST_Q, failoverTransportURL);
 
-        assertEquals("number of consumed messages",3,consumedMessages.size());
+            assertEquals("number of consumed messages", 3, consumedMessages.size());
 
-        //check db contents
-        dbSeq = dbMessageCount();
-        LOG.info("*** after consume - db contains message seq " + dbSeq);
+            //check db contents
+            dbSeq = dbMessageCount(checkOnStoreConnection);
+            LOG.info("*** after consume - db contains message seq " + dbSeq);
 
-        assertEquals("number of messages in DB after test",0,dbSeq.size());
+            assertEquals("number of messages in DB after test", 0, dbSeq.size());
 
-        broker.stop();
-        broker.waitUntilStopped();
+        } finally {
+            try {
+                checkOnStoreConnection.close();
+            } catch (Exception ignored) {}
+            broker.stop();
+            broker.waitUntilStopped();
+        }
     }
 
 
@@ -212,7 +217,7 @@ public class TrapMessageInJDBCStoreTest extends TestCase {
             producer.send(m);
 
             //check db contents
-            ArrayList<Long> dbSeq = dbMessageCount();
+            ArrayList<Long> dbSeq = dbMessageCount(checkOnStoreConnection);
             LOG.info("*** after send 2 - db contains message seq " + dbSeq);
             assertEquals("number of messages in DB after send 2",2,dbSeq.size());
 
@@ -233,10 +238,10 @@ public class TrapMessageInJDBCStoreTest extends TestCase {
      * @return
      * @throws SQLException
      * @throws IOException
+     * @param checkOnStoreConnection
      */
-    private ArrayList<Long> dbMessageCount() throws SQLException, IOException {
-        java.sql.Connection conn = ((JDBCPersistenceAdapter) broker.getPersistenceAdapter()).getDataSource().getConnection();
-        PreparedStatement statement = conn.prepareStatement("SELECT MSGID_SEQ FROM ACTIVEMQ_MSGS");
+    private ArrayList<Long> dbMessageCount(java.sql.Connection checkOnStoreConnection)
throws SQLException, IOException {
+        PreparedStatement statement = checkOnStoreConnection.prepareStatement("SELECT MSGID_SEQ
FROM ACTIVEMQ_MSGS");
 
         try{
 
@@ -251,8 +256,6 @@ public class TrapMessageInJDBCStoreTest extends TestCase {
 
         }finally{
             statement.close();
-            conn.close();
-
         }
 
     }


Mime
View raw message