tidy up a bunch of jdbc test cases to ensure embedded derby is shutdown

This commit is contained in:
gtully 2015-04-23 13:12:49 +01:00
parent 971ff0dd9e
commit 165959e250
23 changed files with 80 additions and 129 deletions

View File

@ -18,6 +18,7 @@ package org.apache.activemq.store.jdbc;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.sql.SQLException;
import javax.sql.DataSource; import javax.sql.DataSource;
@ -36,6 +37,7 @@ abstract public class DataSourceServiceSupport extends LockableServiceSupport {
private String dataDirectory = IOHelper.getDefaultDataDirectory(); private String dataDirectory = IOHelper.getDefaultDataDirectory();
private File dataDirectoryFile; private File dataDirectoryFile;
private DataSource dataSource; private DataSource dataSource;
private DataSource createdDefaultDataSource;
public DataSourceServiceSupport() { public DataSourceServiceSupport() {
} }
@ -68,11 +70,19 @@ abstract public class DataSourceServiceSupport extends LockableServiceSupport {
dataSource = createDataSource(getDataDirectoryFile().getCanonicalPath()); dataSource = createDataSource(getDataDirectoryFile().getCanonicalPath());
if (dataSource == null) { if (dataSource == null) {
throw new IllegalArgumentException("No dataSource property has been configured"); throw new IllegalArgumentException("No dataSource property has been configured");
} else {
createdDefaultDataSource = dataSource;
} }
} }
return dataSource; return dataSource;
} }
public void closeDataSource(DataSource dataSource) {
if (createdDefaultDataSource != null && createdDefaultDataSource.equals(dataSource)) {
shutdownDefaultDataSource(dataSource);
}
}
public void setDataSource(DataSource dataSource) { public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource; this.dataSource = dataSource;
} }
@ -90,6 +100,15 @@ abstract public class DataSourceServiceSupport extends LockableServiceSupport {
return ds; 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() { public String toString() {
return "" + dataSource; return "" + dataSource;
} }

View File

@ -143,7 +143,7 @@ public class DefaultDatabaseLocker extends AbstractJDBCLocker {
try { try {
connection.rollback(); connection.rollback();
} catch (SQLException sqle) { } 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 { } finally {
try { try {
connection.close(); connection.close();

View File

@ -336,6 +336,7 @@ public class JDBCPersistenceAdapter extends DataSourceServiceSupport implements
cleanupTicket.cancel(true); cleanupTicket.cancel(true);
cleanupTicket = null; cleanupTicket = null;
} }
closeDataSource(getDataSource());
} }
public void cleanup() { public void cleanup() {
@ -408,15 +409,14 @@ public class JDBCPersistenceAdapter extends DataSourceServiceSupport implements
throw new IllegalArgumentException( throw new IllegalArgumentException(
"No dataSource property has been configured"); "No dataSource property has been configured");
} }
} else {
LOG.info("Using a separate dataSource for locking: "
+ lockDataSource);
} }
return lockDataSource; return lockDataSource;
} }
public void setLockDataSource(DataSource dataSource) { public void setLockDataSource(DataSource dataSource) {
this.lockDataSource = dataSource; this.lockDataSource = dataSource;
LOG.info("Using a separate dataSource for locking: "
+ lockDataSource);
} }
@Override @Override

View File

