activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtu...@apache.org
Subject [2/2] activemq git commit: tidy up a bunch of jdbc test cases to ensure embedded derby is shutdown
Date Thu, 23 Apr 2015 12:11:03 GMT
tidy up a bunch of jdbc test cases to ensure embedded derby is shutdown


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

Branch: refs/heads/master
Commit: 165959e25007271f8cdfdcf72641b9a92483ef40
Parents: 971ff0d
Author: gtully <gary.tully@gmail.com>
Authored: Thu Apr 23 13:12:49 2015 +0100
Committer: gtully <gary.tully@gmail.com>
Committed: Thu Apr 23 13:12:49 2015 +0100

----------------------------------------------------------------------
 .../store/jdbc/DataSourceServiceSupport.java    | 19 +++++++++++
 .../store/jdbc/DefaultDatabaseLocker.java       |  2 +-
 .../store/jdbc/JDBCPersistenceAdapter.java      |  6 ++--
 .../org/apache/activemq/broker/AMQ4351Test.java |  5 ---
 .../broker/ft/DbRestartJDBCQueueTest.java       |  5 +++
 .../broker/ft/JDBCQueueMasterSlaveTest.java     |  7 +++-
 .../org/apache/activemq/bugs/AMQ4636Test.java   | 11 ++-----
 .../org/apache/activemq/bugs/AMQ4952Test.java   |  7 ++++
 .../bugs/TrapMessageInJDBCStoreTest.java        |  1 -
 .../activemq/store/MessagePriorityTest.java     |  2 +-
 .../store/jdbc/JDBCCommitExceptionTest.java     |  7 ----
 .../store/jdbc/JDBCIOExceptionHandlerTest.java  | 34 ++++++++------------
 .../store/jdbc/JDBCMessagePriorityTest.java     | 25 ++------------
 .../store/jdbc/JDBCNegativeQueueTest.java       |  1 -
 .../store/jdbc/JDBCNetworkBrokerDetachTest.java |  4 +--
 .../store/jdbc/JDBCPersistenceAdapterTest.java  |  6 ----
 .../store/jdbc/JDBCStoreAutoCommitTest.java     | 14 ++++----
 .../store/jdbc/JDBCStoreBrokerTest.java         | 14 ++------
 .../activemq/store/jdbc/JDBCStoreOrderTest.java |  7 +---
 .../store/jdbc/JDBCTablePrefixAssignedTest.java |  5 ---
 .../activemq/store/jdbc/JDBCTestMemory.java     |  9 ------
 .../store/jdbc/LeaseDatabaseLockerTest.java     | 14 +++++---
 .../usecases/JDBCDurableSubscriptionTest.java   |  4 ---
 23 files changed, 80 insertions(+), 129 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/165959e2/activemq-jdbc-store/src/main/java/org/apache/activemq/store/jdbc/DataSourceServiceSupport.java
----------------------------------------------------------------------
diff --git a/activemq-jdbc-store/src/main/java/org/apache/activemq/store/jdbc/DataSourceServiceSupport.java
b/activemq-jdbc-store/src/main/java/org/apache/activemq/store/jdbc/DataSourceServiceSupport.java
index 00b2490..31835ba 100644
--- a/activemq-jdbc-store/src/main/java/org/apache/activemq/store/jdbc/DataSourceServiceSupport.java
+++ b/activemq-jdbc-store/src/main/java/org/apache/activemq/store/jdbc/DataSourceServiceSupport.java
@@ -18,6 +18,7 @@ package org.apache.activemq.store.jdbc;
 
 import java.io.File;
 import java.io.IOException;
+import java.sql.SQLException;
 
 import javax.sql.DataSource;
 
@@ -36,6 +37,7 @@ abstract public class DataSourceServiceSupport extends LockableServiceSupport
{
     private String dataDirectory = IOHelper.getDefaultDataDirectory();
     private File dataDirectoryFile;
     private DataSource dataSource;
+    private DataSource createdDefaultDataSource;
 
     public DataSourceServiceSupport() {
     }
@@ -68,11 +70,19 @@ abstract public class DataSourceServiceSupport extends LockableServiceSupport
{
             dataSource = createDataSource(getDataDirectoryFile().getCanonicalPath());
             if (dataSource == null) {
                 throw new IllegalArgumentException("No dataSource property has been configured");
+            } else {
+                createdDefaultDataSource = dataSource;
             }
         }
         return dataSource;
     }
 
