mirror of https://github.com/apache/activemq.git
patched test from: https://issues.apache.org/activemq/browse/AMQ-1763 - still cannot reproduce
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@792220 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
bd1b10c207
commit
63f14732c7
|
@ -16,6 +16,8 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.broker.virtual;
|
package org.apache.activemq.broker.virtual;
|
||||||
|
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
import javax.jms.Connection;
|
import javax.jms.Connection;
|
||||||
import javax.jms.JMSException;
|
import javax.jms.JMSException;
|
||||||
import javax.jms.Message;
|
import javax.jms.Message;
|
||||||
|
@ -31,27 +33,29 @@ import org.apache.activemq.command.ActiveMQTopic;
|
||||||
import org.apache.activemq.spring.ConsumerBean;
|
import org.apache.activemq.spring.ConsumerBean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @version $Revision: $
|
* @version $Revision: $
|
||||||
*/
|
*/
|
||||||
public class VirtualTopicPubSubTest extends EmbeddedBrokerTestSupport {
|
public class VirtualTopicPubSubTest extends EmbeddedBrokerTestSupport {
|
||||||
|
|
||||||
private Connection connection;
|
private Vector<Connection> connections = new Vector<Connection>();
|
||||||
public int ackMode = Session.AUTO_ACKNOWLEDGE;
|
public int ackMode = Session.AUTO_ACKNOWLEDGE;
|
||||||
|
|
||||||
public static Test suite() {
|
public static Test suite() {
|
||||||
return suite(VirtualTopicPubSubTest.class);
|
return suite(VirtualTopicPubSubTest.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initCombosForTestVirtualTopicCreation() {
|
public void initCombosForTestVirtualTopicCreation() {
|
||||||
addCombinationValues("ackMode", new Object[] {new Integer(Session.AUTO_ACKNOWLEDGE), new Integer(Session.CLIENT_ACKNOWLEDGE) });
|
addCombinationValues("ackMode", new Object[] {new Integer(Session.AUTO_ACKNOWLEDGE), new Integer(Session.CLIENT_ACKNOWLEDGE) });
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testVirtualTopicCreation() throws Exception {
|
private boolean doneTwice = false;
|
||||||
if (connection == null) {
|
|
||||||
connection = createConnection();
|
public void testVirtualTopicCreation() throws Exception {
|
||||||
}
|
doTestVirtualTopicCreation(10);
|
||||||
connection.start();
|
}
|
||||||
|
|
||||||
|
public void doTestVirtualTopicCreation(int total) throws Exception {
|
||||||
|
|
||||||
ConsumerBean messageList = new ConsumerBean() {
|
ConsumerBean messageList = new ConsumerBean() {
|
||||||
public synchronized void onMessage(Message message) {
|
public synchronized void onMessage(Message message) {
|
||||||
|
@ -63,48 +67,61 @@ public class VirtualTopicPubSubTest extends EmbeddedBrokerTestSupport {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
messageList.setVerbose(true);
|
messageList.setVerbose(true);
|
||||||
|
|
||||||
String queueAName = getVirtualTopicConsumerName();
|
String queueAName = getVirtualTopicConsumerName();
|
||||||
// create consumer 'cluster'
|
// create consumer 'cluster'
|
||||||
ActiveMQQueue queue1 = new ActiveMQQueue(queueAName);
|
ActiveMQQueue queue1 = new ActiveMQQueue(queueAName);
|
||||||
ActiveMQQueue queue2 = new ActiveMQQueue(queueAName);
|
ActiveMQQueue queue2 = new ActiveMQQueue(queueAName);
|
||||||
|
|
||||||
Session session = connection.createSession(false, ackMode);
|
Session session = createStartAndTrackConnection().createSession(false, ackMode);
|
||||||
MessageConsumer c1 = session.createConsumer(queue1);
|
MessageConsumer c1 = session.createConsumer(queue1);
|
||||||
|
|
||||||
|
session = createStartAndTrackConnection().createSession(false, ackMode);
|
||||||
MessageConsumer c2 = session.createConsumer(queue2);
|
MessageConsumer c2 = session.createConsumer(queue2);
|
||||||
|
|
||||||
c1.setMessageListener(messageList);
|
c1.setMessageListener(messageList);
|
||||||
c2.setMessageListener(messageList);
|
c2.setMessageListener(messageList);
|
||||||
|
|
||||||
// create topic producer
|
// create topic producer
|
||||||
MessageProducer producer = session.createProducer(new ActiveMQTopic(getVirtualTopicName()));
|
Session producerSession = createStartAndTrackConnection().createSession(false, ackMode);
|
||||||
|
MessageProducer producer = producerSession.createProducer(new ActiveMQTopic(getVirtualTopicName()));
|
||||||
assertNotNull(producer);
|
assertNotNull(producer);
|
||||||
|
|
||||||
int total = 10;
|
|
||||||
for (int i = 0; i < total; i++) {
|
for (int i = 0; i < total; i++) {
|
||||||
producer.send(session.createTextMessage("message: " + i));
|
producer.send(producerSession.createTextMessage("message: " + i));
|
||||||
}
|
}
|
||||||
|
|
||||||
messageList.assertMessagesArrived(total);
|
messageList.assertMessagesArrived(total);
|
||||||
|
|
||||||
|
// do twice so we confirm messages do not get redelivered after client acknowledgement
|
||||||
|
if( doneTwice == false ) {
|
||||||
|
doneTwice = true;
|
||||||
|
doTestVirtualTopicCreation(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Connection createStartAndTrackConnection() throws Exception {
|
||||||
|
Connection connection = createConnection();
|
||||||
|
connection.start();
|
||||||
|
connections.add(connection);
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|
||||||
protected String getVirtualTopicName() {
|
protected String getVirtualTopicName() {
|
||||||
return "VirtualTopic.TEST";
|
return "VirtualTopic.TEST";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected String getVirtualTopicConsumerName() {
|
protected String getVirtualTopicConsumerName() {
|
||||||
return "Consumer.A.VirtualTopic.TEST";
|
return "Consumer.A.VirtualTopic.TEST";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
if (connection != null) {
|
for (Connection connection: connections) {
|
||||||
connection.close();
|
connection.close();
|
||||||
}
|
}
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
|
|
|
@ -41,7 +41,7 @@ public class ConsumerBean extends Assert implements MessageListener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor, initialized semaphore object.
|
* Constructor, initialized semaphore object.
|
||||||
*
|
*
|
||||||
* @param semaphore
|
* @param semaphore
|
||||||
*/
|
*/
|
||||||
public ConsumerBean(Object semaphore) {
|
public ConsumerBean(Object semaphore) {
|
||||||
|
@ -59,7 +59,7 @@ public class ConsumerBean extends Assert implements MessageListener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method implemented from MessageListener interface.
|
* Method implemented from MessageListener interface.
|
||||||
*
|
*
|
||||||
* @param message
|
* @param message
|
||||||
*/
|
*/
|
||||||
public synchronized void onMessage(Message message) {
|
public synchronized void onMessage(Message message) {
|
||||||
|
@ -96,7 +96,7 @@ public class ConsumerBean extends Assert implements MessageListener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to wait for a message to arrive given a particular message count.
|
* Used to wait for a message to arrive given a particular message count.
|
||||||
*
|
*
|
||||||
* @param messageCount
|
* @param messageCount
|
||||||
*/
|
*/
|
||||||
public void waitForMessagesToArrive(int messageCount) {
|
public void waitForMessagesToArrive(int messageCount) {
|
||||||
|
@ -106,12 +106,12 @@ public class ConsumerBean extends Assert implements MessageListener {
|
||||||
|
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
try {
|
try {
|
||||||
if (hasReceivedMessages(messageCount)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
synchronized (semaphore) {
|
synchronized (semaphore) {
|
||||||
semaphore.wait(1000);
|
semaphore.wait(1000);
|
||||||
}
|
}
|
||||||
|
if (hasReceivedMessages(messageCount)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
LOG.info("Caught: " + e);
|
LOG.info("Caught: " + e);
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,7 @@ public class ConsumerBean extends Assert implements MessageListener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Identifies if the message is empty.
|
* Identifies if the message is empty.
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
protected boolean hasReceivedMessage() {
|
protected boolean hasReceivedMessage() {
|
||||||
|
@ -149,7 +149,7 @@ public class ConsumerBean extends Assert implements MessageListener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Identifies if the message count has reached the total size of message.
|
* Identifies if the message count has reached the total size of message.
|
||||||
*
|
*
|
||||||
* @param messageCount
|
* @param messageCount
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue