1 3 package org.jgroups.tests; 4 5 6 import junit.framework.Test; 7 import junit.framework.TestCase; 8 import junit.framework.TestSuite; 9 import org.jgroups.JChannel; 10 import org.jgroups.Message; 11 import org.jgroups.TimeoutException; 12 import org.jgroups.tests.stack.Utilities; 13 import org.jgroups.util.Promise; 14 15 23 public class TUNNELDeadLockTest extends TestCase { 24 private JChannel channel; 25 private Promise promise; 26 private int receivedCnt; 27 28 private int msgCount=20000; 30 private int payloadSize=32; 32 private int mainTimeout=60000; 35 36 int routerPort=-1; 37 38 39 public TUNNELDeadLockTest(String name) { 40 super(name); 41 } 42 43 public void setUp() throws Exception { 44 super.setUp(); 45 promise=new Promise(); 46 routerPort=Utilities.startGossipRouter("127.0.0.1"); 47 } 48 49 public void tearDown() throws Exception { 50 51 super.tearDown(); 52 53 57 61 channel=null; 62 promise.reset(); 63 promise=null; 64 Utilities.stopGossipRouter(); 65 } 66 67 68 private String getTUNNELProps(int routerPort) { 69 String props; 70 71 props="TUNNEL(router_host=127.0.0.1;router_port=" + routerPort + "):" + 72 "PING(timeout=3000;gossip_refresh=10000;num_initial_members=3;" + 73 "gossip_host=127.0.0.1;gossip_port=" + routerPort + "):" + 74 "FD_SOCK:" + 75 "pbcast.NAKACK(gc_lag=100;retransmit_timeout=600,1200,2400,4800):" + 76 "pbcast.STABLE(stability_delay=1000;desired_avg_gossip=20000;max_bytes=100000):" + 77 "pbcast.GMS(print_local_addr=true;join_timeout=5000;join_retry_timeout=2000;shun=true):" + 78 "SFC(max_credits=100000)"; 79 return props; 80 } 81 82 94 public void testStress() throws Exception { 95 String props=getTUNNELProps(routerPort); 96 channel=new JChannel(props); 97 channel.connect("agroup"); 98 99 new Thread (new Runnable () { 101 public void run() { 102 try { 103 while(true) { 104 if(channel == null) 105 return; 106 Object o=channel.receive(10000); 107 if(o instanceof Message) { 108 receivedCnt++; 109 if(receivedCnt % 2000 == 0) 110 System.out.println("-- received " + receivedCnt); 111 if(receivedCnt == msgCount) { 112 promise.setResult(new Object ()); 114 return; 115 } 116 } 117 } 118 } 119 catch(TimeoutException e) { 120 System.err.println("Timeout receiving from the channel. " + receivedCnt + 121 " msgs received so far."); 122 } 123 catch(Exception e) { 124 System.err.println("Error receiving data"); 125 e.printStackTrace(); 126 } 127 } 128 }).start(); 129 130 new Thread (new Runnable () { 132 public void run() { 133 try { 134 for(int i=0; i < msgCount; i++) { 135 channel.send(null, null, new byte[payloadSize]); 136 if(i % 2000 == 0) 137 System.out.println("-- sent " + i); 138 } 139 } 140 catch(Exception e) { 141 System.err.println("Error sending data over ..."); 142 e.printStackTrace(); 143 } 144 } 145 }).start(); 146 147 148 151 Object result=promise.getResult(mainTimeout); 152 if(result == null) { 153 String msg= 154 "The channel has failed to send/receive " + msgCount + " messages " + 155 "possibly because of the channel deadlock or too short " + 156 "timeout (currently " + mainTimeout + " ms). " + receivedCnt + 157 " messages received so far."; 158 fail(msg); 159 } 160 161 channel.close(); 164 } 165 166 167 public static Test suite() { 168 return new TestSuite(TUNNELDeadLockTest.class); 169 } 170 171 public static void main(String [] args) { 172 junit.textui.TestRunner.run(suite()); 173 System.exit(0); 174 } 175 176 177 } 178 | Popular Tags |