1 18 package org.apache.activemq.usecases; 19 20 import java.net.URI ; 21 import java.util.Iterator ; 22 23 import javax.jms.Connection ; 24 import javax.jms.Session ; 25 import javax.jms.TemporaryQueue ; 26 27 import org.apache.activemq.JmsMultipleBrokersTestSupport; 28 import org.apache.activemq.network.NetworkConnector; 29 32 public class ThreeBrokerTempQueueNetworkTest extends JmsMultipleBrokersTestSupport{ 33 protected static final int MESSAGE_COUNT=100; 34 boolean enableTempDestinationBridging = true; 35 36 39 public void testTempQueueCleanup() throws Exception { 40 bridgeBrokers("BrokerA","BrokerB",false,2); 42 bridgeBrokers("BrokerB","BrokerC",false,2); 43 startAllBrokers(); 44 BrokerItem brokerItem=(BrokerItem) brokers.get("BrokerC"); 45 Connection conn=brokerItem.createConnection(); 46 conn.start(); 47 Session sess=conn.createSession(false,Session.AUTO_ACKNOWLEDGE); 48 TemporaryQueue tempQ=sess.createTemporaryQueue(); 49 Thread.sleep(5000); 50 for(Iterator 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 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 public void testTempQueueRecovery() throws Exception { 66 bridgeBrokers("BrokerA","BrokerB",false,3); 68 bridgeBrokers("BrokerB","BrokerC",false,3); 69 startAllBrokers(); 70 BrokerItem brokerItem=(BrokerItem) brokers.get("BrokerC"); 71 Connection conn=brokerItem.createConnection(); 72 conn.start(); 73 Session sess=conn.createSession(false,Session.AUTO_ACKNOWLEDGE); 74 TemporaryQueue tempQ=sess.createTemporaryQueue(); 75 Thread.sleep(5000); 76 for(Iterator 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 ("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 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 { 97 enableTempDestinationBridging=false; 98 try { 99 testTempQueueCleanup(); 100 } catch (Throwable e) { 101 return; 103 } 104 fail("Test should have failed since temp queues are disabled."); 105 } 106 107 public void setUp() throws Exception { 108 super.setAutoFail(true); 109 super.setUp(); 110 createBroker(new URI ("broker:(tcp://localhost:61616)/BrokerA?persistent=false&useJmx=true")); 111 createBroker(new URI ("broker:(tcp://localhost:61617)/BrokerB?persistent=false&useJmx=true")); 112 createBroker(new URI ("broker:(tcp://localhost:61618)/BrokerC?persistent=false&useJmx=true")); 113 } 114 115 protected NetworkConnector bridgeBrokers(String localBrokerName, String remoteBrokerName, boolean dynamicOnly, int networkTTL) throws Exception { 116 NetworkConnector connector = super.bridgeBrokers(localBrokerName, remoteBrokerName, dynamicOnly, networkTTL); 117 connector.setBridgeTempDestinations(enableTempDestinationBridging); 118 return connector; 119 } 120 121 } 122 | Popular Tags |