KickJava   Java API By Example, From Geeks To Geeks.

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


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

30 public class ThreeBrokerTopicNetworkTest 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", true);
45
46         // Setup consumers
47
MessageConsumer JavaDoc clientA = createConsumer("BrokerA", dest);
48         MessageConsumer JavaDoc clientB = createConsumer("BrokerB", dest);
49         MessageConsumer JavaDoc clientC = createConsumer("BrokerC", dest);
50
51 // let consumers propogate around the network
52
Thread.sleep(2000);
53         // Send messages
54
sendMessages("BrokerA", dest, MESSAGE_COUNT);
55         sendMessages("BrokerB", dest, MESSAGE_COUNT);
56         sendMessages("BrokerC", dest, MESSAGE_COUNT);
57
58         // Get message count
59
MessageIdList msgsA = getConsumerMessages("BrokerA", clientA);
60         MessageIdList msgsB = getConsumerMessages("BrokerB", clientB);
61         MessageIdList msgsC = getConsumerMessages("BrokerC", clientC);
62
63         msgsA.waitForMessagesToArrive(MESSAGE_COUNT);
64         msgsB.waitForMessagesToArrive(MESSAGE_COUNT * 2);
65         msgsC.waitForMessagesToArrive(MESSAGE_COUNT * 2);
66
67         assertEquals(MESSAGE_COUNT, msgsA.getMessageCount());
68         assertEquals(MESSAGE_COUNT * 2, msgsB.getMessageCount());
69         assertEquals(MESSAGE_COUNT * 2, msgsC.getMessageCount());
70     }
71
72     /**
73      * BrokerA <- BrokerB -> BrokerC
74      */

75     public void test_BA_BC_BrokerNetwork() throws Exception JavaDoc {
76         // Setup broker networks
77
bridgeBrokers("BrokerB", "BrokerA");
78         bridgeBrokers("BrokerB", "BrokerC");
79
80         startAllBrokers();
81
82         // Setup destination
83
Destination JavaDoc dest = createDestination("TEST.FOO", true);
84
85         // Setup consumers
86
MessageConsumer JavaDoc clientA = createConsumer("BrokerA", dest);
87         MessageConsumer JavaDoc clientB = createConsumer("BrokerB", dest);
88         MessageConsumer JavaDoc clientC = createConsumer("BrokerC", dest);
89
90 // let consumers propogate around the network
91
Thread.sleep(2000);
92         // Send messages
93
sendMessages("BrokerA", dest, MESSAGE_COUNT);
94         sendMessages("BrokerB", dest, MESSAGE_COUNT);
95         sendMessages("BrokerC", dest, MESSAGE_COUNT);
96
97         // Get message count
98
MessageIdList msgsA = getConsumerMessages("BrokerA", clientA);
99         MessageIdList msgsB = getConsumerMessages("BrokerB", clientB);
100         MessageIdList msgsC = getConsumerMessages("BrokerC", clientC);
101
102         msgsA.waitForMessagesToArrive(MESSAGE_COUNT * 2);
103         msgsB.waitForMessagesToArrive(MESSAGE_COUNT);
104         msgsC.waitForMessagesToArrive(MESSAGE_COUNT * 2);
105
106         assertEquals(MESSAGE_COUNT * 2, msgsA.getMessageCount());
107         assertEquals(MESSAGE_COUNT, msgsB.getMessageCount());
108         assertEquals(MESSAGE_COUNT * 2, msgsC.getMessageCount());
109     }
110
111     /**
112      * BrokerA -> BrokerB <- BrokerC
113      */

114     public void test_AB_CB_BrokerNetwork() throws Exception JavaDoc {
115         // Setup broker networks
116
bridgeBrokers("BrokerA", "BrokerB");
117         bridgeBrokers("BrokerC", "BrokerB");
118
119         startAllBrokers();
120
121         // Setup destination
122
Destination JavaDoc dest = createDestination("TEST.FOO", true);
123
124         // Setup consumers
125
MessageConsumer JavaDoc clientA = createConsumer("BrokerA", dest);
126         MessageConsumer JavaDoc clientB = createConsumer("BrokerB", dest);
127         MessageConsumer JavaDoc clientC = createConsumer("BrokerC", dest);
128
129 // let consumers propogate around the network
130
Thread.sleep(2000);
131         
132         // Send messages
133
sendMessages("BrokerA", dest, MESSAGE_COUNT);
134         sendMessages("BrokerB", dest, MESSAGE_COUNT);
135         sendMessages("BrokerC", dest, MESSAGE_COUNT);
136
137         // Get message count
138
MessageIdList msgsA = getConsumerMessages("BrokerA", clientA);
139         MessageIdList msgsB = getConsumerMessages("BrokerB", clientB);
140         MessageIdList msgsC = getConsumerMessages("BrokerC", clientC);
141
142         msgsA.waitForMessagesToArrive(MESSAGE_COUNT);
143         msgsB.waitForMessagesToArrive(MESSAGE_COUNT * 3);
144         msgsC.waitForMessagesToArrive(MESSAGE_COUNT);
145
146         assertEquals(MESSAGE_COUNT, msgsA.getMessageCount());
147         assertEquals(MESSAGE_COUNT * 3, msgsB.getMessageCount());
148         assertEquals(MESSAGE_COUNT, msgsC.getMessageCount());
149     }
150
151     /**
152      * BrokerA <-> BrokerB <-> BrokerC
153      */

154     public void testAllConnectedBrokerNetwork() throws Exception JavaDoc {
155         // Setup broker networks
156
bridgeBrokers("BrokerA", "BrokerB");
157         bridgeBrokers("BrokerB", "BrokerA");
158         bridgeBrokers("BrokerB", "BrokerC");
159         bridgeBrokers("BrokerC", "BrokerB");
160         bridgeBrokers("BrokerA", "BrokerC");
161         bridgeBrokers("BrokerC", "BrokerA");
162
163         startAllBrokers();
164
165         // Setup destination
166
Destination JavaDoc dest = createDestination("TEST.FOO", true);
167
168         // Setup consumers
169
MessageConsumer JavaDoc clientA = createConsumer("BrokerA", dest);
170         MessageConsumer JavaDoc clientB = createConsumer("BrokerB", dest);
171         MessageConsumer JavaDoc clientC = createConsumer("BrokerC", dest);
172         //let consumers propogate around the network
173
Thread.sleep(2000);
174
175         // Send messages
176
sendMessages("BrokerA", dest, MESSAGE_COUNT);
177         sendMessages("BrokerB", dest, MESSAGE_COUNT);
178         sendMessages("BrokerC", dest, MESSAGE_COUNT);
179
180         // Get message count
181
MessageIdList msgsA = getConsumerMessages("BrokerA", clientA);
182         MessageIdList msgsB = getConsumerMessages("BrokerB", clientB);
183         MessageIdList msgsC = getConsumerMessages("BrokerC", clientC);
184
185         msgsA.waitForMessagesToArrive(MESSAGE_COUNT * 3);
186         msgsB.waitForMessagesToArrive(MESSAGE_COUNT * 3);
187         msgsC.waitForMessagesToArrive(MESSAGE_COUNT * 3);
188
189         assertEquals(MESSAGE_COUNT * 3, msgsA.getMessageCount());
190         assertEquals(MESSAGE_COUNT * 3, msgsB.getMessageCount());
191         assertEquals(MESSAGE_COUNT * 3, msgsC.getMessageCount());
192     }
193
194     /**
195      * BrokerA <-> BrokerB <-> BrokerC
196      */

197     public void testAllConnectedUsingMulticast() throws Exception JavaDoc {
198         // Setup broker networks
199
bridgeAllBrokers();
200
201         startAllBrokers();
202
203         // Setup destination
204
Destination JavaDoc dest = createDestination("TEST.FOO", true);
205
206         // Setup consumers
207
MessageConsumer JavaDoc clientA = createConsumer("BrokerA", dest);
208         MessageConsumer JavaDoc clientB = createConsumer("BrokerB", dest);
209         MessageConsumer JavaDoc clientC = createConsumer("BrokerC", dest);
210         
211         //let consumers propogate around the network
212
Thread.sleep(2000);
213
214         // Send messages
215
sendMessages("BrokerA", dest, MESSAGE_COUNT);
216         sendMessages("BrokerB", dest, MESSAGE_COUNT);
217         sendMessages("BrokerC", dest, MESSAGE_COUNT);
218
219         // Get message count
220
MessageIdList msgsA = getConsumerMessages("BrokerA", clientA);
221         MessageIdList msgsB = getConsumerMessages("BrokerB", clientB);
222         MessageIdList msgsC = getConsumerMessages("BrokerC", clientC);
223
224         msgsA.waitForMessagesToArrive(MESSAGE_COUNT * 3);
225         msgsB.waitForMessagesToArrive(MESSAGE_COUNT * 3);
226         msgsC.waitForMessagesToArrive(MESSAGE_COUNT * 3);
227
228         assertEquals(MESSAGE_COUNT * 3, msgsA.getMessageCount());
229         assertEquals(MESSAGE_COUNT * 3, msgsB.getMessageCount());
230         assertEquals(MESSAGE_COUNT * 3, msgsC.getMessageCount());
231     }
232
233     public void setUp() throws Exception JavaDoc {
234         super.setAutoFail(true);
235         super.setUp();
236         createBroker(new URI JavaDoc("broker:(tcp://localhost:61616)/BrokerA?persistent=false&useJmx=false"));
237         createBroker(new URI JavaDoc("broker:(tcp://localhost:61617)/BrokerB?persistent=false&useJmx=false"));
238         createBroker(new URI JavaDoc("broker:(tcp://localhost:61618)/BrokerC?persistent=false&useJmx=false"));
239     }
240 }
241
Popular Tags