1 package org.jgroups.tests; 2 3 import junit.framework.TestCase; 4 import org.jgroups.*; 5 6 11 public class UnicastLoopbackTest extends TestCase { 12 JChannel channel=null; 13 14 15 public UnicastLoopbackTest(String name) { 16 super(name); 17 } 18 19 protected void setUp() throws Exception { 20 super.setUp(); 21 channel=new JChannel(); 22 channel.connect("demo-group"); 23 } 24 25 protected void tearDown() throws Exception { 26 super.tearDown(); 27 if(channel != null) { 28 channel.close(); 29 channel=null; 30 } 31 } 32 33 34 public void testUnicastMsgs() throws ChannelClosedException, ChannelNotConnectedException, TimeoutException { 35 int NUM=1000; 36 Address local_addr=channel.getLocalAddress(); 37 for(int i=1; i <= NUM; i++) { 38 channel.send(new Message(local_addr, null, new Integer (i))); 39 if(i % 100 == 0) 46 System.out.println("-- sent " + i); 47 } 48 int received=0; 49 while(received < NUM) { 50 Object o=channel.receive(0); 51 if(o instanceof Message) { 52 Message m=(Message)o; 53 Integer num=(Integer )m.getObject(); 54 received++; 55 if(num.intValue() % 100 == 0) 56 System.out.println("-- received " + num); 57 } 58 } 59 assertEquals(NUM, received); 60 } 61 62 public static void main(String [] args) { 63 String [] testCaseName={UnicastLoopbackTest.class.getName()}; 64 junit.textui.TestRunner.main(testCaseName); 65 } 66 } 67 | Popular Tags |