resolve intermittent failure verifying connector restart

This commit is contained in:
gtully 2015-01-22 13:44:22 +00:00
parent 2a62b74232
commit c28d520727
1 changed files with 16 additions and 8 deletions

View File

@ -45,6 +45,7 @@ public class JDBCIOExceptionHandlerTest extends TestCase {
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;
@ -60,7 +61,7 @@ public class JDBCIOExceptionHandlerTest extends TestCase {
broker.setUseJmx(withJMX); broker.setUseJmx(withJMX);
EmbeddedDataSource embeddedDataSource = new EmbeddedDataSource(); EmbeddedDataSource embeddedDataSource = new EmbeddedDataSource();
embeddedDataSource.setDatabaseName("derbydb_15"); embeddedDataSource.setDatabaseName(DATABASE_NAME);
embeddedDataSource.setCreateDatabase("create"); embeddedDataSource.setCreateDatabase("create");
// create a wrapper to EmbeddedDataSource to allow the connection be // create a wrapper to EmbeddedDataSource to allow the connection be
@ -190,13 +191,20 @@ public class JDBCIOExceptionHandlerTest extends TestCase {
// restart db underneath // restart db underneath
dataSource.restartDB(); dataSource.restartDB();
// give the transport connector a moment to start Wait.waitFor(new Wait.Condition() {
LOG.debug("*** Waiting for connector to start..."); @Override
TimeUnit.SECONDS.sleep(3); public boolean isSatisified() throws Exception {
LOG.debug("*** checking connector to start...");
try {
checkTransportConnectorStarted();
return true;
} catch (Throwable t) {
LOG.debug(t.toString());
}
return false;
}
});
LOG.debug("*** checking connector to start...");
// check the connector has restarted
checkTransportConnectorStarted();
} finally { } finally {
LOG.debug("*** broker is stopping..."); LOG.debug("*** broker is stopping...");
@ -289,7 +297,7 @@ public class JDBCIOExceptionHandlerTest extends TestCase {
*/ */
public void restartDB() throws SQLException { public void restartDB() throws SQLException {
EmbeddedDataSource newDatasource = new EmbeddedDataSource(); EmbeddedDataSource newDatasource = new EmbeddedDataSource();
newDatasource.setDatabaseName(this.realDatasource.getDatabaseName()); newDatasource.setDatabaseName(DATABASE_NAME);
newDatasource.getConnection(); newDatasource.getConnection();
LOG.info("*** DB restarted now..."); LOG.info("*** DB restarted now...");
this.realDatasource = newDatasource; this.realDatasource = newDatasource;