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 00b249082b..31835ba794 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; } 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 d7a406a039..36497d1dde 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(); 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 4236e9d105..23b5cfacc6 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 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 ce7ed3d940..0b0e5ccaac 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; 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 9b21c441ea..6064efb666 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) { 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 c7b0ec6980..0547b7c895 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"); 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 014d86a525..9b397b0e8c 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); } } 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 dd26e81916..cc16b75647 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); } } 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 688d066d2a..c07364660a 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 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 521c8991ea..c6b63245ab 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); 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 e183553642..05e72087ad 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(); 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 6ad2f0357b..20c69865e6 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 { 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 34796a4a3b..de171fc2da 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"); 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 0a2ca1dd50..52c512909f 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(); } 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 409b20f0eb..8a011fcb53 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); 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 ce539d2381..116e9552d4 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(); } 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 b9e6e98bdd..a3f571f921 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; 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 6e78927cd4..c19516f550 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; } 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 4d3ac55953..dd9c541d6a 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()); } } 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 06f623f25d..4484c17d7f 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; 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 e8bda0786c..7ed3eb0236 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; 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 774d172bb1..9d69f953b9 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 { 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 33afc85a9e..bc4215d06e 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; }