+    public void closeDataSource(DataSource dataSource) {
+        if (createdDefaultDataSource != null && createdDefaultDataSource.equals(dataSource))
{
+            shutdownDefaultDataSource(dataSource);
+        }
+    }
+
     public void setDataSource(DataSource dataSource) {
         this.dataSource = dataSource;
     }
@@ -90,6 +100,15 @@ abstract public class DataSourceServiceSupport extends LockableServiceSupport
{
         return ds;
     }
 
+    public static void shutdownDefaultDataSource(DataSource dataSource) {
+        final EmbeddedDataSource ds =  (EmbeddedDataSource) dataSource;
+        ds.setShutdownDatabase("shutdown");
+        try {
+            ds.getConnection();
+        } catch (SQLException expectedAndIgnored) {
+        }
+    }
+
     public String toString() {
         return "" + dataSource;
     }

http://git-wip-us.apache.org/repos/asf/activemq/blob/165959e2/activemq-jdbc-store/src/main/java/org/apache/activemq/store/jdbc/DefaultDatabaseLocker.java
----------------------------------------------------------------------
diff --git a/activemq-jdbc-store/src/main/java/org/apache/activemq/store/jdbc/DefaultDatabaseLocker.java
b/activemq-jdbc-store/src/main/java/org/apache/activemq/store/jdbc/DefaultDatabaseLocker.java
index d7a406a..36497d1 100644
--- a/activemq-jdbc-store/src/main/java/org/apache/activemq/store/jdbc/DefaultDatabaseLocker.java
+++ b/activemq-jdbc-store/src/main/java/org/apache/activemq/store/jdbc/DefaultDatabaseLocker.java
@@ -143,7 +143,7 @@ public class DefaultDatabaseLocker extends AbstractJDBCLocker {
             try {
                 connection.rollback();
             } catch (SQLException sqle) {
-                LOG.warn("Exception while rollbacking the connection on shutdown. This exception
is ignored.", sqle);
+                LOG.debug("Exception while rollbacking the connection on shutdown. This exception
is ignored.", sqle);
             } finally {
                 try {
                     connection.close();

http://git-wip-us.apache.org/repos/asf/activemq/blob/165959e2/activemq-jdbc-store/src/main/java/org/apache/activemq/store/jdbc/JDBCPersistenceAdapter.java
----------------------------------------------------------------------
diff --git a/activemq-jdbc-store/src/main/java/org/apache/activemq/store/jdbc/JDBCPersistenceAdapter.java
b/activemq-jdbc-store/src/main/java/org/apache/activemq/store/jdbc/JDBCPersistenceAdapter.java
index 4236e9d..23b5cfa 100755
--- a/activemq-jdbc-store/src/main/java/org/apache/activemq/store/jdbc/JDBCPersistenceAdapter.java
+++ b/activemq-jdbc-store/src/main/java/org/apache/activemq/store/jdbc/JDBCPersistenceAdapter.java
@@ -336,6 +336,7 @@ public class JDBCPersistenceAdapter extends DataSourceServiceSupport implements
             cleanupTicket.cancel(true);
             cleanupTicket = null;
         }
+        closeDataSource(getDataSource());
     }
 
     public void cleanup() {
@@ -408,15 +409,14 @@ public class JDBCPersistenceAdapter extends DataSourceServiceSupport
implements
                 throw new IllegalArgumentException(
                         "No dataSource property has been configured");
             }
-        } else {
-            LOG.info("Using a separate dataSource for locking: "
-                    + lockDataSource);
         }
         return lockDataSource;
     }
 
     public void setLockDataSource(DataSource dataSource) {
         this.lockDataSource = dataSource;
+        LOG.info("Using a separate dataSource for locking: "
+                            + lockDataSource);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/activemq/blob/165959e2/activemq-unit-tests/src/test/java/org/apache/activemq/broker/AMQ4351Test.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/AMQ4351Test.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/AMQ4351Test.java
index ce7ed3d..0b0e5cc 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/AMQ4351Test.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/AMQ4351Test.java
@@ -63,11 +63,6 @@ public class AMQ4351Test extends BrokerTestSupport {
         System.setProperty("derby.system.home", new File(IOHelper.getDefaultDataDirectory()).getCanonicalPath());
 
         JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter();
-        EmbeddedDataSource dataSource = new EmbeddedDataSource();
-        dataSource.setDatabaseName("derbyDb");
-        dataSource.setCreateDatabase("create");
-        jdbc.setDataSource(dataSource);
-
         jdbc.deleteAllMessages();
         broker.setPersistenceAdapter(jdbc);
         return broker;

http://git-wip-us.apache.org/repos/asf/activemq/blob/165959e2/activemq-unit-tests/src/test/java/org/apache/activemq/broker/ft/DbRestartJDBCQueueTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/ft/DbRestartJDBCQueueTest.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/ft/DbRestartJDBCQueueTest.java
index 9b21c44..6064efb 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/ft/DbRestartJDBCQueueTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/ft/DbRestartJDBCQueueTest.java
@@ -33,6 +33,7 @@ import org.apache.activemq.store.jdbc.JDBCPersistenceAdapter;
 import org.apache.activemq.util.DefaultIOExceptionHandler;
 import org.apache.activemq.util.IOHelper;
 import org.apache.derby.jdbc.EmbeddedDataSource;
+import org.junit.After;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -79,6 +80,10 @@ public class DbRestartJDBCQueueTest extends JmsTopicSendReceiveWithTwoConnection
        broker.stop();
     }
 
+    @After
+    public void shutDownDerby() {
+        DataSourceServiceSupport.shutdownDefaultDataSource(sharedDs);
+    }
 
     protected Session createSendSession(Connection sendConnection) throws Exception {
         if (transactedSends) {

http://git-wip-us.apache.org/repos/asf/activemq/blob/165959e2/activemq-unit-tests/src/test/java/org/apache/activemq/broker/ft/JDBCQueueMasterSlaveTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/ft/JDBCQueueMasterSlaveTest.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/ft/JDBCQueueMasterSlaveTest.java
index c7b0ec6..0547b7c 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/ft/JDBCQueueMasterSlaveTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/ft/JDBCQueueMasterSlaveTest.java
@@ -35,7 +35,7 @@ import org.apache.activemq.util.IOHelper;
 import org.apache.derby.jdbc.EmbeddedDataSource;
 
 public class JDBCQueueMasterSlaveTest extends QueueMasterSlaveTestSupport {
-    protected DataSource sharedDs;
+    protected SyncCreateDataSource sharedDs;
     protected String MASTER_URL = "tcp://localhost:62001";
     protected String SLAVE_URL  = "tcp://localhost:62002";
 
@@ -45,6 +45,11 @@ public class JDBCQueueMasterSlaveTest extends QueueMasterSlaveTestSupport
{
         super.setUp();
     }
 
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        DataSourceServiceSupport.shutdownDefaultDataSource(sharedDs.delegate);
+    }
+
     protected void createMaster() throws Exception {
         master = new BrokerService();
         master.setBrokerName("master");

http://git-wip-us.apache.org/repos/asf/activemq/blob/165959e2/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ4636Test.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ4636Test.java b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ4636Test.java
index 014d86a..9b397b0 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ4636Test.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ4636Test.java
@@ -78,15 +78,8 @@ public class AMQ4636Test {
             broker.stop();
             broker.waitUntilStopped();
         }
-        try {
-            if (embeddedDataSource != null) {
-                // ref http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java?view=markup
-                embeddedDataSource.setShutdownDatabase("shutdown");
-                embeddedDataSource.getConnection();
-            }
-        } catch (Exception ignored) {
-        } finally {
-            embeddedDataSource.setShutdownDatabase(null);
+        if (embeddedDataSource != null) {
+            DataSourceServiceSupport.shutdownDefaultDataSource(embeddedDataSource);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/activemq/blob/165959e2/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ4952Test.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ4952Test.java b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ4952Test.java
index dd26e81..cc16b75 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ4952Test.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ4952Test.java
@@ -55,6 +55,7 @@ import org.apache.activemq.command.ActiveMQDestination;
 import org.apache.activemq.command.ActiveMQQueue;
 import org.apache.activemq.network.ConditionalNetworkBridgeFilterFactory;
 import org.apache.activemq.network.NetworkConnector;
+import org.apache.activemq.store.jdbc.DataSourceServiceSupport;
 import org.apache.activemq.store.jdbc.JDBCPersistenceAdapter;
 import org.apache.activemq.util.IOHelper;
 import org.apache.activemq.util.IntrospectionSupport;
@@ -275,13 +276,19 @@ public class AMQ4952Test {
 
     protected void doTearDown() throws Exception {
 
+        DataSource dataSource = ((JDBCPersistenceAdapter)producerBroker.getPersistenceAdapter()).getDataSource();
         try {
             producerBroker.stop();
         } catch (Exception ex) {
+        } finally {
+            DataSourceServiceSupport.shutdownDefaultDataSource(dataSource);
         }
+        dataSource = ((JDBCPersistenceAdapter)consumerBroker.getPersistenceAdapter()).getDataSource();
         try {
             consumerBroker.stop();
         } catch (Exception ex) {
+        } finally {
+            DataSourceServiceSupport.shutdownDefaultDataSource(dataSource);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/activemq/blob/165959e2/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 688d066..c073646 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
@@ -73,7 +73,6 @@ public class TrapMessageInJDBCStoreTest extends TestCase {
         broker.setUseJmx(withJMX);
 
         EmbeddedDataSource embeddedDataSource = (EmbeddedDataSource) DataSourceServiceSupport.createDataSource(IOHelper.getDefaultDataDirectory());
-        embeddedDataSource.setCreateDatabase("create");
 
         //wire in a TestTransactionContext (wrapper to TransactionContext) that has an executeBatch()
         // method that can be configured to throw a SQL exception on demand

http://git-wip-us.apache.org/repos/asf/activemq/blob/165959e2/activemq-unit-tests/src/test/java/org/apache/activemq/store/MessagePriorityTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/store/MessagePriorityTest.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/store/MessagePriorityTest.java
index 521c899..c6b6324 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/store/MessagePriorityTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/store/MessagePriorityTest.java
@@ -563,7 +563,7 @@ abstract public class MessagePriorityTest extends CombinationTestSupport
{
     }
 
     public void testQueueBacklog() throws Exception {
-        final int backlog = 180000;
+        final int backlog = 18000;
         ActiveMQQueue queue = (ActiveMQQueue)sess.createQueue("TEST");
 
         ProducerThread lowPri = new ProducerThread(queue, backlog, LOW_PRI);

http://git-wip-us.apache.org/repos/asf/activemq/blob/165959e2/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCCommitExceptionTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCCommitExceptionTest.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCCommitExceptionTest.java
index e183553..05e7208 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCCommitExceptionTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCCommitExceptionTest.java
@@ -47,8 +47,6 @@ public class JDBCCommitExceptionTest extends TestCase {
     protected ActiveMQConnectionFactory factory;
     protected BrokerService broker;
     protected String connectionUri;
-    protected EmbeddedDataSource dataSource;
-    protected java.sql.Connection dbConnection;
     protected BrokenPersistenceAdapter jdbc;
 
     @Override
@@ -155,11 +153,6 @@ public class JDBCCommitExceptionTest extends TestCase {
         BrokerService broker = new BrokerService();
         jdbc = new BrokenPersistenceAdapter();
 
-        dataSource = new EmbeddedDataSource();
-        dataSource.setDatabaseName("target/derbyDb");
-        dataSource.setCreateDatabase("create");
-
-        jdbc.setDataSource(dataSource);
         jdbc.setUseLock(false);
         jdbc.deleteAllMessages();
 

http://git-wip-us.apache.org/repos/asf/activemq/blob/165959e2/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCIOExceptionHandlerTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCIOExceptionHandlerTest.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCIOExceptionHandlerTest.java
index 6ad2f03..20c6986 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCIOExceptionHandlerTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCIOExceptionHandlerTest.java
@@ -31,6 +31,7 @@ import org.apache.activemq.util.IOHelper;
 import org.apache.activemq.util.LeaseLockerIOExceptionHandler;
 import org.apache.activemq.util.Wait;
 import org.apache.derby.jdbc.EmbeddedDataSource;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.slf4j.Logger;
@@ -51,14 +52,15 @@ public class JDBCIOExceptionHandlerTest {
     private static final Logger LOG = LoggerFactory.getLogger(JDBCIOExceptionHandlerTest.class);
     private static final String TRANSPORT_URL = "tcp://0.0.0.0:0";
 
-    private static final String DATABASE_NAME = "DERBY_OVERRIDE";
     private ActiveMQConnectionFactory factory;
     private ReconnectingEmbeddedDataSource dataSource;
     private BrokerService broker;
 
-    @Before
-    public void dbHomeSysProp() throws Exception {
-        System.setProperty("derby.system.home", new File(IOHelper.getDefaultDataDirectory()).getCanonicalPath());
+    @After
+    public void stopDB() {
+        if (dataSource != null) {
+            dataSource.stopDB();
+        }
     }
 
     protected BrokerService createBroker(boolean withJMX) throws Exception {
@@ -71,15 +73,11 @@ public class JDBCIOExceptionHandlerTest {
 
         broker.setUseJmx(withJMX);
 
-        EmbeddedDataSource embeddedDataSource = new EmbeddedDataSource();
-        embeddedDataSource.setDatabaseName(DATABASE_NAME);
-        embeddedDataSource.setCreateDatabase("create");
-
+        JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter();
+        EmbeddedDataSource embeddedDataSource = (EmbeddedDataSource) jdbc.getDataSource();
         // create a wrapper to EmbeddedDataSource to allow the connection be
         // reestablished to derby db
         dataSource = new ReconnectingEmbeddedDataSource(embeddedDataSource);
-
-        JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter();
         jdbc.setDataSource(dataSource);
 
         jdbc.setLockKeepAlivePeriod(1000l);
@@ -310,23 +308,17 @@ public class JDBCIOExceptionHandlerTest {
          *
          * @throws SQLException
          */
-        public void restartDB() throws SQLException {
-            EmbeddedDataSource newDatasource = new EmbeddedDataSource();
-            newDatasource.setDatabaseName(DATABASE_NAME);
+        public void restartDB() throws Exception {
+            EmbeddedDataSource newDatasource =
+                    (EmbeddedDataSource) DataSourceServiceSupport.createDataSource(broker.getDataDirectoryFile().getCanonicalPath());
             newDatasource.getConnection();
             LOG.info("*** DB restarted now...");
             this.realDatasource = newDatasource;
         }
 
         public void stopDB() {
-            try {
-                realDatasource.setShutdownDatabase("shutdown");
-                LOG.info("***DB is being shutdown...");
-                dataSource.getConnection();
-                fail("should have thrown a db closed exception");
-            } catch (Exception ex) {
-                ex.printStackTrace(System.out);
-            }
+            LOG.info("***DB is being shutdown...");
+            DataSourceServiceSupport.shutdownDefaultDataSource(realDatasource);
         }
 
         public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException
{

http://git-wip-us.apache.org/repos/asf/activemq/blob/165959e2/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCMessagePriorityTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCMessagePriorityTest.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCMessagePriorityTest.java
index 34796a4..de171fc 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCMessagePriorityTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCMessagePriorityTest.java
@@ -34,6 +34,7 @@ import javax.jms.Session;
 import javax.jms.TextMessage;
 import javax.jms.TopicSubscriber;
 
+import javax.sql.DataSource;
 import junit.framework.Test;
 
 import org.apache.activemq.command.ActiveMQMessage;
@@ -48,39 +49,19 @@ import org.slf4j.LoggerFactory;
 public class JDBCMessagePriorityTest extends MessagePriorityTest {
 
     private static final Logger LOG = LoggerFactory.getLogger(JDBCMessagePriorityTest.class);
-    EmbeddedDataSource dataSource;
+    DataSource dataSource;
     JDBCPersistenceAdapter jdbc;
 
     @Override
     protected PersistenceAdapter createPersistenceAdapter(boolean delete) throws Exception
{
         jdbc = new JDBCPersistenceAdapter();
-        dataSource = new EmbeddedDataSource();
-        dataSource.setDatabaseName("derbyDb");
-        dataSource.setCreateDatabase("create");
-        dataSource.setShutdownDatabase(null);
-        jdbc.setDataSource(dataSource);
+        dataSource = jdbc.getDataSource();
         jdbc.deleteAllMessages();
         jdbc.setCleanupPeriod(2000);
         return jdbc;
     }
 
 
-    @Override
-    protected void tearDown() throws Exception {
-       super.tearDown();
-       try {
-            if (dataSource != null) {
-                // ref http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java?view=markup
-                dataSource.setShutdownDatabase("shutdown");
-                dataSource.getConnection();
-           }
-       } catch (Exception ignored) {
-       } finally {
-            dataSource.setShutdownDatabase(null);
-       }
-
-    }
-
     // this cannot be a general test as kahaDB just has support for 3 priority levels
     public void testDurableSubsReconnectWithFourLevels() throws Exception {
         ActiveMQTopic topic = (ActiveMQTopic) sess.createTopic("TEST");

http://git-wip-us.apache.org/repos/asf/activemq/blob/165959e2/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCNegativeQueueTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCNegativeQueueTest.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCNegativeQueueTest.java
index 0a2ca1d..52c5129 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCNegativeQueueTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCNegativeQueueTest.java
@@ -35,7 +35,6 @@ public class JDBCNegativeQueueTest extends NegativeQueueTest {
     protected void configureBroker(BrokerService answer) throws Exception {
         super.configureBroker(answer);
         JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter();
-        jdbc.setDataSource(dataSource);
         answer.setPersistenceAdapter(jdbc);
         dataSource = jdbc.getDataSource();
     }

http://git-wip-us.apache.org/repos/asf/activemq/blob/165959e2/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCNetworkBrokerDetachTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCNetworkBrokerDetachTest.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCNetworkBrokerDetachTest.java
index 409b20f..8a011fc 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCNetworkBrokerDetachTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCNetworkBrokerDetachTest.java
@@ -24,10 +24,8 @@ public class JDBCNetworkBrokerDetachTest extends NetworkBrokerDetachTest
{
 
     protected void configureBroker(BrokerService broker) throws Exception {
         JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter();
-        EmbeddedDataSource dataSource = new EmbeddedDataSource();
+        EmbeddedDataSource dataSource = (EmbeddedDataSource) jdbc.getDataSource();
         dataSource.setDatabaseName(broker.getBrokerName());
-        dataSource.setCreateDatabase("create");
-        jdbc.setDataSource(dataSource);
         jdbc.deleteAllMessages();
         broker.setPersistenceAdapter(jdbc);
         broker.setUseVirtualTopics(false);

http://git-wip-us.apache.org/repos/asf/activemq/blob/165959e2/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCPersistenceAdapterTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCPersistenceAdapterTest.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCPersistenceAdapterTest.java
index ce539d2..116e955 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCPersistenceAdapterTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCPersistenceAdapterTest.java
@@ -22,7 +22,6 @@ import junit.framework.AssertionFailedError;
 
 import org.apache.activemq.store.PersistenceAdapter;
 import org.apache.activemq.store.PersistenceAdapterTestSupport;
-import org.apache.derby.jdbc.EmbeddedDataSource;
 
 public class JDBCPersistenceAdapterTest extends PersistenceAdapterTestSupport {
     
@@ -35,11 +34,6 @@ public class JDBCPersistenceAdapterTest extends PersistenceAdapterTestSupport
{
         
         brokerService.setSchedulerSupport(false);
         brokerService.setPersistenceAdapter(jdbc);
-        jdbc.setBrokerService(brokerService);
-        EmbeddedDataSource dataSource = new EmbeddedDataSource();
-        dataSource.setDatabaseName("derbyDb");
-        dataSource.setCreateDatabase("create");
-        jdbc.setDataSource(dataSource);
         if( delete ) {
             jdbc.deleteAllMessages();
         }

http://git-wip-us.apache.org/repos/asf/activemq/blob/165959e2/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCStoreAutoCommitTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCStoreAutoCommitTest.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCStoreAutoCommitTest.java
index b9e6e98..a3f571f 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCStoreAutoCommitTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCStoreAutoCommitTest.java
@@ -47,6 +47,7 @@ import javax.jms.MessageProducer;
 import javax.jms.Session;
 import javax.jms.TextMessage;
 
+import javax.sql.DataSource;
 import org.apache.activemq.ActiveMQConnection;
 import org.apache.activemq.ActiveMQConnectionFactory;
 import org.apache.activemq.broker.BrokerService;
@@ -137,22 +138,21 @@ public class JDBCStoreAutoCommitTest {
             c1.close();
             broker.stop();
             broker.waitUntilStopped();
+            if (realDataSource != null) {
+                DataSourceServiceSupport.shutdownDefaultDataSource(realDataSource);
+            }
         }
     }
 
+    DataSource realDataSource;
     private BrokerService createBrokerService() throws IOException {
         BrokerService broker = new BrokerService();
         broker.setBrokerName(BROKER_NAME);
         broker.setUseJmx(false);
 
         JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter();
-        EmbeddedDataSource embeddedDataSource = new EmbeddedDataSource();
-        embeddedDataSource.setDatabaseName("derbyDb");
-        embeddedDataSource.setCreateDatabase("create");
-
-        javax.sql.DataSource wrappedDataSource = new TestDataSource(embeddedDataSource);
-
-        jdbc.setDataSource(wrappedDataSource);
+        realDataSource = jdbc.getDataSource();
+        jdbc.setDataSource(new TestDataSource(realDataSource));
 
         broker.setPersistenceAdapter(jdbc);
         return broker;

http://git-wip-us.apache.org/repos/asf/activemq/blob/165959e2/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCStoreBrokerTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCStoreBrokerTest.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCStoreBrokerTest.java
index 6e78927..c19516f 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCStoreBrokerTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCStoreBrokerTest.java
@@ -27,24 +27,14 @@ public class JDBCStoreBrokerTest extends BrokerTest {
     protected BrokerService createBroker() throws Exception {
         BrokerService broker = new BrokerService();
         JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter();
-        EmbeddedDataSource dataSource = new EmbeddedDataSource();
-        dataSource.setDatabaseName("derbyDb");
-        dataSource.setCreateDatabase("create");
-        jdbc.setDataSource(dataSource);
-        
         jdbc.deleteAllMessages();
         broker.setPersistenceAdapter(jdbc);
         return broker;
     }
     
-    protected BrokerService createRestartedBroker() throws Exception {
+    protected BrokerService x_createRestartedBroker() throws Exception {
         BrokerService broker = new BrokerService();
-        JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter();
-        EmbeddedDataSource dataSource = new EmbeddedDataSource();
-        dataSource.setDatabaseName("derbyDb");
-        dataSource.setCreateDatabase("create");
-        jdbc.setDataSource(dataSource);
-        broker.setPersistenceAdapter(jdbc);
+        broker.setPersistenceAdapter(new JDBCPersistenceAdapter());
         return broker;
     }
     

http://git-wip-us.apache.org/repos/asf/activemq/blob/165959e2/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCStoreOrderTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCStoreOrderTest.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCStoreOrderTest.java
index 4d3ac55..dd9c541 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCStoreOrderTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCStoreOrderTest.java
@@ -52,12 +52,7 @@ public class JDBCStoreOrderTest extends StoreOrderTest {
      @Override
      protected void setPersistentAdapter(BrokerService brokerService)
              throws Exception {
-        JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter();
-        EmbeddedDataSource dataSource = new EmbeddedDataSource();
-        dataSource.setDatabaseName("derbyDb");
-        dataSource.setCreateDatabase("create");
-        jdbc.setDataSource(dataSource);
-        brokerService.setPersistenceAdapter(jdbc);
+        brokerService.setPersistenceAdapter(new JDBCPersistenceAdapter());
     }
 
 }

http://git-wip-us.apache.org/repos/asf/activemq/blob/165959e2/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCTablePrefixAssignedTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCTablePrefixAssignedTest.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCTablePrefixAssignedTest.java
index 06f623f..4484c17 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCTablePrefixAssignedTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCTablePrefixAssignedTest.java
@@ -112,10 +112,6 @@ public class JDBCTablePrefixAssignedTest {
     protected BrokerService createBroker() throws Exception {
         BrokerService broker = new BrokerService();
         JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter();
-        EmbeddedDataSource dataSource = new EmbeddedDataSource();
-        dataSource.setDatabaseName("derbyDb");
-        dataSource.setCreateDatabase("create");
-
         DefaultJDBCAdapter adapter = new DefaultJDBCAdapter();
         jdbc.setAdapter(adapter);
 
@@ -124,7 +120,6 @@ public class JDBCTablePrefixAssignedTest {
         jdbc.setStatements(statements);
 
         jdbc.setUseLock(false);
-        jdbc.setDataSource(dataSource);
         jdbc.deleteAllMessages();
         broker.setPersistenceAdapter(jdbc);
         return broker;

http://git-wip-us.apache.org/repos/asf/activemq/blob/165959e2/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCTestMemory.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCTestMemory.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCTestMemory.java
index e8bda07..7ed3eb0 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCTestMemory.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCTestMemory.java
@@ -53,11 +53,6 @@ public class JDBCTestMemory extends TestCase {
         BrokerService broker = new BrokerService();
         broker.setUseJmx(true);
         JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter();
-        EmbeddedDataSource dataSource = new EmbeddedDataSource();
-        dataSource.setDatabaseName("derbyDb");
-        dataSource.setCreateDatabase("create");
-        jdbc.setDataSource(dataSource);
-        
         jdbc.deleteAllMessages();
         broker.setPersistenceAdapter(jdbc);
         broker.addConnector("tcp://0.0.0.0:61616");
@@ -68,10 +63,6 @@ public class JDBCTestMemory extends TestCase {
         BrokerService broker = new BrokerService();
         broker.setUseJmx(true);
         JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter();
-        EmbeddedDataSource dataSource = new EmbeddedDataSource();
-        dataSource.setDatabaseName("derbyDb");
-        dataSource.setCreateDatabase("create");
-        jdbc.setDataSource(dataSource);
         broker.setPersistenceAdapter(jdbc);
         broker.addConnector("tcp://0.0.0.0:61616");
         return broker;

http://git-wip-us.apache.org/repos/asf/activemq/blob/165959e2/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/LeaseDatabaseLockerTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/LeaseDatabaseLockerTest.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/LeaseDatabaseLockerTest.java
index 774d172..9d69f95 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/LeaseDatabaseLockerTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/LeaseDatabaseLockerTest.java
@@ -27,6 +27,7 @@ import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
+import javax.sql.DataSource;
 import org.apache.activemq.broker.AbstractLocker;
 import org.apache.activemq.broker.BrokerService;
 import org.apache.activemq.store.jdbc.adapter.DefaultJDBCAdapter;
@@ -35,6 +36,7 @@ import org.apache.derby.jdbc.EmbeddedDataSource;
 import org.jmock.Expectations;
 import org.jmock.Mockery;
 import org.jmock.lib.legacy.ClassImposteriser;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.slf4j.Logger;
@@ -51,20 +53,22 @@ public class LeaseDatabaseLockerTest {
 
     JDBCPersistenceAdapter jdbc;
     BrokerService brokerService;
-    EmbeddedDataSource dataSource;
+    DataSource dataSource;
 
     @Before
     public void setUpStore() throws Exception {
-        dataSource = new EmbeddedDataSource();
-        dataSource.setDatabaseName("derbyDb");
-        dataSource.setCreateDatabase("create");
         jdbc = new JDBCPersistenceAdapter();
-        jdbc.setDataSource(dataSource);
+        dataSource = jdbc.getDataSource();
         brokerService = new BrokerService();
         jdbc.setBrokerService(brokerService);
         jdbc.getAdapter().doCreateTables(jdbc.getTransactionContext());
     }
 
+    @After
+    public void stopDerby() {
+        DataSourceServiceSupport.shutdownDefaultDataSource(dataSource);
+    }
+
     @Test
     public void testLockInterleave() throws Exception {
 

http://git-wip-us.apache.org/repos/asf/activemq/blob/165959e2/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/JDBCDurableSubscriptionTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/JDBCDurableSubscriptionTest.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/JDBCDurableSubscriptionTest.java
index 33afc85..bc4215d 100755
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/JDBCDurableSubscriptionTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/JDBCDurableSubscriptionTest.java
@@ -29,10 +29,6 @@ public class JDBCDurableSubscriptionTest extends DurableSubscriptionTestSupport
 
     protected PersistenceAdapter createPersistenceAdapter() throws IOException {
         JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter();
-        EmbeddedDataSource dataSource = new EmbeddedDataSource();
-        dataSource.setDatabaseName("derbyDb");
-        dataSource.setCreateDatabase("create");
-        jdbc.setDataSource(dataSource);
         jdbc.setCleanupPeriod(1000); // set up small cleanup period
         return jdbc;
     }


Mime
View raw message