From c6837acefe8ca466d8cd9b3bd9adf297372b65b8 Mon Sep 17 00:00:00 2001 From: gtully Date: Mon, 9 Feb 2015 12:29:52 +0000 Subject: [PATCH] tidy up some jdbc directory usage - move into target --- .../java/org/apache/activemq/TestSupport.java | 1 + .../apache/activemq/broker/AMQ4351Test.java | 4 ++++ .../broker/JdbcXARecoveryBrokerTest.java | 3 +++ .../org/apache/activemq/bugs/AMQ4952Test.java | 8 +++++++ .../jdbc/JDBCIOExceptionHandlerTest.java | 21 ++++++++++++++++--- .../store/jdbc/JDBCNegativeQueueTest.java | 9 ++++---- 6 files changed, 38 insertions(+), 8 deletions(-) diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/TestSupport.java b/activemq-unit-tests/src/test/java/org/apache/activemq/TestSupport.java index 80aac149d9..26af5963e0 100755 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/TestSupport.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/TestSupport.java @@ -196,6 +196,7 @@ public abstract class TestSupport extends CombinationTestSupport { break; } broker.setPersistenceAdapter(adapter); + adapter.setDirectory(broker.getBrokerDataDirectory()); return adapter; } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/AMQ4351Test.java b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/AMQ4351Test.java index e810f920de..ce7ed3d940 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/AMQ4351Test.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/AMQ4351Test.java @@ -20,12 +20,14 @@ import junit.framework.Test; import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.command.ActiveMQTopic; import org.apache.activemq.store.jdbc.JDBCPersistenceAdapter; +import org.apache.activemq.util.IOHelper; import org.apache.derby.jdbc.EmbeddedDataSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.jms.Connection; import javax.jms.*; +import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.concurrent.CountDownLatch; @@ -58,6 +60,8 @@ public class AMQ4351Test extends BrokerTestSupport { broker.setOfflineDurableSubscriberTaskSchedule(500); broker.setOfflineDurableSubscriberTimeout(2000); // lets delete durable subs much faster. + System.setProperty("derby.system.home", new File(IOHelper.getDefaultDataDirectory()).getCanonicalPath()); + JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter(); EmbeddedDataSource dataSource = new EmbeddedDataSource(); dataSource.setDatabaseName("derbyDb"); diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/JdbcXARecoveryBrokerTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/JdbcXARecoveryBrokerTest.java index 5788dadf11..35b944a893 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/JdbcXARecoveryBrokerTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/JdbcXARecoveryBrokerTest.java @@ -16,10 +16,12 @@ */ package org.apache.activemq.broker; +import java.io.File; import junit.framework.Test; import org.apache.activemq.command.ActiveMQDestination; import org.apache.activemq.command.ActiveMQQueue; import org.apache.activemq.store.jdbc.JDBCPersistenceAdapter; +import org.apache.activemq.util.IOHelper; import org.apache.derby.jdbc.EmbeddedDataSource; import org.apache.derby.jdbc.EmbeddedXADataSource; @@ -29,6 +31,7 @@ public class JdbcXARecoveryBrokerTest extends XARecoveryBrokerTest { @Override protected void setUp() throws Exception { + System.setProperty("derby.system.home", new File(IOHelper.getDefaultDataDirectory()).getCanonicalPath()); dataSource = new EmbeddedXADataSource(); dataSource.setDatabaseName("derbyDb"); dataSource.setCreateDatabase("create"); diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ4952Test.java b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ4952Test.java index 6a52e46bba..dd26e81916 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ4952Test.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ4952Test.java @@ -17,6 +17,7 @@ package org.apache.activemq.bugs; +import java.io.File; import java.net.URI; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -55,11 +56,13 @@ import org.apache.activemq.command.ActiveMQQueue; import org.apache.activemq.network.ConditionalNetworkBridgeFilterFactory; import org.apache.activemq.network.NetworkConnector; import org.apache.activemq.store.jdbc.JDBCPersistenceAdapter; +import org.apache.activemq.util.IOHelper; import org.apache.activemq.util.IntrospectionSupport; import org.apache.activemq.util.Wait; import org.apache.derby.jdbc.EmbeddedDataSource; import org.junit.After; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -125,6 +128,11 @@ public class AMQ4952Test { return Arrays.asList(new Object[][] { { Boolean.TRUE }, { Boolean.FALSE } }); } + @BeforeClass + public static void dbHomeSysProp() throws Exception { + System.setProperty("derby.system.home", new File(IOHelper.getDefaultDataDirectory()).getCanonicalPath()); + } + @Test public void testConsumerBrokerRestart() throws Exception { 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 df10d73e89..e95bcbd096 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 @@ -16,6 +16,7 @@ */ package org.apache.activemq.store.jdbc; +import java.io.File; import java.io.PrintWriter; import java.sql.SQLException; import java.sql.SQLFeatureNotSupportedException; @@ -24,23 +25,28 @@ import java.util.concurrent.atomic.AtomicReference; import javax.jms.Connection; -import junit.framework.TestCase; - import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.util.IOHelper; import org.apache.activemq.util.LeaseLockerIOExceptionHandler; import org.apache.activemq.util.Wait; import org.apache.derby.jdbc.EmbeddedDataSource; +import org.junit.Before; +import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + +import static junit.framework.Assert.assertTrue; +import static junit.framework.Assert.fail; + /** * Test to see if the JDBCExceptionIOHandler will restart the transport connectors correctly after * the underlying DB has been stopped and restarted * * see AMQ-4575 */ -public class JDBCIOExceptionHandlerTest extends TestCase { +public class JDBCIOExceptionHandlerTest { private static final Logger LOG = LoggerFactory.getLogger(JDBCIOExceptionHandlerTest.class); private static final String TRANSPORT_URL = "tcp://0.0.0.0:0"; @@ -50,6 +56,11 @@ public class JDBCIOExceptionHandlerTest extends TestCase { private ReconnectingEmbeddedDataSource dataSource; private BrokerService broker; + @Before + public void dbHomeSysProp() throws Exception { + System.setProperty("derby.system.home", new File(IOHelper.getDefaultDataDirectory()).getCanonicalPath()); + } + protected BrokerService createBroker(boolean withJMX) throws Exception { return createBroker("localhost", withJMX, true, true); } @@ -94,6 +105,7 @@ public class JDBCIOExceptionHandlerTest extends TestCase { /* * run test without JMX enabled */ + @Test public void testRecoverWithOutJMX() throws Exception { recoverFromDisconnectDB(false); } @@ -101,14 +113,17 @@ public class JDBCIOExceptionHandlerTest extends TestCase { /* * run test with JMX enabled */ + @Test public void testRecoverWithJMX() throws Exception { recoverFromDisconnectDB(true); } + @Test public void testSlaveStoppedLease() throws Exception { testSlaveStopped(true); } + @Test public void testSlaveStoppedDefault() throws Exception { testSlaveStopped(false); } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCNegativeQueueTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCNegativeQueueTest.java index 998ff7c5d7..0a2ca1dd50 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCNegativeQueueTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCNegativeQueueTest.java @@ -23,22 +23,21 @@ import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; +import javax.sql.DataSource; import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.region.cursors.NegativeQueueTest; import org.apache.derby.jdbc.EmbeddedDataSource; public class JDBCNegativeQueueTest extends NegativeQueueTest { - EmbeddedDataSource dataSource; + DataSource dataSource; protected void configureBroker(BrokerService answer) throws Exception { super.configureBroker(answer); JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter(); - dataSource = new EmbeddedDataSource(); - dataSource.setDatabaseName("derbyDb"); - dataSource.setCreateDatabase("create"); - jdbc.setDataSource(dataSource); + jdbc.setDataSource(dataSource); answer.setPersistenceAdapter(jdbc); + dataSource = jdbc.getDataSource(); } protected void tearDown() throws Exception {