bring some more consistency to derby usage and log nested exceptions on create failure

This commit is contained in:
gtully 2015-06-17 14:23:08 +01:00
parent 6cf9a8a9a5
commit 38f7857533
3 changed files with 41 additions and 9 deletions

View File

@ -89,6 +89,10 @@ abstract public class DataSourceServiceSupport extends LockableServiceSupport {
} }
public static DataSource createDataSource(String homeDir) throws IOException { public static DataSource createDataSource(String homeDir) throws IOException {
return createDataSource(homeDir, "derbydb");
}
public static DataSource createDataSource(String homeDir, String dbName) throws IOException {
// Setup the Derby datasource. // Setup the Derby datasource.
System.setProperty("derby.system.home", homeDir); System.setProperty("derby.system.home", homeDir);
@ -96,7 +100,7 @@ abstract public class DataSourceServiceSupport extends LockableServiceSupport {
System.setProperty("derby.storage.pageCacheSize", "100"); System.setProperty("derby.storage.pageCacheSize", "100");
final EmbeddedDataSource ds = new EmbeddedDataSource(); final EmbeddedDataSource ds = new EmbeddedDataSource();
ds.setDatabaseName("derbydb"); ds.setDatabaseName(dbName);
ds.setCreateDatabase("create"); ds.setCreateDatabase("create");
return ds; return ds;
} }

View File

@ -108,11 +108,15 @@ public class NetworkBrokerDetachTest {
@After @After
public void cleanup() throws Exception { public void cleanup() throws Exception {
networkedBroker.stop(); if (networkedBroker != null) {
networkedBroker.waitUntilStopped(); networkedBroker.stop();
networkedBroker.waitUntilStopped();
}
broker.stop(); if (broker != null) {
broker.waitUntilStopped(); broker.stop();
broker.waitUntilStopped();
}
} }
@Test @Test

View File

@ -16,19 +16,43 @@
*/ */
package org.apache.activemq.store.jdbc; package org.apache.activemq.store.jdbc;
import java.sql.SQLException;
import java.util.LinkedList;
import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.network.NetworkBrokerDetachTest; import org.apache.activemq.network.NetworkBrokerDetachTest;
import org.apache.derby.jdbc.EmbeddedDataSource; import org.apache.derby.jdbc.EmbeddedDataSource;
import org.junit.After;
public class JDBCNetworkBrokerDetachTest extends NetworkBrokerDetachTest { public class JDBCNetworkBrokerDetachTest extends NetworkBrokerDetachTest {
LinkedList<EmbeddedDataSource> dataSources = new LinkedList<>();
protected void configureBroker(BrokerService broker) throws Exception { protected void configureBroker(BrokerService broker) throws Exception {
JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter(); JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter();
EmbeddedDataSource dataSource = (EmbeddedDataSource) jdbc.getDataSource(); try {
dataSource.setDatabaseName(broker.getBrokerName()); EmbeddedDataSource dataSource = (EmbeddedDataSource) DataSourceServiceSupport.createDataSource(jdbc.getDataDirectoryFile().getCanonicalPath(), broker.getBrokerName());
dataSource.getConnection().close(); // ensure derby for brokerName is initialized dataSource.getConnection().close(); // ensure derby for brokerName is initialized
jdbc.setDataSource(dataSource);
dataSources.add(dataSource);
} catch (SQLException e) {
e.printStackTrace();
Exception n = e.getNextException();
while (n != null) {
n.printStackTrace();
if (n instanceof SQLException) {
n = ((SQLException) n).getNextException();
}
}
throw e;
}
broker.setPersistenceAdapter(jdbc); broker.setPersistenceAdapter(jdbc);
broker.setUseVirtualTopics(false); broker.setUseVirtualTopics(false);
} }
@After
public void shutdownDataSources() throws Exception {
for (EmbeddedDataSource ds: dataSources) {
DataSourceServiceSupport.shutdownDefaultDataSource(ds);
}
dataSources.clear();
}
} }