1 3 package org.jgroups.tests; 4 5 import junit.framework.Test; 6 import junit.framework.TestCase; 7 import junit.framework.TestSuite; 8 import org.jgroups.ChannelException; 9 import org.jgroups.JChannel; 10 11 import java.io.IOException ; 12 import java.io.InterruptedIOException ; 13 import java.net.ServerSocket ; 14 import java.net.Socket ; 15 16 17 25 public class InexistentRouterTest extends TestCase { 26 private int SERVER_SOCKET_TIMEOUT=20000; 27 28 private int port; 29 private ServerSocket ss; 30 private JChannel channel; 31 private String action; 32 33 public InexistentRouterTest(String name) { 34 super(name); 35 } 36 37 public void setUp() throws Exception { 38 39 super.setUp(); 40 41 ss=new ServerSocket (0); 43 port=ss.getLocalPort(); 44 ss.close(); 45 46 debug("ROUTER PORT: " + port); 47 String props="TUNNEL(router_host=127.0.0.1;router_port=" + port + ')'; 48 channel=new JChannel(props); 49 50 } 51 52 public void tearDown() throws Exception { 53 54 super.tearDown(); 55 ss.close(); 56 channel.close(); 57 } 58 59 60 70 public void testReconnect() throws Exception { 71 72 try { 73 channel.connect("GROUP"); 74 } 75 catch(ChannelException e) { 76 } 77 78 startServerSocket(); 79 80 } 81 82 83 private void startServerSocket() { 84 85 try { 86 debug("Starting server on " + port); 87 ss=new ServerSocket (port); 88 ss.setSoTimeout(SERVER_SOCKET_TIMEOUT); 89 Socket s=ss.accept(); 90 fail("The Server Socket received a connection attempt."); 91 } 92 catch(InterruptedIOException e) { 93 } 95 catch(IOException e) { 96 debug("Socket exception:", e); 97 fail("Not suposed to get exception here."); 98 } 99 } 100 101 102 private void debug(String msg) { 103 System.out.println(msg); 104 } 105 106 private void debug(String msg, Throwable t) { 107 System.out.println(msg + ", exception=" + t); 108 } 109 110 111 public static Test suite() { 112 TestSuite s=new TestSuite(InexistentRouterTest.class); 113 return s; 114 } 115 116 public static void main(String [] args) { 117 junit.textui.TestRunner.run(suite()); 118 } 119 120 121 } 122 | Popular Tags |