001: package org.jgroups.blocks;
002:
003: import junit.framework.Test;
004: import junit.framework.TestCase;
005: import junit.framework.TestSuite;
006: import org.jgroups.Address;
007: import org.jgroups.JChannel;
008: import org.jgroups.util.RspList;
009: import org.jgroups.util.Util;
010:
011: import java.util.Vector;
012:
013: /**
014: * @author Bela Ban
015: * @version $Id: RpcDispatcherAnycastTest.java,v 1.1.2.1 2006/12/04 13:52:51 belaban Exp $
016: */
017: public class RpcDispatcherAnycastTest extends TestCase {
018: RpcDispatcher disp, disp2, disp3;
019: JChannel ch, ch2, ch3;
020: static String CONFIG = "udp.xml";
021:
022: protected void setUp() throws Exception {
023: super .setUp();
024: CONFIG = System.getProperty("stack", CONFIG);
025:
026: ch = new JChannel(CONFIG);
027: ServerObject obj = new ServerObject(null);
028: disp = new RpcDispatcher(ch, null, null, obj);
029: ch.connect("demo");
030: obj.setAddress(ch.getLocalAddress());
031:
032: ch2 = new JChannel(CONFIG);
033: ServerObject obj2 = new ServerObject(null);
034: disp2 = new RpcDispatcher(ch2, null, null, obj2);
035: ch2.connect("demo");
036: obj2.setAddress(ch2.getLocalAddress());
037:
038: ch3 = new JChannel(CONFIG);
039: ServerObject obj3 = new ServerObject(null);
040: disp3 = new RpcDispatcher(ch3, null, null, obj3);
041: ch3.connect("demo");
042: obj3.setAddress(ch3.getLocalAddress());
043: }
044:
045: protected void tearDown() throws Exception {
046: super .tearDown();
047:
048: ch3.close();
049: disp3.stop();
050: ch2.close();
051: disp2.stop();
052: ch.close();
053: disp.stop();
054: }
055:
056: public void testUnserializableValue() {
057: Vector members = ch.getView().getMembers();
058: System.out.println("members: " + members);
059: assertTrue("we should have more than 1 member",
060: members.size() > 1);
061:
062: Vector subset = Util.pickSubset(members, 0.2);
063: System.out.println("subset: " + subset);
064:
065: Util.sleep(1000);
066:
067: RspList rsps = disp.callRemoteMethods(subset, "foo", null,
068: (Class[]) null, GroupRequest.GET_ALL, 0, false);
069: System.out.println("rsps (no anycast): " + rsps);
070:
071: rsps = disp.callRemoteMethods(subset, "foo", null,
072: (Class[]) null, GroupRequest.GET_ALL, 0, true);
073: System.out.println("rsps (with anycast): " + rsps);
074: }
075:
076: static class ServerObject {
077: Address addr;
078:
079: public ServerObject(Address addr) {
080: this .addr = addr;
081: }
082:
083: public Address foo() {
084: System.out.println("foo() - returning " + addr);
085: return addr;
086: }
087:
088: public void setAddress(Address localAddress) {
089: addr = localAddress;
090: }
091: }
092:
093: public static Test suite() {
094: return new TestSuite(RpcDispatcherAnycastTest.class);
095: }
096:
097: public static void main(String[] args) {
098: junit.textui.TestRunner.run(RpcDispatcherAnycastTest.suite());
099: }
100: }
|