Search in sources :

Example 11 with RpcDispatcher

use of org.jgroups.blocks.RpcDispatcher 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 12 with RpcDispatcher

use of org.jgroups.blocks.RpcDispatcher 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 13 with RpcDispatcher

use of org.jgroups.blocks.RpcDispatcher 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)

Aggregations

RpcDispatcher (org.jgroups.blocks.RpcDispatcher)13 MethodCall (org.jgroups.blocks.MethodCall)7 RequestOptions (org.jgroups.blocks.RequestOptions)7 Method (java.lang.reflect.Method)3 MBeanServer (javax.management.MBeanServer)3 Rsp (org.jgroups.util.Rsp)3 RspList (org.jgroups.util.RspList)3 org.jgroups (org.jgroups)2 ResponseMode (org.jgroups.blocks.ResponseMode)2 JmxConfigurator (org.jgroups.jmx.JmxConfigurator)2 BeforeMethod (org.testng.annotations.BeforeMethod)2 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 LongAdder (java.util.concurrent.atomic.LongAdder)1 JChannel (org.jgroups.JChannel)1 Property (org.jgroups.annotations.Property)1