Search in sources :

Example 21 with RequestOptions

use of org.jgroups.blocks.RequestOptions 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;
    assertSiteView(a, Arrays.asList(LON, SFO));
    assert getCurrentSites(b) == null;
    assertSiteView(x, Arrays.asList(LON, SFO));
    assert getCurrentSites(y) == 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 22 with RequestOptions

use of org.jgroups.blocks.RequestOptions 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();
    obj1 = new ServerObject("obj1");
    RpcDispatcher disp1 = new RpcDispatcher(c1, obj1);
    obj1.setRpcDispatcher(disp1);
    c2 = createChannel();
    obj2 = new ServerObject("obj2");
    RpcDispatcher disp2 = new RpcDispatcher(c2, obj2);
    obj2.setRpcDispatcher(disp2);
    makeUnique(c1, c2);
    c1.connect(name);
    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) RequestOptions(org.jgroups.blocks.RequestOptions) MethodCall(org.jgroups.blocks.MethodCall)

Example 23 with RequestOptions

use of org.jgroups.blocks.RequestOptions 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, the test will time out.
 */
public void testOneChannel() throws Exception {
    c1 = createChannel();
    makeUnique(c1);
    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<String> rspList = disp.callRemoteMethods(null, call, new RequestOptions(ResponseMode.GET_ALL, 0));
    log("results of outerMethod(): " + rspList);
    Assert.assertEquals(1, rspList.size());
    assert "outerMethod[innerMethod]".equals(rspList.getValue(localAddress));
    assert rspList.isReceived(localAddress);
    assert !rspList.isSuspected(localAddress);
}
Also used : RpcDispatcher(org.jgroups.blocks.RpcDispatcher) RequestOptions(org.jgroups.blocks.RequestOptions) MethodCall(org.jgroups.blocks.MethodCall)

Example 24 with RequestOptions

use of org.jgroups.blocks.RequestOptions in project JGroups by belaban.

the class Deadlock2Test method testTwoChannelsWithInitialMulticast.

public void testTwoChannelsWithInitialMulticast() throws Exception {
    ServerObject obj1, obj2 = null;
    c1 = createChannel();
    obj1 = new ServerObject("obj1");
    RpcDispatcher disp1 = new RpcDispatcher(c1, obj1);
    obj1.setRpcDispatcher(disp1);
    c2 = createChannel();
    obj2 = new ServerObject("obj2");
    RpcDispatcher disp2 = new RpcDispatcher(c2, obj2);
    obj2.setRpcDispatcher(disp2);
    makeUnique(c1, c2);
    c1.connect(name);
    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<String> 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) RequestOptions(org.jgroups.blocks.RequestOptions) ArrayList(java.util.ArrayList) MethodCall(org.jgroups.blocks.MethodCall)

Example 25 with RequestOptions

use of org.jgroups.blocks.RequestOptions in project JGroups by belaban.

the class MessageDispatcherUnitTest method testNullMessageToAll.

public void testNullMessageToAll() throws Exception {
    da.setRequestHandler(new MyHandler(null));
    b = createChannel().name("B");
    long stop, start = System.currentTimeMillis();
    db = new MessageDispatcher(b, new MyHandler(null));
    stop = System.currentTimeMillis();
    b.connect("MessageDispatcherUnitTest");
    Assert.assertEquals(2, b.getView().size());
    System.out.println("view: " + b.getView());
    System.out.println("casting message");
    start = System.currentTimeMillis();
    RspList<byte[]> rsps = da.castMessage(null, new BytesMessage(null, buf), new RequestOptions(ResponseMode.GET_ALL, 0));
    stop = System.currentTimeMillis();
    System.out.println("rsps:\n" + rsps);
    System.out.println("call took " + (stop - start) + " ms");
    assert rsps != null;
    assert 2 == rsps.size();
    Rsp<byte[]> rsp = rsps.get(a.getAddress());
    assert rsp != null;
    Object ret = rsp.getValue();
    assert ret == null;
    rsp = rsps.get(b.getAddress());
    assert rsp != null;
    ret = rsp.getValue();
    assert ret == null;
}
Also used : MessageDispatcher(org.jgroups.blocks.MessageDispatcher) RequestOptions(org.jgroups.blocks.RequestOptions) BytesMessage(org.jgroups.BytesMessage)

Aggregations

RequestOptions (org.jgroups.blocks.RequestOptions)31 MethodCall (org.jgroups.blocks.MethodCall)15 Rsp (org.jgroups.util.Rsp)10 RpcDispatcher (org.jgroups.blocks.RpcDispatcher)8 IOException (java.io.IOException)7 CancellationException (java.util.concurrent.CancellationException)4 ExecutionException (java.util.concurrent.ExecutionException)4 TimeoutException (java.util.concurrent.TimeoutException)4 BytesMessage (org.jgroups.BytesMessage)4 Message (org.jgroups.Message)4 MessageDispatcher (org.jgroups.blocks.MessageDispatcher)4 ResponseMode (org.jgroups.blocks.ResponseMode)4 RspList (org.jgroups.util.RspList)4 Map (java.util.Map)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 org.jgroups (org.jgroups)3 Address (org.jgroups.Address)3 CommandDispatcherException (org.wildfly.clustering.dispatcher.CommandDispatcherException)3 Method (java.lang.reflect.Method)2 InetAddress (java.net.InetAddress)2