mirror of https://github.com/apache/activemq.git
bring some more consistency to derby usage and log nested exceptions on create failure
This commit is contained in:
parent
6cf9a8a9a5
commit
38f7857533
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -108,11 +108,15 @@ public class NetworkBrokerDetachTest {
|
|||
|
||||
@After
|
||||
public void cleanup() throws Exception {
|
||||
networkedBroker.stop();
|
||||
networkedBroker.waitUntilStopped();
|
||||
if (networkedBroker != null) {
|
||||
networkedBroker.stop();
|
||||
networkedBroker.waitUntilStopped();
|
||||
}
|
||||
|
||||
broker.stop();
|
||||
broker.waitUntilStopped();
|
||||
if (broker != null) {
|
||||
broker.stop();
|
||||
broker.waitUntilStopped();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -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());
|
||||
dataSource.getConnection().close(); // ensure derby for brokerName is initialized
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue