KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.net.URI JavaDoc;
21 import java.util.Iterator JavaDoc;
22
23 import javax.jms.Connection JavaDoc;
24 import javax.jms.Session JavaDoc;
25 import javax.jms.TemporaryQueue JavaDoc;
26
27 import org.apache.activemq.JmsMultipleBrokersTestSupport;
28 import org.apache.activemq.network.NetworkConnector;
29 /**
30  * @version $Revision: 1.1.1.1 $
31  */

32 public class ThreeBrokerTempQueueNetworkTest extends JmsMultipleBrokersTestSupport{
33     protected static final int MESSAGE_COUNT=100;
34     boolean enableTempDestinationBridging = true;
35
36     /**
37      * BrokerA -> BrokerB -> BrokerC
38      */

39     public void testTempQueueCleanup() throws Exception JavaDoc{
40         // Setup broker networks
41
bridgeBrokers("BrokerA","BrokerB",false,2);
42         bridgeBrokers("BrokerB","BrokerC",false,2);
43         startAllBrokers();
44         BrokerItem brokerItem=(BrokerItem) brokers.get("BrokerC");
45         Connection JavaDoc conn=brokerItem.createConnection();
46         conn.start();
47         Session JavaDoc sess=conn.createSession(false,Session.AUTO_ACKNOWLEDGE);
48         TemporaryQueue JavaDoc tempQ=sess.createTemporaryQueue();
49         Thread.sleep(5000);
50         for(Iterator JavaDoc i=brokers.values().iterator();i.hasNext();){
51             BrokerItem bi=(BrokerItem) i.next();
52             assertEquals("No queues on broker "+bi.broker.getBrokerName(),1,bi.broker.getAdminView()
53                             .getTemporaryQueues().length);
54         }
55         tempQ.delete();
56         Thread.sleep(2000);
57         for(Iterator JavaDoc i=brokers.values().iterator();i.hasNext();){
58             BrokerItem bi=(BrokerItem) i.next();
59             assertEquals("Temp queue left behind on broker "+bi.broker.getBrokerName(),0,bi.broker.getAdminView()
60                             .getTemporaryQueues().length);
61         }
62     }
63
64     // this actually uses 4 brokers ...
65
public void testTempQueueRecovery() throws Exception JavaDoc{
66         // Setup broker networks
67
bridgeBrokers("BrokerA","BrokerB",false,3);
68         bridgeBrokers("BrokerB","BrokerC",false,3);
69         startAllBrokers();
70         BrokerItem brokerItem=(BrokerItem) brokers.get("BrokerC");
71         Connection JavaDoc conn=brokerItem.createConnection();
72         conn.start();
73         Session JavaDoc sess=conn.createSession(false,Session.AUTO_ACKNOWLEDGE);
74         TemporaryQueue JavaDoc tempQ=sess.createTemporaryQueue();
75         Thread.sleep(5000);
76         for(Iterator JavaDoc i=brokers.values().iterator();i.hasNext();){
77             BrokerItem bi=(BrokerItem) i.next();
78             assertEquals("No queues on broker "+bi.broker.getBrokerName(),1,bi.broker.getAdminView()
79                             .getTemporaryQueues().length);
80         }
81         createBroker(new URI JavaDoc("broker:(tcp://localhost:61619)/BrokerD?persistent=false&useJmx=true"));
82         bridgeBrokers("BrokerD","BrokerA",false,3);
83         BrokerItem newBroker=(BrokerItem) brokers.get("BrokerD");
84         newBroker.broker.start();
85         Thread.sleep(1000);
86         assertEquals("No queues on broker D",1,newBroker.broker.getAdminView().getTemporaryQueues().length);
87         tempQ.delete();
88         Thread.sleep(2000);
89         for(Iterator JavaDoc i=brokers.values().iterator();i.hasNext();){
90             BrokerItem bi=(BrokerItem) i.next();
91             assertEquals("Temp queue left behind on broker "+bi.broker.getBrokerName(),0,bi.broker.getAdminView()
92                             .getTemporaryQueues().length);
93         }
94     }
95     
96     public void testTempDisable() throws Exception JavaDoc{
97         enableTempDestinationBridging=false;
98         try {
99             testTempQueueCleanup();
100         } catch (Throwable JavaDoc e) {
101             // Expecting an error
102
return;
103         }
104         fail("Test should have failed since temp queues are disabled.");
105     }
106
107     public void setUp() throws Exception JavaDoc{
108         super.setAutoFail(true);
109         super.setUp();
110         createBroker(new URI JavaDoc("broker:(tcp://localhost:61616)/BrokerA?persistent=false&useJmx=true"));
111         createBroker(new URI JavaDoc("broker:(tcp://localhost:61617)/BrokerB?persistent=false&useJmx=true"));
112         createBroker(new URI JavaDoc("broker:(tcp://localhost:61618)/BrokerC?persistent=false&useJmx=true"));
113     }
114
115     protected NetworkConnector bridgeBrokers(String JavaDoc localBrokerName, String JavaDoc remoteBrokerName, boolean dynamicOnly, int networkTTL) throws Exception JavaDoc {
116         NetworkConnector connector = super.bridgeBrokers(localBrokerName, remoteBrokerName, dynamicOnly, networkTTL);
117         connector.setBridgeTempDestinations(enableTempDestinationBridging);
118         return connector;
119     }
120     
121 }
122
Popular Tags