1 3 package org.jgroups.tests.stack; 4 5 import junit.framework.Test; 6 import junit.framework.TestCase; 7 import junit.framework.TestSuite; 8 import org.jgroups.stack.GossipRouter; 9 import org.jgroups.stack.IpAddress; 10 import org.jgroups.util.Util; 11 12 import java.io.DataInputStream ; 13 import java.io.DataOutputStream ; 14 import java.io.EOFException ; 15 import java.net.Socket ; 16 import java.net.SocketException ; 17 18 19 29 public class LazyRoutingClientTest extends TestCase { 30 31 private int routerPort=-1; 32 33 private long routingClientReplyTimeout=30000; 34 35 public LazyRoutingClientTest(String name) { 36 super(name); 37 } 38 39 public void setUp() throws Exception { 40 super.setUp(); 41 routerPort= 42 Utilities.startGossipRouter(GossipRouter.EXPIRY_TIME, 43 GossipRouter.GOSSIP_REQUEST_TIMEOUT, 44 routingClientReplyTimeout); 45 } 46 47 public void tearDown() throws Exception { 48 super.tearDown(); 49 Utilities.stopGossipRouter(); 50 } 51 52 53 58 public void testLazyClient() throws Exception { 59 60 int len; 61 byte[] buffer; 62 63 Socket s=new Socket ("localhost", routerPort); 64 DataInputStream dis=new DataInputStream (s.getInputStream()); 65 DataOutputStream dos=new DataOutputStream (s.getOutputStream()); 66 67 len=dis.readInt(); 69 buffer=new byte[len]; 70 dis.readFully(buffer, 0, len); 71 IpAddress localAddr=(IpAddress)Util.objectFromByteBuffer(buffer); 72 assertEquals(localAddr.getIpAddress(), s.getLocalAddress()); 73 assertEquals(localAddr.getPort(), s.getLocalPort()); 74 75 Thread.sleep(routingClientReplyTimeout + 500); 77 78 81 Exception expected13=null; 82 Exception expected14=null; 83 84 try { 85 dos.writeInt(GossipRouter.GET); 86 dos.writeUTF("testgroup"); 87 } 88 catch(Exception e) { 89 expected14=e; 91 } 92 93 try { 94 dis.readInt(); 95 } 96 catch(Exception e) { 97 expected13=e; 99 } 100 101 assertTrue(expected14 instanceof SocketException || 102 expected13 instanceof EOFException ); 103 104 dis.close(); 105 dos.close(); 106 s.close(); 107 } 108 109 110 public static Test suite() { 111 TestSuite s=new TestSuite(LazyRoutingClientTest.class); 112 return s; 113 } 114 115 public static void main(String [] args) { 116 junit.textui.TestRunner.run(suite()); 117 System.exit(0); 118 } 119 120 } 121 | Popular Tags |