Update tests to not use hardcoded port for the transport connector and
remove the unneeded sleep calls with proper test setup
This commit is contained in:
Timothy Bish 2016-04-20 15:16:36 -04:00
parent b65c0d1be4
commit 10478c313e
7 changed files with 54 additions and 71 deletions

View File

@ -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() {

View File

@ -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 {

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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");
}

View File

@ -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);