You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by gt...@apache.org on 2015/05/15 15:06:23 UTC
activemq git commit: tidy up derby usage - thread safe
creation/shutdown to avoid derby failures and db creation/shutdown sql
exceptions that leave db dir in inconsistent state
Repository: activemq
Updated Branches:
refs/heads/master 5e36f65e0 -> 6f1f06fb1
tidy up derby usage - thread safe creation/shutdown to avoid derby failures and db creation/shutdown sql exceptions that leave db dir in inconsistent state
Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/6f1f06fb
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/6f1f06fb
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/6f1f06fb
Branch: refs/heads/master
Commit: 6f1f06fb163ac5601b770284c5588e48faac6f11
Parents: 5e36f65
Author: gtully <ga...@gmail.com>
Authored: Fri May 15 14:06:04 2015 +0100
Committer: gtully <ga...@gmail.com>
Committed: Fri May 15 14:06:04 2015 +0100
----------------------------------------------------------------------
.../activemq/broker/ft/SyncCreateDataSource.java | 4 ++--
.../store/jdbc/JDBCIOExceptionHandlerTest.java | 17 +++++++++++------
2 files changed, 13 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/activemq/blob/6f1f06fb/activemq-unit-tests/src/test/java/org/apache/activemq/broker/ft/SyncCreateDataSource.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/ft/SyncCreateDataSource.java b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/ft/SyncCreateDataSource.java
index 5331a22..6b327af 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/ft/SyncCreateDataSource.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/ft/SyncCreateDataSource.java
@@ -30,7 +30,7 @@ import org.apache.derby.jdbc.EmbeddedDataSource;
public class SyncCreateDataSource implements DataSource {
final EmbeddedDataSource delegate;
- SyncCreateDataSource(EmbeddedDataSource dataSource) {
+ public SyncCreateDataSource(EmbeddedDataSource dataSource) {
this.delegate = dataSource;
}
@@ -76,7 +76,7 @@ public class SyncCreateDataSource implements DataSource {
return false;
}
- EmbeddedDataSource getDelegate() {
+ public EmbeddedDataSource getDelegate() {
return delegate;
}
http://git-wip-us.apache.org/repos/asf/activemq/blob/6f1f06fb/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCIOExceptionHandlerTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCIOExceptionHandlerTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCIOExceptionHandlerTest.java
index 20c6986..5144182 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCIOExceptionHandlerTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCIOExceptionHandlerTest.java
@@ -27,6 +27,7 @@ import javax.jms.Connection;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.broker.ft.SyncCreateDataSource;
import org.apache.activemq.util.IOHelper;
import org.apache.activemq.util.LeaseLockerIOExceptionHandler;
import org.apache.activemq.util.Wait;
@@ -77,7 +78,7 @@ public class JDBCIOExceptionHandlerTest {
EmbeddedDataSource embeddedDataSource = (EmbeddedDataSource) jdbc.getDataSource();
// create a wrapper to EmbeddedDataSource to allow the connection be
// reestablished to derby db
- dataSource = new ReconnectingEmbeddedDataSource(embeddedDataSource);
+ dataSource = new ReconnectingEmbeddedDataSource(new SyncCreateDataSource(embeddedDataSource));
jdbc.setDataSource(dataSource);
jdbc.setLockKeepAlivePeriod(1000l);
@@ -251,13 +252,12 @@ public class JDBCIOExceptionHandlerTest {
* Wrapped the derby datasource object to get DB reconnect functionality as I not
* manage to get that working directly on the EmbeddedDataSource
*
- * NOTE: Not a thread Safe but for this unit test it should be fine
*/
public class ReconnectingEmbeddedDataSource implements javax.sql.DataSource {
- private EmbeddedDataSource realDatasource;
+ private SyncCreateDataSource realDatasource;
- public ReconnectingEmbeddedDataSource(EmbeddedDataSource datasource) {
+ public ReconnectingEmbeddedDataSource(SyncCreateDataSource datasource) {
this.realDatasource = datasource;
}
@@ -313,12 +313,17 @@ public class JDBCIOExceptionHandlerTest {
(EmbeddedDataSource) DataSourceServiceSupport.createDataSource(broker.getDataDirectoryFile().getCanonicalPath());
newDatasource.getConnection();
LOG.info("*** DB restarted now...");
- this.realDatasource = newDatasource;
+ Object existingDataSource = realDatasource;
+ synchronized (existingDataSource) {
+ this.realDatasource = new SyncCreateDataSource(newDatasource);
+ }
}
public void stopDB() {
LOG.info("***DB is being shutdown...");
- DataSourceServiceSupport.shutdownDefaultDataSource(realDatasource);
+ synchronized (realDatasource) {
+ DataSourceServiceSupport.shutdownDefaultDataSource(realDatasource.getDelegate());
+ }
}
public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException {