1 18 package org.apache.activemq.broker.policy; 19 20 import org.apache.activemq.broker.QueueSubscriptionTest; 21 import org.apache.activemq.broker.BrokerService; 22 import org.apache.activemq.broker.region.policy.FixedCountSubscriptionRecoveryPolicy; 23 import org.apache.activemq.broker.region.policy.PolicyEntry; 24 import org.apache.activemq.broker.region.policy.PolicyMap; 25 import org.apache.activemq.broker.region.policy.SimpleDispatchPolicy; 26 import org.apache.activemq.util.MessageIdList; 27 28 import java.util.Iterator ; 29 import java.util.List ; 30 31 public class SimpleDispatchPolicyTest extends QueueSubscriptionTest { 32 33 protected BrokerService createBroker() throws Exception { 34 BrokerService broker = super.createBroker(); 35 36 PolicyEntry policy = new PolicyEntry(); 37 policy.setDispatchPolicy(new SimpleDispatchPolicy()); 38 policy.setSubscriptionRecoveryPolicy(new FixedCountSubscriptionRecoveryPolicy()); 39 PolicyMap pMap = new PolicyMap(); 40 pMap.setDefaultEntry(policy); 41 42 broker.setDestinationPolicy(pMap); 43 44 return broker; 45 } 46 47 public void testOneProducerTwoConsumersSmallMessagesLargePrefetch() throws Exception { 48 super.testOneProducerTwoConsumersSmallMessagesLargePrefetch(); 49 50 assertOneConsumerReceivedAllMessages(messageCount); 52 } 53 54 public void testOneProducerTwoConsumersLargeMessagesLargePrefetch() throws Exception { 55 super.testOneProducerTwoConsumersLargeMessagesLargePrefetch(); 56 57 assertOneConsumerReceivedAllMessages(messageCount); 59 } 60 61 public void assertOneConsumerReceivedAllMessages(int messageCount) throws Exception { 62 boolean found = false; 63 for (Iterator i=consumers.keySet().iterator(); i.hasNext();) { 64 MessageIdList messageIdList = (MessageIdList)consumers.get(i.next()); 65 int count = messageIdList.getMessageCount(); 66 if (count > 0) { 67 if (found) { 68 fail("No other consumers should have received any messages"); 69 } else { 70 assertEquals("Consumer should have received all messages.", messageCount, count); 71 found = true; 72 } 73 } 74 } 75 76 if (!found) { 77 fail("At least one consumer should have received all messages"); 78 } 79 } 80 } 81 | Popular Tags |