activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtu...@apache.org
Subject [1/3] activemq git commit: bring some more consistency to derby usage and log nested exceptions on create failure
Date Wed, 17 Jun 2015 13:41:59 GMT
Repository: activemq
Updated Branches:
  refs/heads/master 471911466 -> d5c25c027


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


Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/38f78575
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/38f78575
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/38f78575

Branch: refs/heads/master
Commit: 38f7857533ecd71641b8d7f0075351972469cf2c
Parents: 6cf9a8a
Author: gtully <gary.tully@gmail.com>
Authored: Wed Jun 17 14:23:08 2015 +0100
Committer: gtully <gary.tully@gmail.com>
Committed: Wed Jun 17 14:30:25 2015 +0100

----------------------------------------------------------------------
 .../store/jdbc/DataSourceServiceSupport.java    |  6 +++-
 .../network/NetworkBrokerDetachTest.java        | 12 +++++---
 .../store/jdbc/JDBCNetworkBrokerDetachTest.java | 32 +++++++++++++++++---
 3 files changed, 41 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/38f78575/activemq-jdbc-store/src/main/java/org/apache/activemq/store/jdbc/DataSourceServiceSupport.java
----------------------------------------------------------------------
diff --git a/activemq-jdbc-store/src/main/java/org/apache/activemq/store/jdbc/DataSourceServiceSupport.java
b/activemq-jdbc-store/src/main/java/org/apache/activemq/store/jdbc/DataSourceServiceSupport.java
index 9790d3d..cf7cb0d 100644
--- a/activemq-jdbc-store/src/main/java/org/apache/activemq/store/jdbc/DataSourceServiceSupport.java
+++ b/activemq-jdbc-store/src/main/java/org/apache/activemq/store/jdbc/DataSourceServiceSupport.java
@@ -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;
     }

http://git-wip-us.apache.org/repos/asf/activemq/blob/38f78575/activemq-unit-tests/src/test/java/org/apache/activemq/network/NetworkBrokerDetachTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/network/NetworkBrokerDetachTest.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/network/NetworkBrokerDetachTest.java
index ceef43c..02f9a44 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/network/NetworkBrokerDetachTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/network/NetworkBrokerDetachTest.java
@@ -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

http://git-wip-us.apache.org/repos/asf/activemq/blob/38f78575/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCNetworkBrokerDetachTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCNetworkBrokerDetachTest.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCNetworkBrokerDetachTest.java
index 4881b2f..aa56862 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCNetworkBrokerDetachTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCNetworkBrokerDetachTest.java
@@ -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();
+    }
 }


Mime
View raw message