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:
Gary Tully 2009-07-08 16:40:54 +00:00
parent bd1b10c207
commit 63f14732c7
2 changed files with 44 additions and 27 deletions

View File

@ -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;
@ -36,7 +38,7 @@ import org.apache.activemq.spring.ConsumerBean;
*/ */
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() {
@ -47,11 +49,13 @@ public class VirtualTopicPubSubTest extends EmbeddedBrokerTestSupport {
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) {
@ -73,38 +77,51 @@ public class VirtualTopicPubSubTest extends EmbeddedBrokerTestSupport {
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();

View File

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