Repository: activemq Updated Branches: refs/heads/master b65c0d1be -> 10478c313
https://issues.apache.org/jira/browse/AMQ-5621 Update tests to not use hardcoded port for the transport connector and remove the unneeded sleep calls with proper test setup Project: http://git-wip-us.apache.org/repos/asf/activemq/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/10478c31 Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/10478c31 Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/10478c31 Branch: refs/heads/master Commit: 10478c313e81f0209ed5cb89e9c7529870e6a300 Parents: b65c0d1 Author: Timothy Bish <[email protected]> Authored: Wed Apr 20 15:16:36 2016 -0400 Committer: Timothy Bish <[email protected]> Committed: Wed Apr 20 15:16:36 2016 -0400 ---------------------------------------------------------------------- .../test/JmsSendReceiveTestSupport.java | 32 +++++++++----------- .../activemq/test/JmsTopicSendReceiveTest.java | 18 +++++------ ...dReceiveWithEmbeddedBrokerAndUserIDTest.java | 16 +++------- ...veWithTwoConnectionsAndByteSelectorTest.java | 9 ++---- ...WithTwoConnectionsAndEmbeddedBrokerTest.java | 28 ++++++++++------- ...sTopicSendReceiveWithTwoConnectionsTest.java | 16 +++++----- .../TemporaryDestinationToFromNameTest.java | 6 +--- 7 files changed, 54 insertions(+), 71 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq/blob/10478c31/activemq-unit-tests/src/test/java/org/apache/activemq/test/JmsSendReceiveTestSupport.java ---------------------------------------------------------------------- diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/test/JmsSendReceiveTestSupport.java b/activemq-unit-tests/src/test/java/org/apache/activemq/test/JmsSendReceiveTestSupport.java index 310fc1b..8925c17 100755 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/test/JmsSendReceiveTestSupport.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/test/JmsSendReceiveTestSupport.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. @@ -33,16 +33,13 @@ import javax.jms.MessageProducer; import javax.jms.Session; import javax.jms.TextMessage; -import junit.framework.AssertionFailedError; - -import org.apache.activemq.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** - * - */ +import junit.framework.AssertionFailedError; + public abstract class JmsSendReceiveTestSupport extends org.apache.activemq.TestSupport implements MessageListener { + private static final Logger LOG = LoggerFactory.getLogger(JmsSendReceiveTestSupport.class); protected int messageCount = 100; @@ -66,8 +63,10 @@ public abstract class JmsSendReceiveTestSupport extends org.apache.activemq.Test /* * @see junit.framework.TestCase#setUp() */ + @Override protected void setUp() throws Exception { super.setUp(); + messages.clear(); String temp = System.getProperty("messageCount"); if (temp != null) { @@ -102,14 +101,10 @@ public abstract class JmsSendReceiveTestSupport extends org.apache.activemq.Test /** * Test if all the messages sent are being received. - * + * * @throws Exception */ public void testSendReceive() throws Exception { - - Thread.sleep(1000); - messages.clear(); - sendMessages(); assertMessagesAreReceived(); @@ -128,7 +123,7 @@ public abstract class JmsSendReceiveTestSupport extends org.apache.activemq.Test } protected void sendMessage(int index, Message message) throws Exception { - producer.send(producerDestination, message); + producer.send(producerDestination, message); } protected Message createMessage(int index) throws JMSException { @@ -138,7 +133,7 @@ public abstract class JmsSendReceiveTestSupport extends org.apache.activemq.Test /** * A hook to allow the message to be configured such as adding extra headers - * + * * @throws JMSException */ protected void configureMessage(Message message) throws JMSException { @@ -147,7 +142,7 @@ public abstract class JmsSendReceiveTestSupport extends org.apache.activemq.Test /** * Waits to receive the messages and performs the test if all messages have * been received and are in sequential order. - * + * * @throws JMSException */ protected void assertMessagesAreReceived() throws JMSException { @@ -157,7 +152,7 @@ public abstract class JmsSendReceiveTestSupport extends org.apache.activemq.Test /** * Tests if the messages have all been received and are in sequential order. - * + * * @param receivedMessages * @throws JMSException */ @@ -224,13 +219,14 @@ public abstract class JmsSendReceiveTestSupport extends org.apache.activemq.Test /** * @see javax.jms.MessageListener#onMessage(javax.jms.Message) */ + @Override public synchronized void onMessage(Message message) { consumeMessage(message, messages); } /** * Consumes a received message. - * + * * @param message - a newly received message. * @param messageList - list containing the received messages. */ @@ -250,7 +246,7 @@ public abstract class JmsSendReceiveTestSupport extends org.apache.activemq.Test /** * Creates a synchronized list. - * + * * @return a synchronized view of the specified list. */ protected List<Message> createConcurrentList() { http://git-wip-us.apache.org/repos/asf/activemq/blob/10478c31/activemq-unit-tests/src/test/java/org/apache/activemq/test/JmsTopicSendReceiveTest.java ---------------------------------------------------------------------- diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/test/JmsTopicSendReceiveTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/test/JmsTopicSendReceiveTest.java index feff243..0fa89d2 100755 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/test/JmsTopicSendReceiveTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/test/JmsTopicSendReceiveTest.java @@ -27,13 +27,14 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * + * */ public class JmsTopicSendReceiveTest extends JmsSendReceiveTestSupport { private static final Logger LOG = LoggerFactory.getLogger(JmsTopicSendReceiveTest.class); protected Connection connection; + @Override protected void setUp() throws Exception { super.setUp(); @@ -76,21 +77,16 @@ public class JmsTopicSendReceiveTest extends JmsSendReceiveTestSupport { connection.start(); } + @Override protected void tearDown() throws Exception { - LOG.info("Dumping stats..."); - // TODO - // connectionFactory.getFactoryStats().dump(new IndentPrinter()); - LOG.info("Closing down connection"); - - /** TODO we should be able to shut down properly */ session.close(); connection.close(); } /** * Creates a session. - * + * * @return session * @throws JMSException */ @@ -103,9 +99,9 @@ public class JmsTopicSendReceiveTest extends JmsSendReceiveTestSupport { } /** - * Creates a durable suscriber or a consumer. - * - * @return MessageConsumer - durable suscriber or consumer. + * Creates a durable subscriber or a consumer. + * + * @return MessageConsumer - durable subscriber or consumer. * @throws JMSException */ protected MessageConsumer createConsumer() throws JMSException { http://git-wip-us.apache.org/repos/asf/activemq/blob/10478c31/activemq-unit-tests/src/test/java/org/apache/activemq/test/JmsTopicSendReceiveWithEmbeddedBrokerAndUserIDTest.java ---------------------------------------------------------------------- diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/test/JmsTopicSendReceiveWithEmbeddedBrokerAndUserIDTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/test/JmsTopicSendReceiveWithEmbeddedBrokerAndUserIDTest.java index aac150f..e4f713e 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/test/JmsTopicSendReceiveWithEmbeddedBrokerAndUserIDTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/test/JmsTopicSendReceiveWithEmbeddedBrokerAndUserIDTest.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. @@ -23,12 +23,10 @@ import javax.jms.Message; import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.broker.TransportConnector; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** - * - */ public class JmsTopicSendReceiveWithEmbeddedBrokerAndUserIDTest extends JmsTopicSendReceiveWithTwoConnectionsAndEmbeddedBrokerTest { private static final Logger LOG = LoggerFactory.getLogger(JmsTopicSendReceiveWithEmbeddedBrokerAndUserIDTest.class); @@ -42,9 +40,9 @@ public class JmsTopicSendReceiveWithEmbeddedBrokerAndUserIDTest extends JmsTopic } @Override - protected void configureBroker(BrokerService answer) throws Exception { + protected TransportConnector configureBroker(BrokerService answer) throws Exception { answer.setPopulateJMSXUserID(true); - super.configureBroker(answer); + return super.configureBroker(answer); } @Override @@ -76,9 +74,6 @@ public class JmsTopicSendReceiveWithEmbeddedBrokerAndUserIDTest extends JmsTopic } public void testSpoofedJMSXUserIdIsIgnored() throws Exception { - Thread.sleep(1000); - messages.clear(); - for (int i = 0; i < data.length; i++) { Message message = createMessage(i); configureMessage(message); @@ -93,9 +88,6 @@ public class JmsTopicSendReceiveWithEmbeddedBrokerAndUserIDTest extends JmsTopic } public void testSpoofedJMSXUserIdIsIgnoredAsObjectProperty() throws Exception { - Thread.sleep(1000); - messages.clear(); - for (int i = 0; i < data.length; i++) { Message message = createMessage(i); configureMessage(message); http://git-wip-us.apache.org/repos/asf/activemq/blob/10478c31/activemq-unit-tests/src/test/java/org/apache/activemq/test/JmsTopicSendReceiveWithTwoConnectionsAndByteSelectorTest.java ---------------------------------------------------------------------- diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/test/JmsTopicSendReceiveWithTwoConnectionsAndByteSelectorTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/test/JmsTopicSendReceiveWithTwoConnectionsAndByteSelectorTest.java index 78a7f6f..717d98e 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/test/JmsTopicSendReceiveWithTwoConnectionsAndByteSelectorTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/test/JmsTopicSendReceiveWithTwoConnectionsAndByteSelectorTest.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. @@ -20,18 +20,15 @@ import javax.jms.JMSException; import javax.jms.Message; import javax.jms.MessageConsumer; -/** - * - */ public class JmsTopicSendReceiveWithTwoConnectionsAndByteSelectorTest extends JmsTopicSendReceiveWithTwoConnectionsTest { - + @Override protected void configureMessage(Message message) throws JMSException { message.setByteProperty("dummy", (byte) 33); } + @Override protected MessageConsumer createConsumer() throws JMSException { return receiveSession.createConsumer(consumerDestination, "dummy = 33", false); } - } http://git-wip-us.apache.org/repos/asf/activemq/blob/10478c31/activemq-unit-tests/src/test/java/org/apache/activemq/test/JmsTopicSendReceiveWithTwoConnectionsAndEmbeddedBrokerTest.java ---------------------------------------------------------------------- diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/test/JmsTopicSendReceiveWithTwoConnectionsAndEmbeddedBrokerTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/test/JmsTopicSendReceiveWithTwoConnectionsAndEmbeddedBrokerTest.java index 6bd92df..e72a824 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/test/JmsTopicSendReceiveWithTwoConnectionsAndEmbeddedBrokerTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/test/JmsTopicSendReceiveWithTwoConnectionsAndEmbeddedBrokerTest.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. @@ -18,20 +18,20 @@ package org.apache.activemq.test; import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.broker.TransportConnector; -/** - * - */ public class JmsTopicSendReceiveWithTwoConnectionsAndEmbeddedBrokerTest extends JmsTopicSendReceiveWithTwoConnectionsTest { protected BrokerService broker; - protected String bindAddress = "tcp://localhost:61616"; + protected String bindAddress = "tcp://localhost:0"; + protected String connectionAddress; /** * Sets up a test where the producer and consumer have their own connection. - * + * * @see junit.framework.TestCase#setUp() */ + @Override protected void setUp() throws Exception { if (broker == null) { broker = createBroker(); @@ -39,31 +39,37 @@ public class JmsTopicSendReceiveWithTwoConnectionsAndEmbeddedBrokerTest extends super.setUp(); } + @Override protected void tearDown() throws Exception { super.tearDown(); if (broker != null) { broker.stop(); + broker = null; } } /** * Factory method to create a new broker - * + * * @throws Exception */ protected BrokerService createBroker() throws Exception { BrokerService answer = new BrokerService(); - configureBroker(answer); + TransportConnector connector = configureBroker(answer); answer.start(); + + connectionAddress = connector.getPublishableConnectString(); + return answer; } - protected void configureBroker(BrokerService answer) throws Exception { - answer.addConnector(bindAddress); + protected TransportConnector configureBroker(BrokerService answer) throws Exception { + return answer.addConnector(bindAddress); } + @Override protected ActiveMQConnectionFactory createConnectionFactory() throws Exception { - return new ActiveMQConnectionFactory(bindAddress); + return new ActiveMQConnectionFactory(connectionAddress); } } http://git-wip-us.apache.org/repos/asf/activemq/blob/10478c31/activemq-unit-tests/src/test/java/org/apache/activemq/test/JmsTopicSendReceiveWithTwoConnectionsTest.java ---------------------------------------------------------------------- diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/test/JmsTopicSendReceiveWithTwoConnectionsTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/test/JmsTopicSendReceiveWithTwoConnectionsTest.java index 21a3575..7d59641 100755 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/test/JmsTopicSendReceiveWithTwoConnectionsTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/test/JmsTopicSendReceiveWithTwoConnectionsTest.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. @@ -26,9 +26,6 @@ import org.apache.activemq.ActiveMQConnectionFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** - * - */ public class JmsTopicSendReceiveWithTwoConnectionsTest extends JmsSendReceiveTestSupport { private static final Logger LOG = LoggerFactory.getLogger(JmsTopicSendReceiveWithTwoConnectionsTest.class); @@ -39,9 +36,10 @@ public class JmsTopicSendReceiveWithTwoConnectionsTest extends JmsSendReceiveTes /** * Sets up a test where the producer and consumer have their own connection. - * + * * @see junit.framework.TestCase#setUp() */ + @Override protected void setUp() throws Exception { super.setUp(); @@ -95,6 +93,7 @@ public class JmsTopicSendReceiveWithTwoConnectionsTest extends JmsSendReceiveTes /* * @see junit.framework.TestCase#tearDown() */ + @Override protected void tearDown() throws Exception { session.close(); receiveSession.close(); @@ -104,7 +103,7 @@ public class JmsTopicSendReceiveWithTwoConnectionsTest extends JmsSendReceiveTes /** * Creates a connection. - * + * * @return Connection * @throws Exception */ @@ -114,7 +113,7 @@ public class JmsTopicSendReceiveWithTwoConnectionsTest extends JmsSendReceiveTes /** * Creates a connection. - * + * * @return Connection * @throws Exception */ @@ -124,9 +123,10 @@ public class JmsTopicSendReceiveWithTwoConnectionsTest extends JmsSendReceiveTes /** * Creates an ActiveMQConnectionFactory. - * + * * @see org.apache.activemq.test.TestSupport#createConnectionFactory() */ + @Override protected ActiveMQConnectionFactory createConnectionFactory() throws Exception { return new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false"); } http://git-wip-us.apache.org/repos/asf/activemq/blob/10478c31/activemq-unit-tests/src/test/java/org/apache/activemq/test/TemporaryDestinationToFromNameTest.java ---------------------------------------------------------------------- diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/test/TemporaryDestinationToFromNameTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/test/TemporaryDestinationToFromNameTest.java index 4dc0088..7efae32 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/test/TemporaryDestinationToFromNameTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/test/TemporaryDestinationToFromNameTest.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. @@ -21,13 +21,9 @@ import javax.jms.Session; import javax.jms.Topic; import org.apache.activemq.EmbeddedBrokerAndConnectionTestSupport; -import org.apache.activemq.broker.jmx.PurgeTest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** - * - */ public class TemporaryDestinationToFromNameTest extends EmbeddedBrokerAndConnectionTestSupport { private static final Logger LOG = LoggerFactory.getLogger(TemporaryDestinationToFromNameTest.class);
