1 18 package org.apache.activemq.transport.failover; 19 20 import java.io.IOException ; 21 import java.net.URI ; 22 23 import junit.framework.TestCase; 24 25 import org.apache.activemq.command.ActiveMQMessage; 26 import org.apache.activemq.transport.Transport; 27 import org.apache.activemq.transport.TransportFactory; 28 import org.apache.activemq.transport.TransportListener; 29 import org.apache.commons.logging.Log; 30 import org.apache.commons.logging.LogFactory; 31 32 36 public class BadConnectionTest extends TestCase { 37 38 protected static final Log log = LogFactory.getLog(BadConnectionTest.class); 39 40 protected Transport transport; 41 42 public void testConnectingToUnavailableServer() throws Exception { 43 try { 44 transport.asyncRequest(new ActiveMQMessage(), null); 45 fail("This should never succeed"); 46 } 47 catch (IOException e) { 48 log.info("Caught expected exception: " + e, e); 49 } 50 } 51 protected Transport createTransport() throws Exception { 52 return TransportFactory.connect(new URI ("failover://(tcp://doesNotExist:1234)?useExponentialBackOff=false&maxReconnectAttempts=3&initialReconnectDelay=100")); 53 } 54 55 protected void setUp() throws Exception { 56 transport = createTransport(); 57 transport.setTransportListener(new TransportListener() { 58 59 public void onCommand(Object command) { 60 } 61 62 public void onException(IOException error) { 63 } 64 65 public void transportInterupted() { 66 } 67 68 public void transportResumed() { 69 } 70 }); 71 transport.start(); 72 } 73 74 protected void tearDown() throws Exception { 75 if (transport != null) { 76 transport.stop(); 77 } 78 } 79 80 } 81 | Popular Tags |