[jboss-cvs] JBoss Messaging SVN: r5460 - in trunk: tests/src/org/jboss/messaging/tests/integration/queue and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Dec 4 06:24:01 EST 2008
Author: ataylor
Date: 2008-12-04 06:24:01 -0500 (Thu, 04 Dec 2008)
New Revision: 5460
Added:
trunk/tests/src/org/jboss/messaging/tests/integration/queue/MessageGroupingTest.java
Modified:
trunk/src/main/org/jboss/messaging/core/server/impl/GroupingRoundRobinDistributionPolicy.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/GroupingRoundRobinDistributionPolicyTest.java
Log:
tests and tweaks to message grouping
Modified: trunk/src/main/org/jboss/messaging/core/server/impl/GroupingRoundRobinDistributionPolicy.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/GroupingRoundRobinDistributionPolicy.java 2008-12-04 01:40:14 UTC (rev 5459)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/GroupingRoundRobinDistributionPolicy.java 2008-12-04 11:24:01 UTC (rev 5460)
@@ -54,26 +54,26 @@
public HandleStatus distribute(MessageReference reference)
{
+ if (getConsumerCount() == 0)
+ {
+ return HandleStatus.BUSY;
+ }
final SimpleString groupId = (SimpleString) reference.getMessage().getProperty(MessageImpl.HDR_GROUP_ID);
if (groupId != null)
{
- boolean bound;
int startPos = pos;
boolean filterRejected = false;
while (true)
{
Consumer consumer = cons.putIfAbsent(groupId, consumers.get(pos));
+
if (consumer == null)
{
incrementPosition();
consumer = cons.get(groupId);
- bound = false;
}
- else
- {
- bound = true;
- }
+
HandleStatus status = handle(reference, consumer);
if (status == HandleStatus.HANDLED)
{
@@ -86,14 +86,7 @@
else if (status == HandleStatus.BUSY)
{
//if we were previously bound, we can remove and try the next consumer
- if (bound)
- {
- return HandleStatus.BUSY;
- }
- else
- {
- cons.remove(groupId);
- }
+ return HandleStatus.BUSY;
}
//if we've tried all of them
if (startPos == pos)
@@ -127,7 +120,6 @@
if (consumer == cons.get(group))
{
cons.remove(group);
- break;
}
}
}
Added: trunk/tests/src/org/jboss/messaging/tests/integration/queue/MessageGroupingTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/queue/MessageGroupingTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/queue/MessageGroupingTest.java 2008-12-04 11:24:01 UTC (rev 5460)
@@ -0,0 +1,603 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.tests.integration.queue;
+
+import org.jboss.messaging.tests.util.UnitTestCase;
+import org.jboss.messaging.core.server.MessagingService;
+import org.jboss.messaging.core.server.impl.MessagingServiceImpl;
+import org.jboss.messaging.core.server.impl.GroupingRoundRobinDistributionPolicy;
+import org.jboss.messaging.core.config.impl.ConfigurationImpl;
+import org.jboss.messaging.core.config.TransportConfiguration;
+import org.jboss.messaging.core.client.ClientSessionFactory;
+import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.ClientProducer;
+import org.jboss.messaging.core.client.ClientMessage;
+import org.jboss.messaging.core.client.ClientConsumer;
+import org.jboss.messaging.core.client.MessageHandler;
+import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
+import org.jboss.messaging.core.exception.MessagingException;
+import org.jboss.messaging.core.settings.impl.QueueSettings;
+import org.jboss.messaging.core.message.impl.MessageImpl;
+import org.jboss.messaging.core.transaction.impl.XidImpl;
+import org.jboss.messaging.util.SimpleString;
+
+import javax.transaction.xa.Xid;
+import javax.transaction.xa.XAResource;
+import java.util.ArrayList;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author <a href="mailto:andy.taylor at jboss.org">Andy Taylor</a>
+ */
+public class MessageGroupingTest extends UnitTestCase
+{
+ private MessagingService messagingService;
+
+ private ClientSession clientSession;
+
+ private SimpleString qName = new SimpleString("MessageGroupingTestQueue");
+
+ public void testBasicGrouping() throws Exception
+ {
+ ClientProducer clientProducer = clientSession.createProducer(qName);
+ ClientConsumer consumer = clientSession.createConsumer(qName);
+ ClientConsumer consumer2 = clientSession.createConsumer(qName);
+ clientSession.start();
+ SimpleString groupId = new SimpleString("grp1");
+ int numMessages = 100;
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = createTextMessage("m" + i, clientSession);
+ message.putStringProperty(MessageImpl.HDR_GROUP_ID, groupId);
+ clientProducer.send(message);
+ }
+ CountDownLatch latch = new CountDownLatch(numMessages);
+ DummyMessageHandler dummyMessageHandler = new DummyMessageHandler(latch, true);
+ consumer.setMessageHandler(dummyMessageHandler);
+ DummyMessageHandler dummyMessageHandler2 = new DummyMessageHandler(latch, true);
+ consumer2.setMessageHandler(dummyMessageHandler2);
+ assertTrue(latch.await(10, TimeUnit.SECONDS));
+ assertTrue(dummyMessageHandler.list.size() == 100);
+ assertTrue(dummyMessageHandler2.list.size() == 0);
+ consumer.close();
+ consumer2.close();
+ }
+
+ public void testMultipleGrouping() throws Exception
+ {
+ ClientProducer clientProducer = clientSession.createProducer(qName);
+ ClientConsumer consumer = clientSession.createConsumer(qName);
+ ClientConsumer consumer2 = clientSession.createConsumer(qName);
+ clientSession.start();
+ SimpleString groupId = new SimpleString("grp1");
+ SimpleString groupId2 = new SimpleString("grp2");
+ int numMessages = 100;
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = createTextMessage("m" + i, clientSession);
+ if( i % 2 == 0 || i == 0)
+ {
+ message.putStringProperty(MessageImpl.HDR_GROUP_ID, groupId);
+ }
+ else
+ {
+ message.putStringProperty(MessageImpl.HDR_GROUP_ID, groupId2);
+ }
+ clientProducer.send(message);
+ }
+ CountDownLatch latch = new CountDownLatch(numMessages);
+ DummyMessageHandler dummyMessageHandler = new DummyMessageHandler(latch, true);
+ consumer.setMessageHandler(dummyMessageHandler);
+ DummyMessageHandler dummyMessageHandler2 = new DummyMessageHandler(latch, true);
+ consumer2.setMessageHandler(dummyMessageHandler2);
+ assertTrue(latch.await(10, TimeUnit.SECONDS));
+ assertEquals(dummyMessageHandler.list.size(), 50);
+ int i = 0;
+ for (ClientMessage message : dummyMessageHandler.list)
+ {
+ assertEquals(message.getBody().getString(), "m" + i);
+ i += 2;
+ }
+ assertEquals(dummyMessageHandler2.list.size(), 50);
+ i = 1;
+ for (ClientMessage message : dummyMessageHandler2.list)
+ {
+ assertEquals(message.getBody().getString(), "m" + i);
+ i += 2;
+ }
+ consumer.close();
+ consumer2.close();
+ }
+
+ public void testMultipleGroupingStartConsumersAfterMessagesSent() throws Exception
+ {
+ ClientProducer clientProducer = clientSession.createProducer(qName);
+ ClientConsumer consumer = clientSession.createConsumer(qName);
+ ClientConsumer consumer2 = clientSession.createConsumer(qName);
+ SimpleString groupId = new SimpleString("grp1");
+ SimpleString groupId2 = new SimpleString("grp2");
+ int numMessages = 100;
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = createTextMessage("m" + i, clientSession);
+ if( i % 2 == 0 || i == 0)
+ {
+ message.putStringProperty(MessageImpl.HDR_GROUP_ID, groupId);
+ }
+ else
+ {
+ message.putStringProperty(MessageImpl.HDR_GROUP_ID, groupId2);
+ }
+ clientProducer.send(message);
+ }
+
+ clientSession.start();
+ CountDownLatch latch = new CountDownLatch(numMessages);
+ DummyMessageHandler dummyMessageHandler = new DummyMessageHandler(latch, true);
+ consumer.setMessageHandler(dummyMessageHandler);
+ DummyMessageHandler dummyMessageHandler2 = new DummyMessageHandler(latch, true);
+ consumer2.setMessageHandler(dummyMessageHandler2);
+ assertTrue(latch.await(10, TimeUnit.SECONDS));
+ assertEquals(dummyMessageHandler.list.size(), 50);
+ int i = 0;
+ for (ClientMessage message : dummyMessageHandler.list)
+ {
+ assertEquals(message.getBody().getString(), "m" + i);
+ i += 2;
+ }
+ assertEquals(dummyMessageHandler2.list.size(), 50);
+ i = 1;
+ for (ClientMessage message : dummyMessageHandler2.list)
+ {
+ assertEquals(message.getBody().getString(), "m" + i);
+ i += 2;
+ }
+ consumer.close();
+ consumer2.close();
+ }
+
+ public void testMultipleGroupingConsumeHalf() throws Exception
+ {
+ ClientProducer clientProducer = clientSession.createProducer(qName);
+ ClientConsumer consumer = clientSession.createConsumer(qName);
+ ClientConsumer consumer2 = clientSession.createConsumer(qName);
+ clientSession.start();
+ SimpleString groupId = new SimpleString("grp1");
+ SimpleString groupId2 = new SimpleString("grp2");
+ int numMessages = 100;
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = createTextMessage("m" + i, clientSession);
+ if( i % 2 == 0 || i == 0)
+ {
+ message.putStringProperty(MessageImpl.HDR_GROUP_ID, groupId);
+ }
+ else
+ {
+ message.putStringProperty(MessageImpl.HDR_GROUP_ID, groupId2);
+ }
+ clientProducer.send(message);
+ }
+
+ for(int i = 0; i < numMessages/2; i++)
+ {
+ ClientMessage cm = consumer.receive(500);
+ assertNotNull(cm);
+ assertEquals(cm.getBody().getString(), "m" + i);
+ i++;
+ cm = consumer2.receive(500);
+ assertNotNull(cm);
+ assertEquals(cm.getBody().getString(), "m" + i);
+ }
+
+ consumer2.close();
+ consumer.close();
+ //check that within their groups the messages are still in the correct order
+ consumer = clientSession.createConsumer(qName);
+ for(int i = 0; i < numMessages; i+=2)
+ {
+ ClientMessage cm = consumer.receive(500);
+ assertNotNull(cm);
+ assertEquals(cm.getBody().getString(), "m" + i);
+ }
+ for(int i = 1; i < numMessages; i+=2)
+ {
+ ClientMessage cm = consumer.receive(500);
+ assertNotNull(cm);
+ assertEquals(cm.getBody().getString(), "m" + i);
+ }
+ consumer.close();
+ }
+
+ public void testMultipleGroupingSingleConsumer() throws Exception
+ {
+ ClientProducer clientProducer = clientSession.createProducer(qName);
+ ClientConsumer consumer = clientSession.createConsumer(qName);
+ clientSession.start();
+ SimpleString groupId = new SimpleString("grp1");
+ SimpleString groupId2 = new SimpleString("grp2");
+ int numMessages = 100;
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = createTextMessage("m" + i, clientSession);
+ if( i % 2 == 0 || i == 0)
+ {
+ message.putStringProperty(MessageImpl.HDR_GROUP_ID, groupId);
+ }
+ else
+ {
+ message.putStringProperty(MessageImpl.HDR_GROUP_ID, groupId2);
+ }
+ clientProducer.send(message);
+ }
+ CountDownLatch latch = new CountDownLatch(numMessages);
+ DummyMessageHandler dummyMessageHandler = new DummyMessageHandler(latch, true);
+ consumer.setMessageHandler(dummyMessageHandler);
+ assertTrue(latch.await(10, TimeUnit.SECONDS));
+ assertEquals(dummyMessageHandler.list.size(), 100);
+ int i = 0;
+ for (ClientMessage message : dummyMessageHandler.list)
+ {
+ assertEquals(message.getBody().getString(), "m" + i);
+ i += 1;
+ }
+ consumer.close();
+ }
+
+ public void testMultipleGroupingTXCommit() throws Exception
+ {
+ ClientSessionFactory sessionFactory = new ClientSessionFactoryImpl(new TransportConfiguration(INVM_CONNECTOR_FACTORY));
+ ClientSession clientSession = sessionFactory.createSession(false, false, false);
+ ClientProducer clientProducer = this.clientSession.createProducer(qName);
+ clientSession.start();
+ ClientConsumer consumer = clientSession.createConsumer(qName);
+ ClientConsumer consumer2 = clientSession.createConsumer(qName);
+
+ SimpleString groupId = new SimpleString("grp1");
+ SimpleString groupId2 = new SimpleString("grp2");
+ int numMessages = 100;
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = createTextMessage("m" + i, clientSession);
+ if( i % 2 == 0 || i == 0)
+ {
+ message.putStringProperty(MessageImpl.HDR_GROUP_ID, groupId);
+ }
+ else
+ {
+ message.putStringProperty(MessageImpl.HDR_GROUP_ID, groupId2);
+ }
+ clientProducer.send(message);
+ }
+ CountDownLatch latch = new CountDownLatch(numMessages);
+ DummyMessageHandler dummyMessageHandler = new DummyMessageHandler(latch, true);
+ consumer.setMessageHandler(dummyMessageHandler);
+ DummyMessageHandler dummyMessageHandler2 = new DummyMessageHandler(latch, true);
+ consumer2.setMessageHandler(dummyMessageHandler2);
+ assertTrue(latch.await(10, TimeUnit.SECONDS));
+ clientSession.commit();
+ assertEquals(dummyMessageHandler.list.size(), 50);
+ int i = 0;
+ for (ClientMessage message : dummyMessageHandler.list)
+ {
+ assertEquals(message.getBody().getString(), "m" + i);
+ i += 2;
+ }
+ assertEquals(dummyMessageHandler2.list.size(), 50);
+ i = 1;
+ for (ClientMessage message : dummyMessageHandler2.list)
+ {
+ assertEquals(message.getBody().getString(), "m" + i);
+ i += 2;
+ }
+ consumer.close();
+ consumer2.close();
+ consumer = this.clientSession.createConsumer(qName);
+ assertNull(consumer.receive(500));
+ }
+
+ public void testMultipleGroupingTXRollback() throws Exception
+ {
+ ClientSessionFactory sessionFactory = new ClientSessionFactoryImpl(new TransportConfiguration(INVM_CONNECTOR_FACTORY));
+ sessionFactory.setBlockOnAcknowledge(true);
+ ClientSession clientSession = sessionFactory.createSession(false, false, false);
+ ClientProducer clientProducer = this.clientSession.createProducer(qName);
+ ClientConsumer consumer = clientSession.createConsumer(qName);
+ ClientConsumer consumer2 = clientSession.createConsumer(qName);
+ clientSession.start();
+ SimpleString groupId = new SimpleString("grp1");
+ SimpleString groupId2 = new SimpleString("grp2");
+ int numMessages = 100;
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = createTextMessage("m" + i, clientSession);
+ if( i % 2 == 0 || i == 0)
+ {
+ message.putStringProperty(MessageImpl.HDR_GROUP_ID, groupId);
+ }
+ else
+ {
+ message.putStringProperty(MessageImpl.HDR_GROUP_ID, groupId2);
+ }
+ clientProducer.send(message);
+ }
+ CountDownLatch latch = new CountDownLatch(numMessages);
+ DummyMessageHandler dummyMessageHandler = new DummyMessageHandler(latch, true);
+ consumer.setMessageHandler(dummyMessageHandler);
+ DummyMessageHandler dummyMessageHandler2 = new DummyMessageHandler(latch, true);
+ consumer2.setMessageHandler(dummyMessageHandler2);
+ assertTrue(latch.await(10, TimeUnit.SECONDS));
+ assertEquals(dummyMessageHandler.list.size(), 50);
+ int i = 0;
+ for (ClientMessage message : dummyMessageHandler.list)
+ {
+ assertEquals(message.getBody().getString(), "m" + i);
+ i += 2;
+ }
+ assertEquals(dummyMessageHandler2.list.size(), 50);
+ i = 1;
+ for (ClientMessage message : dummyMessageHandler2.list)
+ {
+ assertEquals(message.getBody().getString(), "m" + i);
+ i += 2;
+ }
+ latch = new CountDownLatch(numMessages);
+ dummyMessageHandler.reset(latch);
+ dummyMessageHandler2.reset(latch);
+ clientSession.rollback();
+ assertTrue(latch.await(10, TimeUnit.SECONDS));
+ assertEquals(dummyMessageHandler.list.size(), 50);
+ i = 0;
+ for (ClientMessage message : dummyMessageHandler.list)
+ {
+ assertEquals(message.getBody().getString(), "m" + i);
+ i += 2;
+ }
+ assertEquals(dummyMessageHandler2.list.size(), 50);
+ i = 1;
+ for (ClientMessage message : dummyMessageHandler2.list)
+ {
+ assertEquals(message.getBody().getString(), "m" + i);
+ i += 2;
+ }
+ consumer = this.clientSession.createConsumer(qName);
+ assertNull(consumer.receive(500));
+ }
+
+ public void testMultipleGroupingXACommit() throws Exception
+ {
+ ClientSessionFactory sessionFactory = new ClientSessionFactoryImpl(new TransportConfiguration(INVM_CONNECTOR_FACTORY));
+ ClientSession clientSession = sessionFactory.createSession(true, false, false);
+ ClientProducer clientProducer = this.clientSession.createProducer(qName);
+ ClientConsumer consumer = clientSession.createConsumer(qName);
+ ClientConsumer consumer2 = clientSession.createConsumer(qName);
+ clientSession.start();
+ Xid xid = new XidImpl("bq".getBytes(), 4, "gtid".getBytes());
+ clientSession.start(xid, XAResource.TMNOFLAGS);
+
+ SimpleString groupId = new SimpleString("grp1");
+ SimpleString groupId2 = new SimpleString("grp2");
+ int numMessages = 100;
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = createTextMessage("m" + i, clientSession);
+ if( i % 2 == 0 || i == 0)
+ {
+ message.putStringProperty(MessageImpl.HDR_GROUP_ID, groupId);
+ }
+ else
+ {
+ message.putStringProperty(MessageImpl.HDR_GROUP_ID, groupId2);
+ }
+ clientProducer.send(message);
+ }
+ CountDownLatch latch = new CountDownLatch(numMessages);
+ DummyMessageHandler dummyMessageHandler = new DummyMessageHandler(latch, true);
+ consumer.setMessageHandler(dummyMessageHandler);
+ DummyMessageHandler dummyMessageHandler2 = new DummyMessageHandler(latch, true);
+ consumer2.setMessageHandler(dummyMessageHandler2);
+ assertTrue(latch.await(10, TimeUnit.SECONDS));
+ clientSession.end(xid, XAResource.TMSUCCESS);
+ clientSession.prepare(xid);
+ clientSession.commit(xid, true);
+ assertEquals(dummyMessageHandler.list.size(), 50);
+ int i = 0;
+ for (ClientMessage message : dummyMessageHandler.list)
+ {
+ assertEquals(message.getBody().getString(), "m" + i);
+ i += 2;
+ }
+ assertEquals(dummyMessageHandler2.list.size(), 50);
+ i = 1;
+ for (ClientMessage message : dummyMessageHandler2.list)
+ {
+ assertEquals(message.getBody().getString(), "m" + i);
+ i += 2;
+ }
+ consumer.close();
+ consumer2.close();
+ consumer = this.clientSession.createConsumer(qName);
+ assertNull(consumer.receive(500));
+ }
+
+ public void testMultipleGroupingXARollback() throws Exception
+ {
+ ClientSessionFactory sessionFactory = new ClientSessionFactoryImpl(new TransportConfiguration(INVM_CONNECTOR_FACTORY));
+ sessionFactory.setBlockOnAcknowledge(true);
+ ClientSession clientSession = sessionFactory.createSession(true, false, false);
+ ClientProducer clientProducer = this.clientSession.createProducer(qName);
+ clientSession.start();
+ ClientConsumer consumer = clientSession.createConsumer(qName);
+ ClientConsumer consumer2 = clientSession.createConsumer(qName);
+ Xid xid = new XidImpl("bq".getBytes(), 4, "gtid".getBytes());
+ clientSession.start(xid, XAResource.TMNOFLAGS);
+
+ SimpleString groupId = new SimpleString("grp1");
+ SimpleString groupId2 = new SimpleString("grp2");
+ int numMessages = 100;
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = createTextMessage("m" + i, clientSession);
+ if( i % 2 == 0 || i == 0)
+ {
+ message.putStringProperty(MessageImpl.HDR_GROUP_ID, groupId);
+ }
+ else
+ {
+ message.putStringProperty(MessageImpl.HDR_GROUP_ID, groupId2);
+ }
+ clientProducer.send(message);
+ }
+ CountDownLatch latch = new CountDownLatch(numMessages);
+ DummyMessageHandler dummyMessageHandler = new DummyMessageHandler(latch, true);
+ consumer.setMessageHandler(dummyMessageHandler);
+ DummyMessageHandler dummyMessageHandler2 = new DummyMessageHandler(latch, true);
+ consumer2.setMessageHandler(dummyMessageHandler2);
+ assertTrue(latch.await(10, TimeUnit.SECONDS));
+ clientSession.end(xid, XAResource.TMSUCCESS);
+ assertEquals(dummyMessageHandler.list.size(), 50);
+ int i = 0;
+ for (ClientMessage message : dummyMessageHandler.list)
+ {
+ assertEquals(message.getBody().getString(), "m" + i);
+ i += 2;
+ }
+ assertEquals(dummyMessageHandler2.list.size(), 50);
+ i = 1;
+ for (ClientMessage message : dummyMessageHandler2.list)
+ {
+ assertEquals(message.getBody().getString(), "m" + i);
+ i += 2;
+ }
+ latch = new CountDownLatch(numMessages);
+ dummyMessageHandler.reset(latch);
+ dummyMessageHandler2.reset(latch);
+ clientSession.rollback(xid);
+ clientSession.start(xid, XAResource.TMNOFLAGS);
+ assertTrue(latch.await(10, TimeUnit.SECONDS));
+ clientSession.end(xid, XAResource.TMSUCCESS);
+ clientSession.prepare(xid);
+ clientSession.commit(xid, false);
+ assertEquals(dummyMessageHandler.list.size(), 50);
+ i = 0;
+ for (ClientMessage message : dummyMessageHandler.list)
+ {
+ assertEquals(message.getBody().getString(), "m" + i);
+ i += 2;
+ }
+ assertEquals(dummyMessageHandler2.list.size(), 50);
+ i = 1;
+ for (ClientMessage message : dummyMessageHandler2.list)
+ {
+ assertEquals(message.getBody().getString(), "m" + i);
+ i += 2;
+ }
+ consumer = this.clientSession.createConsumer(qName);
+ assertNull(consumer.receive(500));
+ }
+
+ protected void tearDown() throws Exception
+ {
+ if (clientSession != null)
+ {
+ try
+ {
+ clientSession.close();
+ }
+ catch (MessagingException e1)
+ {
+ //
+ }
+ }
+ if (messagingService != null && messagingService.isStarted())
+ {
+ try
+ {
+ messagingService.stop();
+ }
+ catch (Exception e1)
+ {
+ //
+ }
+ }
+ messagingService = null;
+ clientSession = null;
+ }
+
+ protected void setUp() throws Exception
+ {
+ ConfigurationImpl configuration = new ConfigurationImpl();
+ configuration.setSecurityEnabled(false);
+ TransportConfiguration transportConfig = new TransportConfiguration(INVM_ACCEPTOR_FACTORY);
+ configuration.getAcceptorConfigurations().add(transportConfig);
+ messagingService = MessagingServiceImpl.newNullStorageMessagingServer(configuration);
+ // start the server
+ messagingService.start();
+
+ QueueSettings qs = new QueueSettings();
+ qs.setDistributionPolicyClass(GroupingRoundRobinDistributionPolicy.class.getName());
+ messagingService.getServer().getQueueSettingsRepository().addMatch(qName.toString(), qs);
+ // then we create a client as normal
+ ClientSessionFactory sessionFactory = new ClientSessionFactoryImpl(new TransportConfiguration(INVM_CONNECTOR_FACTORY));
+ clientSession = sessionFactory.createSession(false, true, true);
+ clientSession.createQueue(qName, qName, null, false, false, true);
+ }
+
+ private static class DummyMessageHandler implements MessageHandler
+ {
+ ArrayList<ClientMessage> list = new ArrayList<ClientMessage>();
+
+ private CountDownLatch latch;
+
+ private final boolean acknowledge;
+
+ public DummyMessageHandler(CountDownLatch latch, boolean acknowledge)
+ {
+ this.latch = latch;
+ this.acknowledge = acknowledge;
+ }
+
+ public void onMessage(ClientMessage message)
+ {
+ list.add(message);
+ if (acknowledge)
+ {
+ try
+ {
+ message.acknowledge();
+ }
+ catch (MessagingException e)
+ {
+ //ignore
+ }
+ }
+ latch.countDown();
+ }
+
+ public void reset(CountDownLatch latch)
+ {
+ list.clear();
+ this.latch = latch;
+ }
+ }
+}
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/GroupingRoundRobinDistributionPolicyTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/GroupingRoundRobinDistributionPolicyTest.java 2008-12-04 01:40:14 UTC (rev 5459)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/GroupingRoundRobinDistributionPolicyTest.java 2008-12-04 11:24:01 UTC (rev 5460)
@@ -195,9 +195,8 @@
EasyMock.expect(reference.getMessage()).andStubReturn(serverMessage);
EasyMock.expect(serverMessage.getProperty(MessageImpl.HDR_GROUP_ID)).andStubReturn(new SimpleString("gid1"));
EasyMock.expect(consumer.handle(reference)).andReturn(HandleStatus.BUSY);
- EasyMock.expect(consumer2.handle(reference)).andReturn(HandleStatus.HANDLED);
EasyMock.replay(consumer, consumer2, consumer3, serverMessage, reference);
- assertEquals(HandleStatus.HANDLED, policy.distribute(reference));
+ assertEquals(HandleStatus.BUSY, policy.distribute(reference));
EasyMock.verify(consumer, consumer2, consumer3, serverMessage, reference);
}
More information about the jboss-cvs-commits
mailing list