1 18 package org.apache.activemq; 19 20 import java.util.Queue ; 21 import java.util.concurrent.ConcurrentLinkedQueue ; 22 23 import org.apache.activemq.ActiveMQConnectionFactory; 24 import org.apache.activemq.broker.BrokerService; 25 26 27 30 public class JmsQueueSendReceiveTwoConnectionsStartBeforeBrokerTest extends JmsQueueSendReceiveTwoConnectionsTest { 31 32 private Queue errors = new ConcurrentLinkedQueue (); 33 private int delayBeforeStartingBroker = 1000; 34 private BrokerService broker; 35 36 public void startBroker() { 37 log.info("Lets wait: " + delayBeforeStartingBroker + " millis before creating the broker"); 39 try { 40 Thread.sleep(delayBeforeStartingBroker); 41 } 42 catch (InterruptedException e) { 43 e.printStackTrace(); 44 } 45 46 log.info("Now starting the broker"); 47 try { 48 broker = new BrokerService(); 49 broker.setPersistent(false); 50 broker.addConnector("tcp://localhost:61616"); 51 broker.start(); 52 } 53 catch (Exception e) { 54 log.info("Caught: " + e); 55 errors.add(e); 56 } 57 } 58 protected ActiveMQConnectionFactory createConnectionFactory() throws Exception { 59 return new ActiveMQConnectionFactory("failover:(tcp://localhost:61616)?maxReconnectAttempts=10&useExponentialBackOff=false&initialReconnectDelay=200"); 60 } 61 62 protected void setUp() throws Exception { 63 Thread thread = new Thread () { 65 public void run() { 66 startBroker(); 67 } 68 }; 69 thread.start(); 70 71 super.setUp(); 72 } 73 74 protected void tearDown() throws Exception { 75 super.tearDown(); 76 77 if (broker != null) { 78 broker.stop(); 79 } 80 if (!errors.isEmpty()) { 81 Exception e = (Exception ) errors.remove(); 82 throw e; 83 } 84 } 85 86 87 88 } 89 | Popular Tags |