1 18 package org.apache.activemq.usecases; 19 20 import junit.framework.TestCase; 21 import org.apache.activemq.ActiveMQConnectionFactory; 22 import org.apache.activemq.broker.BrokerService; 23 import org.apache.activemq.broker.BrokerFactory; 24 import org.apache.activemq.broker.TransportConnector; 25 26 import javax.jms.JMSException ; 27 import java.net.URI ; 28 29 33 public class StartAndStopBrokerTest extends TestCase { 34 public void testStartupShutdown() throws Exception { 35 System.setProperty("activemq.persistenceAdapter", 38 "org.apache.activemq.store.vm.VMPersistenceAdapter"); 39 40 BrokerService broker = createBroker(); 42 43 ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:9100"); 45 factory.createConnection(); 46 47 broker.stop(); 49 50 broker = createBroker(); 52 53 factory = new ActiveMQConnectionFactory("tcp://localhost:9100"); 55 factory.createConnection(); 56 57 broker.stop(); 59 60 } 61 62 protected BrokerService createBroker() throws JMSException { 63 BrokerService broker = null; 64 65 try { 66 broker = BrokerFactory.createBroker(new URI ("broker://()/localhost")); 67 broker.setBrokerName("DefaultBroker"); 68 broker.addConnector("tcp://localhost:9100"); 69 broker.setUseShutdownHook(false); 70 71 broker.start(); 72 } catch (Exception e) { 73 e.printStackTrace(); 74 } 75 76 return broker; 77 } 78 79 } 80 | Popular Tags |