1 18 package org.apache.activemq; 19 20 import javax.jms.Connection ; 21 import javax.jms.InvalidClientIDException ; 22 import javax.jms.JMSException ; 23 import javax.jms.Session ; 24 25 29 public class ReconnectWithSameClientIDTest extends EmbeddedBrokerTestSupport { 30 31 protected Connection connection; 32 protected boolean transacted; 33 protected int authMode = Session.AUTO_ACKNOWLEDGE; 34 35 public void testReconnectMultipleTimesWithSameClientID() throws Exception { 36 connection = connectionFactory.createConnection(); 37 useConnection(connection); 38 39 for (int i = 1; i < 11; i++) { 41 Connection connection2 = connectionFactory.createConnection(); 42 try { 43 useConnection(connection2); 44 fail("Should have thrown InvalidClientIDException on attempt" + i); 45 } 46 catch (InvalidClientIDException e) { 47 connection2.close(); 48 log.info("Caught expected: " + e); 49 } 50 } 51 52 connection.close(); 54 connection = connectionFactory.createConnection(); 55 useConnection(connection); 56 } 57 58 protected void setUp() throws Exception { 59 bindAddress = "tcp://localhost:61616"; 60 super.setUp(); 61 } 62 63 protected void tearDown() throws Exception { 64 if (connection != null) { 65 connection.close(); 66 connection = null; 67 } 68 super.tearDown(); 69 } 70 71 protected void useConnection(Connection connection) throws JMSException { 72 connection.setClientID("foo"); 73 connection.start(); 74 78 } 79 } 80 | Popular Tags |