KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > usecases > ThreeBrokerQueueNetworkTest


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.usecases;
19
20 import org.apache.activemq.JmsMultipleBrokersTestSupport;
21 import org.apache.activemq.util.MessageIdList;
22
23 import javax.jms.Destination JavaDoc;
24 import javax.jms.MessageConsumer JavaDoc;
25 import java.net.URI JavaDoc;
26
27 /**
28  * @version $Revision: 1.1.1.1 $
29  */

30 public class ThreeBrokerQueueNetworkTest extends JmsMultipleBrokersTestSupport {
31     protected static final int MESSAGE_COUNT = 100;
32
33     /**
34      * BrokerA -> BrokerB -> BrokerC
35      */

36     public void test_AB_BC_BrokerNetwork() throws Exception JavaDoc {
37         // Setup broker networks
38
bridgeBrokers("BrokerA", "BrokerB");
39         bridgeBrokers("BrokerB", "BrokerC");
40
41         startAllBrokers();
42
43         // Setup destination
44
Destination JavaDoc dest = createDestination("TEST.FOO", false);
45
46         // Setup consumers
47
MessageConsumer JavaDoc clientC = createConsumer("BrokerC", dest);
48
49         // Send messages
50
sendMessages("BrokerA", dest, MESSAGE_COUNT);
51
52         // Let's try to wait for any messages. Should be none.
53
Thread.sleep(1000);
54
55         // Get message count
56
MessageIdList msgsC = getConsumerMessages("BrokerC", clientC);
57         assertEquals(0, msgsC.getMessageCount());
58     }
59
60     /**
61      * BrokerA <- BrokerB -> BrokerC
62      */

63     public void test_BA_BC_BrokerNetwork() throws Exception JavaDoc {
64         // Setup broker networks
65
bridgeBrokers("BrokerB", "BrokerA");
66         bridgeBrokers("BrokerB", "BrokerC");
67
68         startAllBrokers();
69
70         // Setup destination
71
Destination JavaDoc dest = createDestination("TEST.FOO", false);
72
73         // Setup consumers
74
MessageConsumer JavaDoc clientA = createConsumer("BrokerA", dest);
75         MessageConsumer JavaDoc clientC = createConsumer("BrokerC", dest);
76         Thread.sleep(2000); //et subscriptions get propagated
77
// Send messages
78
sendMessages("BrokerB", dest, MESSAGE_COUNT);
79
80         // Let's try to wait for any messages.
81
Thread.sleep(1000);
82
83         // Get message count
84
MessageIdList msgsA = getConsumerMessages("BrokerA", clientA);
85         MessageIdList msgsC = getConsumerMessages("BrokerC", clientC);
86
87         // Total received should be 100
88
assertEquals(MESSAGE_COUNT, msgsA.getMessageCount() + msgsC.getMessageCount());
89     }
90
91     /**
92      * BrokerA -> BrokerB <- BrokerC
93      */

94     public void test_AB_CB_BrokerNetwork() throws Exception JavaDoc {
95         // Setup broker networks
96
bridgeBrokers("BrokerA", "BrokerB");
97         bridgeBrokers("BrokerC", "BrokerB");
98
99         startAllBrokers();
100
101         // Setup destination
102
Destination JavaDoc dest = createDestination("TEST.FOO", false);
103
104         // Setup consumers
105
MessageConsumer JavaDoc clientB = createConsumer("BrokerB", dest);
106
107         // Send messages
108
sendMessages("BrokerA", dest, MESSAGE_COUNT);
109         sendMessages("BrokerC", dest, MESSAGE_COUNT);
110
111         // Get message count
112
MessageIdList msgsB = getConsumerMessages("BrokerB", clientB);
113
114         msgsB.waitForMessagesToArrive(MESSAGE_COUNT * 2);
115
116         assertEquals(MESSAGE_COUNT * 2, msgsB.getMessageCount());
117     }
118
119     /**
120      * BrokerA <-> BrokerB <-> BrokerC
121      */

122     public void testAllConnectedBrokerNetwork() throws Exception JavaDoc {
123         // Setup broker networks
124
bridgeBrokers("BrokerA", "BrokerB");
125         bridgeBrokers("BrokerB", "BrokerA");
126         bridgeBrokers("BrokerB", "BrokerC");
127         bridgeBrokers("BrokerC", "BrokerB");
128         bridgeBrokers("BrokerA", "BrokerC");
129         bridgeBrokers("BrokerC", "BrokerA");
130
131         startAllBrokers();
132
133         // Setup destination
134
Destination JavaDoc dest = createDestination("TEST.FOO", false);
135
136         // Setup consumers
137
MessageConsumer JavaDoc clientA = createConsumer("BrokerA", dest);
138         MessageConsumer JavaDoc clientB = createConsumer("BrokerB", dest);
139         MessageConsumer JavaDoc clientC = createConsumer("BrokerC", dest);
140
141         // Send messages
142
sendMessages("BrokerA", dest, MESSAGE_COUNT);
143         sendMessages("BrokerB", dest, MESSAGE_COUNT);
144         sendMessages("BrokerC", dest, MESSAGE_COUNT);
145
146         // Let's try to wait for any messages.
147
Thread.sleep(1000);
148
149         // Get message count
150
MessageIdList msgsA = getConsumerMessages("BrokerA", clientA);
151         MessageIdList msgsB = getConsumerMessages("BrokerB", clientB);
152         MessageIdList msgsC = getConsumerMessages("BrokerC", clientC);
153
154         assertEquals(MESSAGE_COUNT * 3, msgsA.getMessageCount() + msgsB.getMessageCount() + msgsC.getMessageCount());
155     }
156
157     /**
158      * BrokerA <-> BrokerB <-> BrokerC
159      */

160     public void testAllConnectedUsingMulticast() throws Exception JavaDoc {
161         // Setup broker networks
162
bridgeAllBrokers();
163
164         startAllBrokers();
165
166         // Setup destination
167
Destination JavaDoc dest = createDestination("TEST.FOO", false);
168
169         // Setup consumers
170
MessageConsumer JavaDoc clientA = createConsumer("BrokerA", dest);
171         MessageConsumer JavaDoc clientB = createConsumer("BrokerB", dest);
172         MessageConsumer JavaDoc clientC = createConsumer("BrokerC", dest);
173
174         // Send messages
175
sendMessages("BrokerA", dest, MESSAGE_COUNT);
176         sendMessages("BrokerB", dest, MESSAGE_COUNT);
177         sendMessages("BrokerC", dest, MESSAGE_COUNT);
178
179         // Let's try to wait for any messages.
180
Thread.sleep(1000);
181
182         // Get message count
183
MessageIdList msgsA = getConsumerMessages("BrokerA", clientA);
184         MessageIdList msgsB = getConsumerMessages("BrokerB", clientB);
185         MessageIdList msgsC = getConsumerMessages("BrokerC", clientC);
186
187         assertEquals(MESSAGE_COUNT * 3, msgsA.getMessageCount() + msgsB.getMessageCount() + msgsC.getMessageCount());
188     }
189
190     public void setUp() throws Exception JavaDoc {
191         super.setAutoFail(true);
192         super.setUp();
193         createBroker(new URI JavaDoc("broker:(tcp://localhost:61616)/BrokerA?persistent=false&useJmx=false"));
194         createBroker(new URI JavaDoc("broker:(tcp://localhost:61617)/BrokerB?persistent=false&useJmx=false"));
195         createBroker(new URI JavaDoc("broker:(tcp://localhost:61618)/BrokerC?persistent=false&useJmx=false"));
196     }
197 }
198
Popular Tags