1 package org.jgroups.blocks; 2 3 import java.util.Vector ; 4 5 import junit.framework.Test; 6 import junit.framework.TestSuite; 7 8 import org.jgroups.Address; 9 import org.jgroups.Channel; 10 import org.jgroups.tests.ChannelTestBase; 11 import org.jgroups.util.RspList; 12 import org.jgroups.util.Util; 13 14 18 public class RpcDispatcherAnycastTest extends ChannelTestBase { 19 RpcDispatcher disp, disp2, disp3; 20 Channel ch, ch2, ch3; 21 22 public void setUp() throws Exception { 23 super.setUp(); 24 25 ch=createChannel("A"); 26 ServerObject obj=new ServerObject(null); 27 disp=new RpcDispatcher(ch, null, null, obj); 28 ch.connect("demo"); 29 obj.setAddress(ch.getLocalAddress()); 30 31 ch2=createChannel("A"); 32 ServerObject obj2=new ServerObject(null); 33 disp2=new RpcDispatcher(ch2, null, null, obj2); 34 ch2.connect("demo"); 35 obj2.setAddress(ch2.getLocalAddress()); 36 37 ch3=createChannel("A"); 38 ServerObject obj3=new ServerObject(null); 39 disp3=new RpcDispatcher(ch3, null, null, obj3); 40 ch3.connect("demo"); 41 obj3.setAddress(ch3.getLocalAddress()); 42 } 43 44 public void tearDown() throws Exception { 45 super.tearDown(); 46 47 48 ch3.close(); 49 disp3.stop(); 50 ch2.close(); 51 disp2.stop(); 52 ch.close(); 53 disp.stop(); 54 } 55 56 57 58 public void testUnserializableValue() { 59 Vector members=ch.getView().getMembers(); 60 System.out.println("members: " + members); 61 assertTrue("we should have more than 1 member", members.size() > 1); 62 63 Vector subset=Util.pickSubset(members, 0.2); 64 System.out.println("subset: " + subset); 65 66 Util.sleep(1000); 67 68 RspList rsps=disp.callRemoteMethods(subset, "foo", null, (Class [])null, GroupRequest.GET_ALL, 0, false); 69 System.out.println("rsps (no anycast): " + rsps); 70 71 rsps=disp.callRemoteMethods(subset, "foo", null, (Class [])null, GroupRequest.GET_ALL, 0, true); 72 System.out.println("rsps (with anycast): " + rsps); 73 } 74 75 76 static class ServerObject { 77 Address addr; 78 79 public ServerObject(Address addr) { 80 this.addr=addr; 81 } 82 83 public Address foo() { 84 System.out.println("foo() - returning " + addr); 85 return addr; 86 } 87 88 public void setAddress(Address localAddress) { 89 addr=localAddress; 90 } 91 } 92 93 94 public static Test suite() { 95 return new TestSuite(RpcDispatcherAnycastTest.class); 96 } 97 98 99 public static void main(String [] args) { 100 junit.textui.TestRunner.run(RpcDispatcherAnycastTest.suite()); 101 } 102 } 103 | Popular Tags |