Search in sources :

Example 26 with MethodCall

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;
}
Also used : RpcDispatcher(org.jgroups.blocks.RpcDispatcher) RequestOptions(org.jgroups.blocks.RequestOptions) BeforeMethod(org.testng.annotations.BeforeMethod) AfterMethod(org.testng.annotations.AfterMethod) Method(java.lang.reflect.Method) MethodCall(org.jgroups.blocks.MethodCall)

Example 27 with MethodCall

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;
}
Also used : RequestOptions(org.jgroups.blocks.RequestOptions) MethodCall(org.jgroups.blocks.MethodCall) SiteMaster(org.jgroups.protocols.relay.SiteMaster) RELAY2(org.jgroups.protocols.relay.RELAY2) Route(org.jgroups.protocols.relay.Route)

Example 28 with MethodCall

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));
}
Also used : RpcDispatcher(org.jgroups.blocks.RpcDispatcher) Address(org.jgroups.Address) RequestOptions(org.jgroups.blocks.RequestOptions) RspList(org.jgroups.util.RspList) MethodCall(org.jgroups.blocks.MethodCall)

Example 29 with MethodCall

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());
}
Also used : RpcDispatcher(org.jgroups.blocks.RpcDispatcher) Address(org.jgroups.Address) RequestOptions(org.jgroups.blocks.RequestOptions) RspList(org.jgroups.util.RspList) ArrayList(java.util.ArrayList) MethodCall(org.jgroups.blocks.MethodCall)

Example 30 with MethodCall

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);
}
Also used : RpcDispatcher(org.jgroups.blocks.RpcDispatcher) Address(org.jgroups.Address) RequestOptions(org.jgroups.blocks.RequestOptions) MethodCall(org.jgroups.blocks.MethodCall)

Aggregations

MethodCall (org.jgroups.blocks.MethodCall)31 RequestOptions (org.jgroups.blocks.RequestOptions)9 Method (java.lang.reflect.Method)6 Address (org.jgroups.Address)5 RpcDispatcher (org.jgroups.blocks.RpcDispatcher)5 Rsp (org.jgroups.util.Rsp)3 SiteMaster (org.jgroups.protocols.relay.SiteMaster)2 RspList (org.jgroups.util.RspList)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 JChannel (org.jgroups.JChannel)1 AdditionalJmxObjects (org.jgroups.jmx.AdditionalJmxObjects)1 RELAY2 (org.jgroups.protocols.relay.RELAY2)1 Route (org.jgroups.protocols.relay.Route)1 Protocol (org.jgroups.stack.Protocol)1 Average (org.jgroups.util.Average)1 AfterMethod (org.testng.annotations.AfterMethod)1 BeforeMethod (org.testng.annotations.BeforeMethod)1 Test (org.testng.annotations.Test)1