KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > broker > policy > StrictOrderDispatchPolicyTest


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.broker.policy;
19
20 import java.util.Iterator JavaDoc;
21
22 import org.apache.activemq.broker.BrokerService;
23 import org.apache.activemq.broker.TopicSubscriptionTest;
24 import org.apache.activemq.broker.region.policy.PolicyEntry;
25 import org.apache.activemq.broker.region.policy.PolicyMap;
26 import org.apache.activemq.broker.region.policy.StrictOrderDispatchPolicy;
27 import org.apache.activemq.util.MessageIdList;
28
29 public class StrictOrderDispatchPolicyTest extends TopicSubscriptionTest {
30
31     protected BrokerService createBroker() throws Exception JavaDoc {
32         BrokerService broker = super.createBroker();
33
34         PolicyEntry policy = new PolicyEntry();
35         policy.setDispatchPolicy(new StrictOrderDispatchPolicy());
36
37         PolicyMap pMap = new PolicyMap();
38         pMap.setDefaultEntry(policy);
39
40         broker.setDestinationPolicy(pMap);
41
42         return broker;
43     }
44
45     public void testOneProducerTwoConsumersLargeMessagesOnePrefetch() throws Exception JavaDoc {
46         super.testOneProducerTwoConsumersLargeMessagesOnePrefetch();
47
48         assertReceivedMessagesAreOrdered();
49     }
50
51     public void testOneProducerTwoConsumersSmallMessagesOnePrefetch() throws Exception JavaDoc {
52         super.testOneProducerTwoConsumersSmallMessagesOnePrefetch();
53
54         assertReceivedMessagesAreOrdered();
55     }
56
57     public void testOneProducerTwoConsumersSmallMessagesLargePrefetch() throws Exception JavaDoc {
58         super.testOneProducerTwoConsumersSmallMessagesLargePrefetch();
59
60         assertReceivedMessagesAreOrdered();
61     }
62
63     public void testOneProducerTwoConsumersLargeMessagesLargePrefetch() throws Exception JavaDoc {
64         super.testOneProducerTwoConsumersLargeMessagesLargePrefetch();
65
66         assertReceivedMessagesAreOrdered();
67     }
68
69     public void testOneProducerManyConsumersFewMessages() throws Exception JavaDoc {
70         super.testOneProducerManyConsumersFewMessages();
71
72         assertReceivedMessagesAreOrdered();
73     }
74
75     public void testOneProducerManyConsumersManyMessages() throws Exception JavaDoc {
76         super.testOneProducerManyConsumersManyMessages();
77
78         assertReceivedMessagesAreOrdered();
79     }
80
81     public void testManyProducersOneConsumer() throws Exception JavaDoc {
82         super.testManyProducersOneConsumer();
83
84         assertReceivedMessagesAreOrdered();
85     }
86
87     public void testManyProducersManyConsumers() throws Exception JavaDoc {
88         super.testManyProducersManyConsumers();
89
90         assertReceivedMessagesAreOrdered();
91     }
92
93     public void assertReceivedMessagesAreOrdered() throws Exception JavaDoc {
94         // If there is only one consumer, messages is definitely ordered
95
if (consumers.size() <= 1) {
96             return;
97         }
98
99         // Get basis of order
100
Iterator JavaDoc i = consumers.keySet().iterator();
101         MessageIdList messageOrder = (MessageIdList)consumers.get(i.next());
102
103         for (;i.hasNext();) {
104             MessageIdList messageIdList = (MessageIdList)consumers.get(i.next());
105             assertTrue("Messages are not ordered.", messageOrder.equals(messageIdList));
106         }
107     }
108 }
109
Popular Tags