Search in sources :

Example 31 with MethodCall

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

the class FlowControlUnitTest method forward.

/**
 * First callback called by B (on A); this will call receive(byte[])
 * @param target The target to call. Null == multicast RPC
 * @param num_bytes The number of bytes to send
 */
@Test(enabled = false)
public void forward(Address target, int num_bytes) throws Exception {
    byte[] buffer = new byte[num_bytes];
    if (target != null) {
        // unicast
        Object retval = da.callRemoteMethod(target, new MethodCall(RECEIVE, a.getAddress(), buffer), RequestOptions.SYNC().timeout(5000).flags(Message.Flag.OOB));
        System.out.println("retval=" + retval);
        int actual_bytes = (Integer) retval;
        assert actual_bytes == num_bytes : "expected " + Util.printBytes(num_bytes) + ", but call returned " + Util.printBytes(actual_bytes);
    } else {
        // multicast
        RspList<Object> rsps = da.callRemoteMethods(null, new MethodCall(RECEIVE, a.getAddress(), buffer), RequestOptions.SYNC().timeout(5000).flags(Message.Flag.OOB));
        System.out.println("rsps:\n" + rsps);
        assert rsps.size() == 2;
        for (Map.Entry<Address, Rsp<Object>> entry : rsps.entrySet()) {
            Rsp<Object> rsp = entry.getValue();
            assert rsp.wasReceived() : " rsp from " + entry.getKey() + " was not received";
            int actual_bytes = (Integer) rsp.getValue();
            assert actual_bytes == num_bytes : "expected " + Util.printBytes(num_bytes) + ", but call returned " + Util.printBytes(actual_bytes);
        }
    }
}
Also used : MethodCall(org.jgroups.blocks.MethodCall) Map(java.util.Map) Rsp(org.jgroups.util.Rsp) Test(org.testng.annotations.Test)

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