@After public void tearDown() throws Exception { if (s2 != null) { s2.stop(); } if (s1 != null) { s1.stop(); } }
@Test public void testNoSuspendedCallbackOnNoReconnect() throws Exception { String uriString = "failover://(" + newURI(1) + "," + newURI(2) + ")?randomize=false&maxReconnectAttempts=0"; ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(uriString); final AtomicInteger calls = new AtomicInteger(0); connectionFactory.setTransportListener( new TransportListener() { @Override public void onCommand(Object command) {} @Override public void onException(IOException error) { LOG.info("on exception: " + error); calls.set(0x01 | calls.intValue()); } @Override public void transportInterupted() { LOG.info("on transportInterupted"); calls.set(0x02 | calls.intValue()); } @Override public void transportResumed() { LOG.info("on transportResumed"); calls.set(0x04 | calls.intValue()); } }); Connection connection = connectionFactory.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue destination = session.createQueue("foo"); MessageProducer producer = session.createProducer(destination); final Message message = session.createTextMessage("TEST"); producer.send(message); // clear listener state calls.set(0); LOG.info("Stopping the Broker1..."); server1.stop(); LOG.info("Attempting to send... failover should throw on disconnect"); try { producer.send(destination, message); fail("Expect IOException to bubble up on send"); } catch (javax.jms.IllegalStateException producerClosed) { } assertEquals("Only an exception is reported to the listener", 0x1, calls.get()); }
@Test public void testInitialReconnectDelay() throws Exception { String uriString = "failover://(" + newURI(1) + "," + newURI(2) + ")?randomize=false&initialReconnectDelay=15000"; ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(uriString); Connection connection = connectionFactory.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue destination = session.createQueue("foo"); MessageProducer producer = session.createProducer(destination); long start = (new Date()).getTime(); producer.send(session.createTextMessage("TEST")); long end = (new Date()).getTime(); // Verify we can send quickly assertTrue((end - start) < 2000); // Halt the broker1... LOG.info("Stopping the Broker1..."); start = (new Date()).getTime(); server1.stop(); LOG.info("Attempting to send... failover should kick in..."); producer.send(session.createTextMessage("TEST")); end = (new Date()).getTime(); // Inital reconnection should kick in and be darned close to what we expected LOG.info("Failover took " + (end - start) + " ms."); assertTrue( "Failover took " + (end - start) + " ms and should be > 14000.", (end - start) > 14000); connection.close(); }
@After public void tearDown() throws Exception { server1.stop(); server2.stop(); }
public void stopServer(EmbeddedJMS jmsServer) throws Exception { jmsServer.stop(); LOGGER.info("Stopped embedded JMS server"); }