KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > transport > failover > BadConnectionTest


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.transport.failover;
19
20 import java.io.IOException JavaDoc;
21 import java.net.URI JavaDoc;
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 /**
33  *
34  * @version $Revision: 1.1 $
35  */

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 JavaDoc {
43         try {
44             transport.asyncRequest(new ActiveMQMessage(), null);
45             fail("This should never succeed");
46         }
47         catch (IOException JavaDoc e) {
48             log.info("Caught expected exception: " + e, e);
49         }
50     }
51     protected Transport createTransport() throws Exception JavaDoc {
52         return TransportFactory.connect(new URI JavaDoc("failover://(tcp://doesNotExist:1234)?useExponentialBackOff=false&maxReconnectAttempts=3&initialReconnectDelay=100"));
53     }
54
55     protected void setUp() throws Exception JavaDoc {
56         transport = createTransport();
57         transport.setTransportListener(new TransportListener() {
58
59             public void onCommand(Object JavaDoc command) {
60             }
61
62             public void onException(IOException JavaDoc 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 JavaDoc {
75         if (transport != null) {
76             transport.stop();
77         }
78     }
79         
80 }
81
Popular Tags