use of org.jgroups.blocks.MethodCall in project JGroups by belaban.
the class RSVPTest method testRpcWithFuture.
public void testRpcWithFuture() throws Exception {
final Method method = getClass().getMethod("getGreeting");
RpcDispatcher[] dispatchers = new RpcDispatcher[channels.length];
for (int i = 0; i < dispatchers.length; i++) {
channels[i].setReceiver(null);
dispatchers[i] = new RpcDispatcher(channels[i], this);
dispatchers[i].start();
}
DISCARD discard = channels[0].getProtocolStack().findProtocol(DISCARD.class);
discard.setDropDownMulticasts(1);
RequestOptions opts = RequestOptions.SYNC().flags(Message.Flag.RSVP_NB);
long start = System.currentTimeMillis();
Future<RspList<String>> future = dispatchers[0].callRemoteMethodsWithFuture(null, new MethodCall(method), opts);
long rpc_time = System.currentTimeMillis() - start;
start = System.currentTimeMillis();
RspList<String> rsps = future.get(3000, TimeUnit.MILLISECONDS);
long get_time = System.currentTimeMillis() - start;
System.out.printf("rsps=\n%s\nRPC time=%d ms, Get time=%d ms", rsps, rpc_time, get_time);
assert rsps.size() == channels.length;
for (Rsp rsp : rsps) assert rsp.wasReceived() && rsp.getValue() != null;
// take a GC into account
assert rpc_time < 500;
}
use of org.jgroups.blocks.MethodCall in project JGroups by belaban.
the class Relay2RpcDispatcherTest method testNotificationAndRpcRelay2Transit.
/**
* Tests that notifications are routed to all sites.
*/
public void testNotificationAndRpcRelay2Transit() throws Exception {
a.connect(LON_CLUSTER);
b.connect(LON_CLUSTER);
rpca.start();
rpcb.start();
Util.waitUntilAllChannelsHaveSameView(30000, 1000, a, b);
x.connect(SFO_CLUSTER);
y.connect(SFO_CLUSTER);
rpcx.start();
rpcy.start();
Util.waitUntilAllChannelsHaveSameView(30000, 1000, x, y);
assert a.getView().size() == 2;
assert x.getView().size() == 2;
RELAY2 ar = a.getProtocolStack().findProtocol(RELAY2.class);
RELAY2 xr = x.getProtocolStack().findProtocol(RELAY2.class);
assert ar != null && xr != null;
JChannel a_bridge = null, x_bridge = null;
for (int i = 0; i < 20; i++) {
a_bridge = ar.getBridge(SFO);
x_bridge = xr.getBridge(LON);
if (a_bridge != null && x_bridge != null && a_bridge.getView().size() == 2 && x_bridge.getView().size() == 2)
break;
Util.sleep(500);
}
assert a_bridge != null && x_bridge != null;
System.out.println("A's bridge channel: " + a_bridge.getView());
System.out.println("X's bridge channel: " + x_bridge.getView());
assert a_bridge.getView().size() == 2 : "bridge view is " + a_bridge.getView();
assert x_bridge.getView().size() == 2 : "bridge view is " + x_bridge.getView();
Route route = getRoute(x, LON);
System.out.println("Route at sfo to lon: " + route);
assert route != null;
System.out.println("B: sending message 0 to the site master of SFO");
Address sm_sfo = new SiteMaster(SFO);
MethodCall call = new MethodCall(ServerObject.class.getMethod("foo"));
System.out.println("B: call foo method on A");
Object rsp = rpcb.callRemoteMethod(a.getAddress(), call, new RequestOptions(ResponseMode.GET_ALL, 5000));
System.out.println("RSP is: " + rsp);
System.out.println("B: call foo method on SFO master site");
rsp = rpcb.callRemoteMethod(sm_sfo, call, new RequestOptions(ResponseMode.GET_ALL, 15000));
System.out.println("RSP is: " + rsp);
System.out.println("B: call foo method on all members in site LON");
RspList<Integer> rsps = rpcb.callRemoteMethods(null, call, new RequestOptions(ResponseMode.GET_ALL, 5000));
System.out.println("RSPs are: \n" + rsps);
assert rsps.size() == 2;
assert rsps.containsKey(a.getAddress()) && rsps.containsKey(b.getAddress());
View bridge_view = xr.getBridgeView(BRIDGE_CLUSTER);
System.out.println("bridge_view = " + bridge_view);
route = getRoute(x, LON);
System.out.println("Route at sfo to lon: " + route);
assert route != null;
}
use of org.jgroups.blocks.MethodCall in project JGroups by belaban.
the class Deadlock2Test method testOneChannel.
/**
* Tests the deadlock resolution using self-calls on a single channel. The deadlock detection
* is turned on so the method call should go straight through. If there is a problem, JUnit will
* timeout.
*
* @throws Exception
*/
public void testOneChannel() throws Exception {
c1 = createChannel(true);
ServerObject serverObject = new ServerObject("obj1");
RpcDispatcher disp = new RpcDispatcher(c1, serverObject);
serverObject.setRpcDispatcher(disp);
c1.connect(name);
Address localAddress = c1.getAddress();
// call the nested group method on itself
MethodCall call = new MethodCall("outerMethod", new Object[0], new Class[0]);
log("calling outerMethod() on all members");
RspList rspList = disp.callRemoteMethods(null, call, new RequestOptions(ResponseMode.GET_ALL, 0));
log("results of outerMethod(): " + rspList);
Assert.assertEquals(1, rspList.size());
assertEquals("outerMethod[innerMethod]", rspList.getValue(localAddress));
assertTrue(rspList.isReceived(localAddress));
assertFalse(rspList.isSuspected(localAddress));
}
use of org.jgroups.blocks.MethodCall in project JGroups by belaban.
the class Deadlock2Test method testTwoChannelsWithInitialMulticast.
public void testTwoChannelsWithInitialMulticast() throws Exception {
ServerObject obj1, obj2 = null;
c1 = createChannel(true);
obj1 = new ServerObject("obj1");
RpcDispatcher disp1 = new RpcDispatcher(c1, obj1);
obj1.setRpcDispatcher(disp1);
c1.connect(name);
c2 = createChannel(c1);
obj2 = new ServerObject("obj2");
RpcDispatcher disp2 = new RpcDispatcher(c2, obj2);
obj2.setRpcDispatcher(disp2);
c2.connect(name);
List<Address> dests = new ArrayList<>();
dests.add(c1.getAddress());
dests.add(c2.getAddress());
// call a point-to-point method on Member 2 that triggers a nested distributed RPC
MethodCall call = new MethodCall("outerMethod", new Object[0], new Class[0]);
log("calling outerMethod() on all members");
RspList rsps = disp1.callRemoteMethods(dests, call, new RequestOptions(ResponseMode.GET_ALL, 0));
log("results of outerMethod():\n" + rsps);
Assert.assertEquals(2, rsps.size());
}
use of org.jgroups.blocks.MethodCall in project JGroups by belaban.
the class Deadlock2Test method testTwoChannels.
/**
* Tests the deadlock resolution using two different channels. The deadlock detection
* is turned on. It implements the following scenario:
*
* Channel1 Channel2
* | |
* + -------------------------------> outerMethod()
* | RPC
* | |
* | |
* | |
* | <-- innerMethod() <-----------------+ ---------+
* | | |
* | | <-- innerMethod()
*
* If there is a deadlock, JUnit will timeout and fail the test.
*/
public void testTwoChannels() throws Throwable {
ServerObject obj1, obj2 = null;
c1 = createChannel(true);
obj1 = new ServerObject("obj1");
RpcDispatcher disp1 = new RpcDispatcher(c1, obj1);
obj1.setRpcDispatcher(disp1);
c1.connect(name);
c2 = createChannel(c1);
obj2 = new ServerObject("obj2");
RpcDispatcher disp2 = new RpcDispatcher(c2, obj2);
obj2.setRpcDispatcher(disp2);
c2.connect(name);
Address localAddress2 = c2.getAddress();
// call a point-to-point method on Member 2 that triggers a nested distributed RPC
MethodCall call = new MethodCall("outerMethod", new Object[0], new Class[0]);
log("calling outerMethod() on " + localAddress2);
Object retval = disp1.callRemoteMethod(localAddress2, call, new RequestOptions(ResponseMode.GET_ALL, 0));
log("results of outerMethod(): " + retval);
}
Aggregations