KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > ReconnectWithSameClientIDTest


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq;
19
20 import javax.jms.Connection JavaDoc;
21 import javax.jms.InvalidClientIDException JavaDoc;
22 import javax.jms.JMSException JavaDoc;
23 import javax.jms.Session JavaDoc;
24
25 /**
26  *
27  * @version $Revision: 426384 $
28  */

29 public class ReconnectWithSameClientIDTest extends EmbeddedBrokerTestSupport {
30
31     protected Connection JavaDoc connection;
32     protected boolean transacted;
33     protected int authMode = Session.AUTO_ACKNOWLEDGE;
34
35     public void testReconnectMultipleTimesWithSameClientID() throws Exception JavaDoc {
36         connection = connectionFactory.createConnection();
37         useConnection(connection);
38
39         // now lets create another which should fail
40
for (int i = 1; i < 11; i++) {
41         Connection JavaDoc connection2 = connectionFactory.createConnection();
42         try {
43             useConnection(connection2);
44             fail("Should have thrown InvalidClientIDException on attempt" + i);
45         }
46         catch (InvalidClientIDException JavaDoc e) {
47             connection2.close();
48             log.info("Caught expected: " + e);
49         }
50         }
51
52         // now lets try closing the original connection and creating a new connection with the same ID
53
connection.close();
54         connection = connectionFactory.createConnection();
55         useConnection(connection);
56     }
57
58     protected void setUp() throws Exception JavaDoc {
59         bindAddress = "tcp://localhost:61616";
60         super.setUp();
61     }
62
63     protected void tearDown() throws Exception JavaDoc {
64         if (connection != null) {
65             connection.close();
66             connection = null;
67         }
68         super.tearDown();
69     }
70
71     protected void useConnection(Connection JavaDoc connection) throws JMSException JavaDoc {
72         connection.setClientID("foo");
73         connection.start();
74         /**
75          * Session session = connection.createSession(transacted, authMode);
76          * return session;
77          */

78     }
79 }
80
Popular Tags