Break up these tests as they are order dependent.

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1441643 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Timothy A. Bish 2013-02-01 21:37:20 +00:00
parent 4751a9c38c
commit 856e5061d7
2 changed files with 107 additions and 69 deletions

View File

@ -16,24 +16,23 @@
*/ */
package org.apache.activemq.config; package org.apache.activemq.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File; import java.io.File;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DatabaseMetaData; import java.sql.DatabaseMetaData;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.util.List; import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import javax.jms.ExceptionListener;
import javax.jms.JMSException; import javax.jms.JMSException;
import javax.jms.MessageConsumer; import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session; import javax.jms.Session;
import javax.jms.Topic; import javax.jms.Topic;
import javax.sql.DataSource; import javax.sql.DataSource;
import junit.framework.TestCase;
import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.TransportConnector; import org.apache.activemq.broker.TransportConnector;
@ -46,6 +45,7 @@ import org.apache.activemq.broker.region.policy.StrictOrderDispatchPolicy;
import org.apache.activemq.broker.region.policy.SubscriptionRecoveryPolicy; import org.apache.activemq.broker.region.policy.SubscriptionRecoveryPolicy;
import org.apache.activemq.broker.region.policy.TimedSubscriptionRecoveryPolicy; import org.apache.activemq.broker.region.policy.TimedSubscriptionRecoveryPolicy;
import org.apache.activemq.command.ActiveMQTopic; import org.apache.activemq.command.ActiveMQTopic;
import org.apache.activemq.network.NetworkConnector;
import org.apache.activemq.store.PersistenceAdapter; import org.apache.activemq.store.PersistenceAdapter;
import org.apache.activemq.store.jdbc.DefaultDatabaseLocker; import org.apache.activemq.store.jdbc.DefaultDatabaseLocker;
import org.apache.activemq.store.jdbc.JDBCPersistenceAdapter; import org.apache.activemq.store.jdbc.JDBCPersistenceAdapter;
@ -54,21 +54,17 @@ import org.apache.activemq.store.journal.JournalPersistenceAdapter;
import org.apache.activemq.store.memory.MemoryPersistenceAdapter; import org.apache.activemq.store.memory.MemoryPersistenceAdapter;
import org.apache.activemq.transport.tcp.TcpTransportServer; import org.apache.activemq.transport.tcp.TcpTransportServer;
import org.apache.activemq.usage.SystemUsage; import org.apache.activemq.usage.SystemUsage;
import org.apache.activemq.wireformat.ObjectStreamWireFormat;
import org.apache.activemq.xbean.BrokerFactoryBean; import org.apache.activemq.xbean.BrokerFactoryBean;
import org.apache.derby.jdbc.EmbeddedDataSource;
import org.jmock.Expectations; import org.jmock.Expectations;
import org.jmock.Mockery; import org.jmock.Mockery;
import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
/** public class ConfigTest {
*
*/
public class ConfigTest extends TestCase {
protected static final String JOURNAL_ROOT = "target/test-data/"; protected static final String JOURNAL_ROOT = "target/test-data/";
protected static final String DERBY_ROOT = "target/test-data/"; protected static final String DERBY_ROOT = "target/test-data/";
@ -95,16 +91,13 @@ public class ConfigTest extends TestCase {
* This tests creating a journal persistence adapter using the persistence * This tests creating a journal persistence adapter using the persistence
* adapter factory bean * adapter factory bean
*/ */
@Test
public void testJournaledJDBCConfig() throws Exception { public void testJournaledJDBCConfig() throws Exception {
// System.out.print("Checking journaled JDBC persistence adapter
// configuration... ");
File journalFile = new File(JOURNAL_ROOT + "testJournaledJDBCConfig/journal"); File journalFile = new File(JOURNAL_ROOT + "testJournaledJDBCConfig/journal");
recursiveDelete(journalFile); recursiveDelete(journalFile);
File derbyFile = new File(DERBY_ROOT + "testJournaledJDBCConfig/derbydb"); // Default File derbyFile = new File(DERBY_ROOT + "testJournaledJDBCConfig/derbydb"); // Default
// derby
// name
recursiveDelete(derbyFile); recursiveDelete(derbyFile);
BrokerService broker; BrokerService broker;
@ -119,8 +112,6 @@ public class ConfigTest extends TestCase {
assertTrue("Should have created a journal directory at " + journalFile.getAbsolutePath(), journalFile.exists()); assertTrue("Should have created a journal directory at " + journalFile.getAbsolutePath(), journalFile.exists());
// Check persistence factory configurations // Check persistence factory configurations
// System.out.print("Checking persistence adapter factory
// settings... ");
broker.getPersistenceAdapter(); broker.getPersistenceAdapter();
assertTrue(broker.getSystemUsage().getStoreUsage().getStore() instanceof JournalPersistenceAdapter); assertTrue(broker.getSystemUsage().getStoreUsage().getStore() instanceof JournalPersistenceAdapter);
@ -133,40 +124,7 @@ public class ConfigTest extends TestCase {
} }
} }
/* @Test
* This tests creating a jdbc persistence adapter using xbeans-spring
*/
public void testJdbcConfig() throws Exception {
// System.out.print("Checking jdbc persistence adapter configuration...
// ");
File journalFile = new File(JOURNAL_ROOT + "testJDBCConfig/journal");
recursiveDelete(journalFile);
File derbyFile = new File(DERBY_ROOT + "testJDBCConfig/derbydb"); // Default
// derby
// name
recursiveDelete(derbyFile);
BrokerService broker;
broker = createBroker(new FileSystemResource(CONF_ROOT + "jdbc-example.xml"));
try {
assertEquals("Broker Config Error (brokerName)", "brokerJdbcConfigTest", broker.getBrokerName());
PersistenceAdapter adapter = broker.getPersistenceAdapter();
assertTrue("Should have created a jdbc persistence adapter", adapter instanceof JDBCPersistenceAdapter);
assertEquals("JDBC Adapter Config Error (cleanupPeriod)", 60000, ((JDBCPersistenceAdapter) adapter).getCleanupPeriod());
assertTrue("Should have created an EmbeddedDataSource", ((JDBCPersistenceAdapter) adapter).getDataSource() instanceof EmbeddedDataSource);
assertTrue("Should have created a DefaultWireFormat", ((JDBCPersistenceAdapter) adapter).getWireFormat() instanceof ObjectStreamWireFormat);
LOG.info("Success");
} finally {
if (broker != null) {
broker.stop();
}
}
}
public void testJdbcLockConfigOverride() throws Exception { public void testJdbcLockConfigOverride() throws Exception {
JDBCPersistenceAdapter adapter = new JDBCPersistenceAdapter(); JDBCPersistenceAdapter adapter = new JDBCPersistenceAdapter();
@ -195,7 +153,6 @@ public class ConfigTest extends TestCase {
adapter.stop(); adapter.stop();
} }
public void testJdbcLockConfigDefault() throws Exception { public void testJdbcLockConfigDefault() throws Exception {
JDBCPersistenceAdapter adapter = new JDBCPersistenceAdapter(); JDBCPersistenceAdapter adapter = new JDBCPersistenceAdapter();
@ -228,6 +185,7 @@ public class ConfigTest extends TestCase {
* This tests configuring the different broker properties using * This tests configuring the different broker properties using
* xbeans-spring * xbeans-spring
*/ */
@Test
public void testBrokerConfig() throws Exception { public void testBrokerConfig() throws Exception {
ActiveMQTopic dest; ActiveMQTopic dest;
BrokerService broker; BrokerService broker;
@ -259,15 +217,15 @@ public class ConfigTest extends TestCase {
// Check transport connectors list // Check transport connectors list
// System.out.print("Checking transport connectors... "); // System.out.print("Checking transport connectors... ");
List connectors = broker.getTransportConnectors(); List<TransportConnector> connectors = broker.getTransportConnectors();
assertTrue("Should have created at least 3 connectors", connectors.size() >= 3); assertTrue("Should have created at least 3 connectors", connectors.size() >= 3);
assertTrue("1st connector should be TcpTransportServer", ((TransportConnector) connectors.get(0)).getServer() instanceof TcpTransportServer); assertTrue("1st connector should be TcpTransportServer", connectors.get(0).getServer() instanceof TcpTransportServer);
assertTrue("2nd connector should be TcpTransportServer", ((TransportConnector) connectors.get(1)).getServer() instanceof TcpTransportServer); assertTrue("2nd connector should be TcpTransportServer", connectors.get(1).getServer() instanceof TcpTransportServer);
assertTrue("3rd connector should be TcpTransportServer", ((TransportConnector) connectors.get(2)).getServer() instanceof TcpTransportServer); assertTrue("3rd connector should be TcpTransportServer", connectors.get(2).getServer() instanceof TcpTransportServer);
// Check network connectors // Check network connectors
// System.out.print("Checking network connectors... "); // System.out.print("Checking network connectors... ");
List networkConnectors = broker.getNetworkConnectors(); List<NetworkConnector> networkConnectors = broker.getNetworkConnectors();
assertEquals("Should have a single network connector", 1, networkConnectors.size()); assertEquals("Should have a single network connector", 1, networkConnectors.size());
LOG.info("Success"); LOG.info("Success");
@ -336,10 +294,8 @@ public class ConfigTest extends TestCase {
/* /*
* This tests creating a journal persistence adapter using xbeans-spring * This tests creating a journal persistence adapter using xbeans-spring
*/ */
@Test
public void testJournalConfig() throws Exception { public void testJournalConfig() throws Exception {
// System.out.print("Checking journal persistence adapter
// configuration... ");
File journalFile = new File(JOURNAL_ROOT + "testJournalConfig/journal"); File journalFile = new File(JOURNAL_ROOT + "testJournalConfig/journal");
recursiveDelete(journalFile); recursiveDelete(journalFile);
@ -364,10 +320,8 @@ public class ConfigTest extends TestCase {
/* /*
* This tests creating a memory persistence adapter using xbeans-spring * This tests creating a memory persistence adapter using xbeans-spring
*/ */
@Test
public void testMemoryConfig() throws Exception { public void testMemoryConfig() throws Exception {
// System.out.print("Checking memory persistence adapter
// configuration... ");
File journalFile = new File(JOURNAL_ROOT + "testMemoryConfig"); File journalFile = new File(JOURNAL_ROOT + "testMemoryConfig");
recursiveDelete(journalFile); recursiveDelete(journalFile);
@ -392,12 +346,10 @@ public class ConfigTest extends TestCase {
broker.stop(); broker.stop();
} }
} }
} }
@Test
public void testConnectorConfig() throws Exception { public void testConnectorConfig() throws Exception {
// System.out.print("Checking memory persistence adapter
// configuration... ");
File journalFile = new File(JOURNAL_ROOT + "testMemoryConfig"); File journalFile = new File(JOURNAL_ROOT + "testMemoryConfig");
recursiveDelete(journalFile); recursiveDelete(journalFile);
@ -434,21 +386,21 @@ public class ConfigTest extends TestCase {
try { try {
for (int i = 0; i < (MAX_CONSUMERS + 1); i++) { for (int i = 0; i < (MAX_CONSUMERS + 1); i++) {
MessageConsumer consumer = session.createConsumer(topic); MessageConsumer consumer = session.createConsumer(topic);
assertNotNull(consumer);
} }
fail("Should have caught an exception"); fail("Should have caught an exception");
} catch (JMSException e) { } catch (JMSException e) {
} }
LOG.info("Success"); LOG.info("Success");
} finally { } finally {
if (broker != null) { if (broker != null) {
broker.stop(); broker.stop();
} }
} }
} }
@Test
public void testXmlConfigHelper() throws Exception { public void testXmlConfigHelper() throws Exception {
BrokerService broker; BrokerService broker;

View File

@ -0,0 +1,86 @@
package org.apache.activemq.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.File;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.store.PersistenceAdapter;
import org.apache.activemq.store.jdbc.JDBCPersistenceAdapter;
import org.apache.activemq.wireformat.ObjectStreamWireFormat;
import org.apache.activemq.xbean.BrokerFactoryBean;
import org.apache.derby.jdbc.EmbeddedDataSource;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
public class JDBCConfigTest {
protected static final String JOURNAL_ROOT = "target/test-data/";
protected static final String DERBY_ROOT = "target/test-data/";
protected static final String CONF_ROOT = "src/test/resources/org/apache/activemq/config/sample-conf/";
private static final Logger LOG = LoggerFactory.getLogger(JDBCConfigTest.class);
/*
* This tests creating a jdbc persistence adapter using xbeans-spring
*/
@Test
public void testJdbcConfig() throws Exception {
File journalFile = new File(JOURNAL_ROOT + "testJDBCConfig/journal");
recursiveDelete(journalFile);
File derbyFile = new File(DERBY_ROOT + "testJDBCConfig/derbydb"); // Default
recursiveDelete(derbyFile);
BrokerService broker;
broker = createBroker(new FileSystemResource(CONF_ROOT + "jdbc-example.xml"));
try {
assertEquals("Broker Config Error (brokerName)", "brokerJdbcConfigTest", broker.getBrokerName());
PersistenceAdapter adapter = broker.getPersistenceAdapter();
assertTrue("Should have created a jdbc persistence adapter", adapter instanceof JDBCPersistenceAdapter);
assertEquals("JDBC Adapter Config Error (cleanupPeriod)", 60000, ((JDBCPersistenceAdapter) adapter).getCleanupPeriod());
assertTrue("Should have created an EmbeddedDataSource", ((JDBCPersistenceAdapter) adapter).getDataSource() instanceof EmbeddedDataSource);
assertTrue("Should have created a DefaultWireFormat", ((JDBCPersistenceAdapter) adapter).getWireFormat() instanceof ObjectStreamWireFormat);
LOG.info("Success");
} finally {
if (broker != null) {
broker.stop();
}
}
}
protected static void recursiveDelete(File file) {
if (file.isDirectory()) {
File[] files = file.listFiles();
for (int i = 0; i < files.length; i++) {
recursiveDelete(files[i]);
}
}
file.delete();
}
protected BrokerService createBroker(String resource) throws Exception {
return createBroker(new ClassPathResource(resource));
}
protected BrokerService createBroker(Resource resource) throws Exception {
BrokerFactoryBean factory = new BrokerFactoryBean(resource);
factory.afterPropertiesSet();
BrokerService broker = factory.getBroker();
assertTrue("Should have a broker!", broker != null);
// Broker is already started by default when using the XML file
// broker.start();
return broker;
}
}