1 18 package org.apache.activemq.network; 19 20 import java.io.IOException ; 21 import java.io.InputStream ; 22 import java.net.URI ; 23 import java.util.ArrayList ; 24 import java.util.Iterator ; 25 26 import org.apache.activemq.broker.BrokerFactory; 27 import org.apache.activemq.broker.BrokerService; 28 29 30 36 public class SSHTunnelNetworkReconnectTest extends NetworkReconnectTest { 37 38 ArrayList processes = new ArrayList (); 39 40 41 protected BrokerService createFirstBroker() throws Exception { 42 return BrokerFactory.createBroker(new URI ("xbean:org/apache/activemq/network/ssh-reconnect-broker1.xml")); 43 } 44 45 protected BrokerService createSecondBroker() throws Exception { 46 return BrokerFactory.createBroker(new URI ("xbean:org/apache/activemq/network/ssh-reconnect-broker2.xml")); 47 } 48 49 protected void setUp() throws Exception { 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 { 56 super.tearDown(); 57 for (Iterator iter = processes.iterator(); iter.hasNext();) { 58 Process p = (Process ) iter.next(); 59 p.destroy(); 60 } 61 } 62 63 private void startProcess(String command) throws IOException { 64 final Process process = Runtime.getRuntime().exec(command); 65 processes.add(process); 66 new Thread ("stdout: "+command){ 67 public void run() { 68 try { 69 InputStream is = process.getInputStream(); 70 int c; 71 while((c=is.read())>=0) { 72 System.out.write(c); 73 } 74 } catch (IOException e) { 75 } 76 } 77 }.start(); 78 new Thread ("stderr: "+command){ 79 public void run() { 80 try { 81 InputStream is = process.getErrorStream(); 82 int c; 83 while((c=is.read())>=0) { 84 System.err.write(c); 85 } 86 } catch (IOException e) { 87 } 88 } 89 }.start(); 90 } 91 } 92 | Popular Tags |