improvement on the composite queue spring listener test

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1021328 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Bosanac Dejan 2010-10-11 12:49:42 +00:00
parent b625db2462
commit 0d47fea17c
3 changed files with 20 additions and 9 deletions

View File

@ -17,6 +17,8 @@
package org.apache.activemq.spring;
import org.apache.activemq.command.ActiveMQTextMessage;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.jms.JMSException;
import javax.jms.Message;
@ -25,6 +27,7 @@ import java.util.ArrayList;
import java.util.List;
public class Listener implements MessageListener {
private static final Log LOG = LogFactory.getLog(Listener.class);
List<Message> messages = new ArrayList<Message>();
long lastReceived = 0L;
@ -33,7 +36,7 @@ public class Listener implements MessageListener {
public void onMessage(Message message) {
try {
System.out.println("LISTENER received " + message.getJMSDestination() + " " + ((ActiveMQTextMessage)message).getText());
LOG.info("LISTENER received " + message.getJMSDestination() + " " + ((ActiveMQTextMessage)message).getText());
lastReceived = System.currentTimeMillis();
synchronized (messages) {
messages.add(message);

View File

@ -16,6 +16,8 @@
*/
package org.apache.activemq.spring;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -32,6 +34,9 @@ import javax.jms.*;
@ContextConfiguration(locations = {"classpath:spring/spring.xml"})
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = false)
public class ListenerTest {
private static final Log LOG = LogFactory.getLog(ListenerTest.class);
int msgNum = 10;
protected String bindAddress = "vm://localhost";
@ -41,24 +46,24 @@ public class ListenerTest {
@Test
@DirtiesContext
public void testSimple() throws Exception {
sendMessages("SIMPLE", 10);
sendMessages("SIMPLE", msgNum);
Thread.sleep(3000);
System.out.println(listener.messages.size());
Assert.assertEquals(listener.messages.size(), 10);
LOG.info("messages received= " + listener.messages.size());
Assert.assertEquals(listener.messages.size(), msgNum);
}
@Test
@DirtiesContext
public void testComposite() throws Exception {
sendMessages("TEST.1,TEST.2,TEST.3,TEST.4,TEST.5,TEST.6", 10);
sendMessages("TEST.1,TEST.2,TEST.3,TEST.4,TEST.5,TEST.6", msgNum);
Thread.sleep(3000);
System.out.println(listener.messages.size());
Assert.assertEquals(listener.messages.size(), 60);
LOG.info("messages received= " + listener.messages.size());
Assert.assertEquals(listener.messages.size(), 6 * msgNum);
}
public void sendMessages(String destName, int msgNum) throws Exception {
@ -68,7 +73,9 @@ public class ListenerTest {
Destination dest = sess.createQueue(destName);
MessageProducer producer = sess.createProducer(dest);
for (int i = 0; i < msgNum; i++) {
producer.send(sess.createTextMessage("test"));
String messageText = i +" test";
LOG.info("sending message '" + messageText + "'");
producer.send(sess.createTextMessage(messageText));
}
}

View File

@ -59,7 +59,8 @@
<property name="connectionFactory" ref="connectionFactory"/>
<property name="messageListener" ref="messageListener"/>
<property name="destinationName" value="TEST.>"/>
<property name="sessionTransacted" value="true"/>
<property name="transactionManager" ref="transactionManager"/>
<property name="cacheLevelName" value="CACHE_CONSUMER"/>
</bean>
</beans>