KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > network > SSHTunnelNetworkReconnectTest


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.network;
19
20 import java.io.IOException JavaDoc;
21 import java.io.InputStream JavaDoc;
22 import java.net.URI JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.Iterator JavaDoc;
25
26 import org.apache.activemq.broker.BrokerFactory;
27 import org.apache.activemq.broker.BrokerService;
28
29
30 /**
31  * Test network reconnects over SSH tunnels. This case can be especially tricky since the SSH tunnels
32  * fool the TCP transport into thinking that they are initially connected.
33  *
34  * @author chirino
35  */

36 public class SSHTunnelNetworkReconnectTest extends NetworkReconnectTest {
37
38     ArrayList JavaDoc processes = new ArrayList JavaDoc();
39     
40     
41     protected BrokerService createFirstBroker() throws Exception JavaDoc {
42         return BrokerFactory.createBroker(new URI JavaDoc("xbean:org/apache/activemq/network/ssh-reconnect-broker1.xml"));
43     }
44     
45     protected BrokerService createSecondBroker() throws Exception JavaDoc {
46         return BrokerFactory.createBroker(new URI JavaDoc("xbean:org/apache/activemq/network/ssh-reconnect-broker2.xml"));
47     }
48     
49     protected void setUp() throws Exception JavaDoc {
50         startProcess("ssh -Nn -L60006:localhost:61616 localhost");
51         startProcess("ssh -Nn -L60007:localhost:61617 localhost");
52         super.setUp();
53     }
54     
55     protected void tearDown() throws Exception JavaDoc {
56         super.tearDown();
57         for (Iterator JavaDoc iter = processes.iterator(); iter.hasNext();) {
58             Process JavaDoc p = (Process JavaDoc) iter.next();
59             p.destroy();
60         }
61     }
62
63     private void startProcess(String JavaDoc command) throws IOException JavaDoc {
64         final Process JavaDoc process = Runtime.getRuntime().exec(command);
65         processes.add(process);
66         new Thread JavaDoc("stdout: "+command){
67             public void run() {
68                 try {
69                     InputStream JavaDoc is = process.getInputStream();
70                     int c;
71                     while((c=is.read())>=0) {
72                         System.out.write(c);
73                     }
74                 } catch (IOException JavaDoc e) {
75                 }
76             }
77         }.start();
78         new Thread JavaDoc("stderr: "+command){
79             public void run() {
80                 try {
81                     InputStream JavaDoc is = process.getErrorStream();
82                     int c;
83                     while((c=is.read())>=0) {
84                         System.err.write(c);
85                     }
86                 } catch (IOException JavaDoc e) {
87                 }
88             }
89         }.start();
90     }
91 }
92
Popular Tags