1 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 ; 24 import javax.jms.MessageConsumer ; 25 import java.net.URI ; 26 27 30 public class ThreeBrokerQueueNetworkTest extends JmsMultipleBrokersTestSupport { 31 protected static final int MESSAGE_COUNT = 100; 32 33 36 public void test_AB_BC_BrokerNetwork() throws Exception { 37 bridgeBrokers("BrokerA", "BrokerB"); 39 bridgeBrokers("BrokerB", "BrokerC"); 40 41 startAllBrokers(); 42 43 Destination dest = createDestination("TEST.FOO", false); 45 46 MessageConsumer clientC = createConsumer("BrokerC", dest); 48 49 sendMessages("BrokerA", dest, MESSAGE_COUNT); 51 52 Thread.sleep(1000); 54 55 MessageIdList msgsC = getConsumerMessages("BrokerC", clientC); 57 assertEquals(0, msgsC.getMessageCount()); 58 } 59 60 63 public void test_BA_BC_BrokerNetwork() throws Exception { 64 bridgeBrokers("BrokerB", "BrokerA"); 66 bridgeBrokers("BrokerB", "BrokerC"); 67 68 startAllBrokers(); 69 70 Destination dest = createDestination("TEST.FOO", false); 72 73 MessageConsumer clientA = createConsumer("BrokerA", dest); 75 MessageConsumer clientC = createConsumer("BrokerC", dest); 76 Thread.sleep(2000); sendMessages("BrokerB", dest, MESSAGE_COUNT); 79 80 Thread.sleep(1000); 82 83 MessageIdList msgsA = getConsumerMessages("BrokerA", clientA); 85 MessageIdList msgsC = getConsumerMessages("BrokerC", clientC); 86 87 assertEquals(MESSAGE_COUNT, msgsA.getMessageCount() + msgsC.getMessageCount()); 89 } 90 91 94 public void test_AB_CB_BrokerNetwork() throws Exception { 95 bridgeBrokers("BrokerA", "BrokerB"); 97 bridgeBrokers("BrokerC", "BrokerB"); 98 99 startAllBrokers(); 100 101 Destination dest = createDestination("TEST.FOO", false); 103 104 MessageConsumer clientB = createConsumer("BrokerB", dest); 106 107 sendMessages("BrokerA", dest, MESSAGE_COUNT); 109 sendMessages("BrokerC", dest, MESSAGE_COUNT); 110 111 MessageIdList msgsB = getConsumerMessages("BrokerB", clientB); 113 114 msgsB.waitForMessagesToArrive(MESSAGE_COUNT * 2); 115 116 assertEquals(MESSAGE_COUNT * 2, msgsB.getMessageCount()); 117 } 118 119 122 public void testAllConnectedBrokerNetwork() throws Exception { 123 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 Destination dest = createDestination("TEST.FOO", false); 135 136 MessageConsumer clientA = createConsumer("BrokerA", dest); 138 MessageConsumer clientB = createConsumer("BrokerB", dest); 139 MessageConsumer clientC = createConsumer("BrokerC", dest); 140 141 sendMessages("BrokerA", dest, MESSAGE_COUNT); 143 sendMessages("BrokerB", dest, MESSAGE_COUNT); 144 sendMessages("BrokerC", dest, MESSAGE_COUNT); 145 146 Thread.sleep(1000); 148 149 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 160 public void testAllConnectedUsingMulticast() throws Exception { 161 bridgeAllBrokers(); 163 164 startAllBrokers(); 165 166 Destination dest = createDestination("TEST.FOO", false); 168 169 MessageConsumer clientA = createConsumer("BrokerA", dest); 171 MessageConsumer clientB = createConsumer("BrokerB", dest); 172 MessageConsumer clientC = createConsumer("BrokerC", dest); 173 174 sendMessages("BrokerA", dest, MESSAGE_COUNT); 176 sendMessages("BrokerB", dest, MESSAGE_COUNT); 177 sendMessages("BrokerC", dest, MESSAGE_COUNT); 178 179 Thread.sleep(1000); 181 182 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 { 191 super.setAutoFail(true); 192 super.setUp(); 193 createBroker(new URI ("broker:(tcp://localhost:61616)/BrokerA?persistent=false&useJmx=false")); 194 createBroker(new URI ("broker:(tcp://localhost:61617)/BrokerB?persistent=false&useJmx=false")); 195 createBroker(new URI ("broker:(tcp://localhost:61618)/BrokerC?persistent=false&useJmx=false")); 196 } 197 } 198 | Popular Tags |