1 18 package org.apache.activemq.broker; 19 20 import org.apache.activemq.EmbeddedBrokerTestSupport; 21 22 import javax.jms.Connection ; 23 import javax.jms.Destination ; 24 import javax.jms.Message ; 25 import javax.jms.MessageConsumer ; 26 import javax.jms.MessageProducer ; 27 import javax.jms.Session ; 28 29 33 public class ReconnectWithJMXEnabledTest extends EmbeddedBrokerTestSupport { 34 35 protected Connection connection; 36 protected boolean transacted; 37 protected int authMode = Session.AUTO_ACKNOWLEDGE; 38 39 public void testTestUseConnectionCloseBrokerThenRestartInSameJVM() throws Exception { 40 connection = connectionFactory.createConnection(); 41 useConnection(connection); 42 connection.close(); 43 44 broker.stop(); 45 broker = createBroker(); 46 startBroker(); 47 48 connection = connectionFactory.createConnection(); 49 useConnection(connection); 50 } 51 52 protected void setUp() throws Exception { 53 bindAddress = "tcp://localhost:61616"; 54 super.setUp(); 55 } 56 57 protected void tearDown() throws Exception { 58 if (connection != null) { 59 connection.close(); 60 connection = null; 61 } 62 super.tearDown(); 63 } 64 65 protected BrokerService createBroker() throws Exception { 66 BrokerService answer = new BrokerService(); 67 answer.setUseJmx(true); 68 answer.setPersistent(isPersistent()); 69 answer.addConnector(bindAddress); 70 return answer; 71 } 72 73 protected void useConnection(Connection connection) throws Exception { 74 connection.setClientID("foo"); 75 connection.start(); 76 Session session = connection.createSession(transacted, authMode); 77 Destination destination = createDestination(); 78 MessageConsumer consumer = session.createConsumer(destination); 79 MessageProducer producer = session.createProducer(destination); 80 Message message = session.createTextMessage("Hello World"); 81 producer.send(message); 82 Thread.sleep(1000); 83 } 84 } 85 | Popular Tags |