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

View File

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

View File

@ -16,19 +16,43 @@
*/
package org.apache.activemq.store.jdbc;
import java.sql.SQLException;
import java.util.LinkedList;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.network.NetworkBrokerDetachTest;
import org.apache.derby.jdbc.EmbeddedDataSource;
import org.junit.After;
public class JDBCNetworkBrokerDetachTest extends NetworkBrokerDetachTest {
LinkedList<EmbeddedDataSource> dataSources = new LinkedList<>();
protected void configureBroker(BrokerService broker) throws Exception {
JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter();
EmbeddedDataSource dataSource = (EmbeddedDataSource) jdbc.getDataSource();
dataSource.setDatabaseName(broker.getBrokerName());
try {
EmbeddedDataSource dataSource = (EmbeddedDataSource) DataSourceServiceSupport.createDataSource(jdbc.getDataDirectoryFile().getCanonicalPath(), broker.getBrokerName());
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.setUseVirtualTopics(false);
}
@After
public void shutdownDataSources() throws Exception {
for (EmbeddedDataSource ds: dataSources) {
DataSourceServiceSupport.shutdownDefaultDataSource(ds);
}
dataSources.clear();
}
}