@ -63,11 +63,6 @@ public class AMQ4351Test extends BrokerTestSupport {
System.setProperty("derby.system.home", new File(IOHelper.getDefaultDataDirectory()).getCanonicalPath()); System.setProperty("derby.system.home", new File(IOHelper.getDefaultDataDirectory()).getCanonicalPath());
JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter(); JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter();
EmbeddedDataSource dataSource = new EmbeddedDataSource();
dataSource.setDatabaseName("derbyDb");
dataSource.setCreateDatabase("create");
jdbc.setDataSource(dataSource);
jdbc.deleteAllMessages(); jdbc.deleteAllMessages();
broker.setPersistenceAdapter(jdbc); broker.setPersistenceAdapter(jdbc);
return broker; return broker;

View File

@ -33,6 +33,7 @@ import org.apache.activemq.store.jdbc.JDBCPersistenceAdapter;
import org.apache.activemq.util.DefaultIOExceptionHandler; import org.apache.activemq.util.DefaultIOExceptionHandler;
import org.apache.activemq.util.IOHelper; import org.apache.activemq.util.IOHelper;
import org.apache.derby.jdbc.EmbeddedDataSource; import org.apache.derby.jdbc.EmbeddedDataSource;
import org.junit.After;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -79,6 +80,10 @@ public class DbRestartJDBCQueueTest extends JmsTopicSendReceiveWithTwoConnection
broker.stop(); broker.stop();
} }
@After
public void shutDownDerby() {
DataSourceServiceSupport.shutdownDefaultDataSource(sharedDs);
}
protected Session createSendSession(Connection sendConnection) throws Exception { protected Session createSendSession(Connection sendConnection) throws Exception {
if (transactedSends) { if (transactedSends) {

View File

@ -35,7 +35,7 @@ import org.apache.activemq.util.IOHelper;
import org.apache.derby.jdbc.EmbeddedDataSource; import org.apache.derby.jdbc.EmbeddedDataSource;
public class JDBCQueueMasterSlaveTest extends QueueMasterSlaveTestSupport { public class JDBCQueueMasterSlaveTest extends QueueMasterSlaveTestSupport {
protected DataSource sharedDs; protected SyncCreateDataSource sharedDs;
protected String MASTER_URL = "tcp://localhost:62001"; protected String MASTER_URL = "tcp://localhost:62001";
protected String SLAVE_URL = "tcp://localhost:62002"; protected String SLAVE_URL = "tcp://localhost:62002";
@ -45,6 +45,11 @@ public class JDBCQueueMasterSlaveTest extends QueueMasterSlaveTestSupport {
super.setUp(); super.setUp();
} }
protected void tearDown() throws Exception {
super.tearDown();
DataSourceServiceSupport.shutdownDefaultDataSource(sharedDs.delegate);
}
protected void createMaster() throws Exception { protected void createMaster() throws Exception {
master = new BrokerService(); master = new BrokerService();
master.setBrokerName("master"); master.setBrokerName("master");

View File

@ -78,15 +78,8 @@ public class AMQ4636Test {
broker.stop(); broker.stop();
broker.waitUntilStopped(); broker.waitUntilStopped();
} }
try { if (embeddedDataSource != null) {
if (embeddedDataSource != null) { DataSourceServiceSupport.shutdownDefaultDataSource(embeddedDataSource);
// 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);
} }
} }

View File

@ -55,6 +55,7 @@ import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ActiveMQQueue; import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.network.ConditionalNetworkBridgeFilterFactory; import org.apache.activemq.network.ConditionalNetworkBridgeFilterFactory;
import org.apache.activemq.network.NetworkConnector; import org.apache.activemq.network.NetworkConnector;
import org.apache.activemq.store.jdbc.DataSourceServiceSupport;
import org.apache.activemq.store.jdbc.JDBCPersistenceAdapter; import org.apache.activemq.store.jdbc.JDBCPersistenceAdapter;
import org.apache.activemq.util.IOHelper; import org.apache.activemq.util.IOHelper;
import org.apache.activemq.util.IntrospectionSupport; import org.apache.activemq.util.IntrospectionSupport;
@ -275,13 +276,19 @@ public class AMQ4952Test {
protected void doTearDown() throws Exception { protected void doTearDown() throws Exception {
DataSource dataSource = ((JDBCPersistenceAdapter)producerBroker.getPersistenceAdapter()).getDataSource();
try { try {
producerBroker.stop(); producerBroker.stop();
} catch (Exception ex) { } catch (Exception ex) {
} finally {
DataSourceServiceSupport.shutdownDefaultDataSource(dataSource);
} }
dataSource = ((JDBCPersistenceAdapter)consumerBroker.getPersistenceAdapter()).getDataSource();
try { try {
consumerBroker.stop(); consumerBroker.stop();
} catch (Exception ex) { } catch (Exception ex) {
} finally {
DataSourceServiceSupport.shutdownDefaultDataSource(dataSource);
} }
} }

View File

@ -73,7 +73,6 @@ public class TrapMessageInJDBCStoreTest extends TestCase {
broker.setUseJmx(withJMX); broker.setUseJmx(withJMX);
EmbeddedDataSource embeddedDataSource = (EmbeddedDataSource) DataSourceServiceSupport.createDataSource(IOHelper.getDefaultDataDirectory()); EmbeddedDataSource embeddedDataSource = (EmbeddedDataSource) DataSourceServiceSupport.createDataSource(IOHelper.getDefaultDataDirectory());
embeddedDataSource.setCreateDatabase("create");
//wire in a TestTransactionContext (wrapper to TransactionContext) that has an executeBatch() //wire in a TestTransactionContext (wrapper to TransactionContext) that has an executeBatch()
// method that can be configured to throw a SQL exception on demand // method that can be configured to throw a SQL exception on demand

View File

@ -563,7 +563,7 @@ abstract public class MessagePriorityTest extends CombinationTestSupport {
} }
public void testQueueBacklog() throws Exception { public void testQueueBacklog() throws Exception {
final int backlog = 180000; final int backlog = 18000;
ActiveMQQueue queue = (ActiveMQQueue)sess.createQueue("TEST"); ActiveMQQueue queue = (ActiveMQQueue)sess.createQueue("TEST");
ProducerThread lowPri = new ProducerThread(queue, backlog, LOW_PRI); ProducerThread lowPri = new ProducerThread(queue, backlog, LOW_PRI);

View File

@ -47,8 +47,6 @@ public class JDBCCommitExceptionTest extends TestCase {
protected ActiveMQConnectionFactory factory; protected ActiveMQConnectionFactory factory;
protected BrokerService broker; protected BrokerService broker;
protected String connectionUri; protected String connectionUri;
protected EmbeddedDataSource dataSource;
protected java.sql.Connection dbConnection;
protected BrokenPersistenceAdapter jdbc; protected BrokenPersistenceAdapter jdbc;
@Override @Override
@ -155,11 +153,6 @@ public class JDBCCommitExceptionTest extends TestCase {
BrokerService broker = new BrokerService(); BrokerService broker = new BrokerService();
jdbc = new BrokenPersistenceAdapter(); jdbc = new BrokenPersistenceAdapter();
dataSource = new EmbeddedDataSource();
dataSource.setDatabaseName("target/derbyDb");
dataSource.setCreateDatabase("create");
jdbc.setDataSource(dataSource);
jdbc.setUseLock(false); jdbc.setUseLock(false);
jdbc.deleteAllMessages(); jdbc.deleteAllMessages();

View File

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

View File

@ -34,6 +34,7 @@ import javax.jms.Session;
import javax.jms.TextMessage; import javax.jms.TextMessage;
import javax.jms.TopicSubscriber; import javax.jms.TopicSubscriber;
import javax.sql.DataSource;
import junit.framework.Test; import junit.framework.Test;
import org.apache.activemq.command.ActiveMQMessage; import org.apache.activemq.command.ActiveMQMessage;
@ -48,39 +49,19 @@ import org.slf4j.LoggerFactory;
public class JDBCMessagePriorityTest extends MessagePriorityTest { public class JDBCMessagePriorityTest extends MessagePriorityTest {
private static final Logger LOG = LoggerFactory.getLogger(JDBCMessagePriorityTest.class); private static final Logger LOG = LoggerFactory.getLogger(JDBCMessagePriorityTest.class);
EmbeddedDataSource dataSource; DataSource dataSource;
JDBCPersistenceAdapter jdbc; JDBCPersistenceAdapter jdbc;
@Override @Override
protected PersistenceAdapter createPersistenceAdapter(boolean delete) throws Exception { protected PersistenceAdapter createPersistenceAdapter(boolean delete) throws Exception {
jdbc = new JDBCPersistenceAdapter(); jdbc = new JDBCPersistenceAdapter();
dataSource = new EmbeddedDataSource(); dataSource = jdbc.getDataSource();
dataSource.setDatabaseName("derbyDb");
dataSource.setCreateDatabase("create");
dataSource.setShutdownDatabase(null);
jdbc.setDataSource(dataSource);
jdbc.deleteAllMessages(); jdbc.deleteAllMessages();
jdbc.setCleanupPeriod(2000); jdbc.setCleanupPeriod(2000);
return jdbc; 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 // this cannot be a general test as kahaDB just has support for 3 priority levels
public void testDurableSubsReconnectWithFourLevels() throws Exception { public void testDurableSubsReconnectWithFourLevels() throws Exception {
ActiveMQTopic topic = (ActiveMQTopic) sess.createTopic("TEST"); ActiveMQTopic topic = (ActiveMQTopic) sess.createTopic("TEST");

View File

@ -35,7 +35,6 @@ public class JDBCNegativeQueueTest extends NegativeQueueTest {
protected void configureBroker(BrokerService answer) throws Exception { protected void configureBroker(BrokerService answer) throws Exception {
super.configureBroker(answer); super.configureBroker(answer);
JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter(); JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter();
jdbc.setDataSource(dataSource);
answer.setPersistenceAdapter(jdbc); answer.setPersistenceAdapter(jdbc);
dataSource = jdbc.getDataSource(); dataSource = jdbc.getDataSource();
} }

View File

@ -24,10 +24,8 @@ public class JDBCNetworkBrokerDetachTest extends NetworkBrokerDetachTest {
protected void configureBroker(BrokerService broker) throws Exception { protected void configureBroker(BrokerService broker) throws Exception {
JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter(); JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter();
EmbeddedDataSource dataSource = new EmbeddedDataSource(); EmbeddedDataSource dataSource = (EmbeddedDataSource) jdbc.getDataSource();
dataSource.setDatabaseName(broker.getBrokerName()); dataSource.setDatabaseName(broker.getBrokerName());
dataSource.setCreateDatabase("create");
jdbc.setDataSource(dataSource);
jdbc.deleteAllMessages(); jdbc.deleteAllMessages();
broker.setPersistenceAdapter(jdbc); broker.setPersistenceAdapter(jdbc);
broker.setUseVirtualTopics(false); broker.setUseVirtualTopics(false);

View File

@ -22,7 +22,6 @@ import junit.framework.AssertionFailedError;
import org.apache.activemq.store.PersistenceAdapter; import org.apache.activemq.store.PersistenceAdapter;
import org.apache.activemq.store.PersistenceAdapterTestSupport; import org.apache.activemq.store.PersistenceAdapterTestSupport;
import org.apache.derby.jdbc.EmbeddedDataSource;
public class JDBCPersistenceAdapterTest extends PersistenceAdapterTestSupport { public class JDBCPersistenceAdapterTest extends PersistenceAdapterTestSupport {
@ -35,11 +34,6 @@ public class JDBCPersistenceAdapterTest extends PersistenceAdapterTestSupport {
brokerService.setSchedulerSupport(false); brokerService.setSchedulerSupport(false);
brokerService.setPersistenceAdapter(jdbc); brokerService.setPersistenceAdapter(jdbc);
jdbc.setBrokerService(brokerService);
EmbeddedDataSource dataSource = new EmbeddedDataSource();
dataSource.setDatabaseName("derbyDb");
dataSource.setCreateDatabase("create");
jdbc.setDataSource(dataSource);
if( delete ) { if( delete ) {
jdbc.deleteAllMessages(); jdbc.deleteAllMessages();
} }

View File

@ -47,6 +47,7 @@ import javax.jms.MessageProducer;
import javax.jms.Session; import javax.jms.Session;
import javax.jms.TextMessage; import javax.jms.TextMessage;
import javax.sql.DataSource;
import org.apache.activemq.ActiveMQConnection; import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.BrokerService;
@ -137,22 +138,21 @@ public class JDBCStoreAutoCommitTest {
c1.close(); c1.close();
broker.stop(); broker.stop();
broker.waitUntilStopped(); broker.waitUntilStopped();
if (realDataSource != null) {
DataSourceServiceSupport.shutdownDefaultDataSource(realDataSource);
}
} }
} }
DataSource realDataSource;
private BrokerService createBrokerService() throws IOException { private BrokerService createBrokerService() throws IOException {
BrokerService broker = new BrokerService(); BrokerService broker = new BrokerService();
broker.setBrokerName(BROKER_NAME); broker.setBrokerName(BROKER_NAME);
broker.setUseJmx(false); broker.setUseJmx(false);
JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter(); JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter();
EmbeddedDataSource embeddedDataSource = new EmbeddedDataSource(); realDataSource = jdbc.getDataSource();
embeddedDataSource.setDatabaseName("derbyDb"); jdbc.setDataSource(new TestDataSource(realDataSource));
embeddedDataSource.setCreateDatabase("create");
javax.sql.DataSource wrappedDataSource = new TestDataSource(embeddedDataSource);
jdbc.setDataSource(wrappedDataSource);
broker.setPersistenceAdapter(jdbc); broker.setPersistenceAdapter(jdbc);
return broker; return broker;

View File

@ -27,24 +27,14 @@ public class JDBCStoreBrokerTest extends BrokerTest {
protected BrokerService createBroker() throws Exception { protected BrokerService createBroker() throws Exception {
BrokerService broker = new BrokerService(); BrokerService broker = new BrokerService();
JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter(); JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter();
EmbeddedDataSource dataSource = new EmbeddedDataSource();
dataSource.setDatabaseName("derbyDb");
dataSource.setCreateDatabase("create");
jdbc.setDataSource(dataSource);
jdbc.deleteAllMessages(); jdbc.deleteAllMessages();
broker.setPersistenceAdapter(jdbc); broker.setPersistenceAdapter(jdbc);
return broker; return broker;
} }
protected BrokerService createRestartedBroker() throws Exception { protected BrokerService x_createRestartedBroker() throws Exception {
BrokerService broker = new BrokerService(); BrokerService broker = new BrokerService();
JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter(); broker.setPersistenceAdapter(new JDBCPersistenceAdapter());
EmbeddedDataSource dataSource = new EmbeddedDataSource();
dataSource.setDatabaseName("derbyDb");
dataSource.setCreateDatabase("create");
jdbc.setDataSource(dataSource);
broker.setPersistenceAdapter(jdbc);
return broker; return broker;
} }

View File

@ -52,12 +52,7 @@ public class JDBCStoreOrderTest extends StoreOrderTest {
@Override @Override
protected void setPersistentAdapter(BrokerService brokerService) protected void setPersistentAdapter(BrokerService brokerService)
throws Exception { throws Exception {
JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter(); brokerService.setPersistenceAdapter(new JDBCPersistenceAdapter());
EmbeddedDataSource dataSource = new EmbeddedDataSource();
dataSource.setDatabaseName("derbyDb");
dataSource.setCreateDatabase("create");
jdbc.setDataSource(dataSource);
brokerService.setPersistenceAdapter(jdbc);
} }
} }

View File

@ -112,10 +112,6 @@ public class JDBCTablePrefixAssignedTest {
protected BrokerService createBroker() throws Exception { protected BrokerService createBroker() throws Exception {
BrokerService broker = new BrokerService(); BrokerService broker = new BrokerService();
JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter(); JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter();
EmbeddedDataSource dataSource = new EmbeddedDataSource();
dataSource.setDatabaseName("derbyDb");
dataSource.setCreateDatabase("create");
DefaultJDBCAdapter adapter = new DefaultJDBCAdapter(); DefaultJDBCAdapter adapter = new DefaultJDBCAdapter();
jdbc.setAdapter(adapter); jdbc.setAdapter(adapter);
@ -124,7 +120,6 @@ public class JDBCTablePrefixAssignedTest {
jdbc.setStatements(statements); jdbc.setStatements(statements);
jdbc.setUseLock(false); jdbc.setUseLock(false);
jdbc.setDataSource(dataSource);
jdbc.deleteAllMessages(); jdbc.deleteAllMessages();
broker.setPersistenceAdapter(jdbc); broker.setPersistenceAdapter(jdbc);
return broker; return broker;

View File

@ -53,11 +53,6 @@ public class JDBCTestMemory extends TestCase {
BrokerService broker = new BrokerService(); BrokerService broker = new BrokerService();
broker.setUseJmx(true); broker.setUseJmx(true);
JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter(); JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter();
EmbeddedDataSource dataSource = new EmbeddedDataSource();
dataSource.setDatabaseName("derbyDb");
dataSource.setCreateDatabase("create");
jdbc.setDataSource(dataSource);
jdbc.deleteAllMessages(); jdbc.deleteAllMessages();
broker.setPersistenceAdapter(jdbc); broker.setPersistenceAdapter(jdbc);
broker.addConnector("tcp://0.0.0.0:61616"); broker.addConnector("tcp://0.0.0.0:61616");
@ -68,10 +63,6 @@ public class JDBCTestMemory extends TestCase {
BrokerService broker = new BrokerService(); BrokerService broker = new BrokerService();
broker.setUseJmx(true); broker.setUseJmx(true);
JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter(); JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter();
EmbeddedDataSource dataSource = new EmbeddedDataSource();
dataSource.setDatabaseName("derbyDb");
dataSource.setCreateDatabase("create");
jdbc.setDataSource(dataSource);
broker.setPersistenceAdapter(jdbc); broker.setPersistenceAdapter(jdbc);
broker.addConnector("tcp://0.0.0.0:61616"); broker.addConnector("tcp://0.0.0.0:61616");
return broker; return broker;

View File

@ -27,6 +27,7 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import javax.sql.DataSource;
import org.apache.activemq.broker.AbstractLocker; import org.apache.activemq.broker.AbstractLocker;
import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.store.jdbc.adapter.DefaultJDBCAdapter; 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.Expectations;
import org.jmock.Mockery; import org.jmock.Mockery;
import org.jmock.lib.legacy.ClassImposteriser; import org.jmock.lib.legacy.ClassImposteriser;
import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -51,20 +53,22 @@ public class LeaseDatabaseLockerTest {
JDBCPersistenceAdapter jdbc; JDBCPersistenceAdapter jdbc;
BrokerService brokerService; BrokerService brokerService;
EmbeddedDataSource dataSource; DataSource dataSource;
@Before @Before
public void setUpStore() throws Exception { public void setUpStore() throws Exception {
dataSource = new EmbeddedDataSource();
dataSource.setDatabaseName("derbyDb");
dataSource.setCreateDatabase("create");
jdbc = new JDBCPersistenceAdapter(); jdbc = new JDBCPersistenceAdapter();
jdbc.setDataSource(dataSource); dataSource = jdbc.getDataSource();
brokerService = new BrokerService(); brokerService = new BrokerService();
jdbc.setBrokerService(brokerService); jdbc.setBrokerService(brokerService);
jdbc.getAdapter().doCreateTables(jdbc.getTransactionContext()); jdbc.getAdapter().doCreateTables(jdbc.getTransactionContext());
} }
@After
public void stopDerby() {
DataSourceServiceSupport.shutdownDefaultDataSource(dataSource);
}
@Test @Test
public void testLockInterleave() throws Exception { public void testLockInterleave() throws Exception {

View File

@ -29,10 +29,6 @@ public class JDBCDurableSubscriptionTest extends DurableSubscriptionTestSupport
protected PersistenceAdapter createPersistenceAdapter() throws IOException { protected PersistenceAdapter createPersistenceAdapter() throws IOException {
JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter(); 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 jdbc.setCleanupPeriod(1000); // set up small cleanup period
return jdbc; return jdbc;
} }