Search in sources :

Example 1 with MessageDispatcher

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

the class MessageDispatcherUnitTest method sendMessageToBothChannels.

private void sendMessageToBothChannels(int size) throws Exception {
    long start, stop;
    da.setRequestHandler(new MyHandler(new byte[size]));
    b = createChannel();
    b.setName("B");
    db = new MessageDispatcher(b, new MyHandler(new byte[size]));
    b.connect("MessageDispatcherUnitTest");
    assert 2 == b.getView().size();
    System.out.println("casting message");
    start = System.currentTimeMillis();
    // RspList<Object> rsps=d1.castMessage(null, buf, new RequestOptions(ResponseMode.GET_ALL, 0));
    RspList<Object> 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.assertEquals(2, rsps.size());
    Rsp rsp = rsps.get(a.getAddress());
    assert rsp != null;
    byte[] ret = (byte[]) rsp.getValue();
    Assert.assertEquals(size, ret.length);
    rsp = rsps.get(b.getAddress());
    assert rsp != null;
    ret = (byte[]) rsp.getValue();
    Assert.assertEquals(size, ret.length);
    Util.close(b);
}
Also used : MessageDispatcher(org.jgroups.blocks.MessageDispatcher) RequestOptions(org.jgroups.blocks.RequestOptions) BytesMessage(org.jgroups.BytesMessage) Rsp(org.jgroups.util.Rsp)

Example 2 with MessageDispatcher

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

the class MessageDispatcherUnitTest method testBlockingSecondMember.

/**
 * In this scenario we block the second member so to verify the sender actually waits;
 * this won't trigger a timeout but will produce a response having "received=false".
 * It's hard to otherwise make sure casting isn't being done asynchronously.
 */
public void testBlockingSecondMember() throws Exception {
    RequestOptions requestOptions = RequestOptions.SYNC().exclusionList(// redundant - simplifies debugging
    a.getAddress()).setMode(// redundant - implied by SYNC()
    ResponseMode.GET_ALL).setTransientFlags(// redundant - self is excluded
    Message.TransientFlag.DONT_LOOPBACK).setTimeout(// Speed up the test execution
    1000);
    b = createChannel().name("B");
    BlockableRequestHandler blockableHandler = new BlockableRequestHandler();
    db = new MessageDispatcher(b).setRequestHandler(blockableHandler);
    b.connect("MessageDispatcherUnitTest");
    assert 2 == b.getView().size();
    blockableHandler.installThreadTrap();
    try {
        RspList<Object> rsps = da.castMessage(null, new BytesMessage(null, buf), requestOptions);
        System.out.printf("responses: %s\n", rsps);
        assert 1 == rsps.size();
        Rsp rsp = rsps.get(b.getAddress());
        assert rsp != null;
        assert !rsp.wasReceived();
        assert !rsp.wasSuspected();
    } catch (Exception e) {
        Assert.fail("exception returned by castMessage", e);
    } finally {
        blockableHandler.releaseBlockedThreads();
    }
    assert blockableHandler.receivedAnything();
}
Also used : MessageDispatcher(org.jgroups.blocks.MessageDispatcher) RequestOptions(org.jgroups.blocks.RequestOptions) BytesMessage(org.jgroups.BytesMessage) Rsp(org.jgroups.util.Rsp)

Example 3 with MessageDispatcher

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

the class DynamicDiscardTest method testLeaveDuringSend.

public void testLeaveDuringSend() throws Exception {
    final JChannel[] channels = new JChannel[NUM];
    final MessageDispatcher[] dispatchers = new MessageDispatcher[NUM];
    for (int i = 0; i < NUM; i++) {
        channels[i] = new JChannel(new SHARED_LOOPBACK(), new SHARED_LOOPBACK_PING(), new MERGE3(), new FD_ALL3().setTimeout(1000).setInterval(300), new NAKACK2(), new UNICAST3(), new STABLE(), new GMS(), new RSVP().ackOnDelivery(false).throwExceptionOnTimeout(false));
        channels[i].setName(Character.toString((char) ('A' + i)));
        channels[i].setDiscardOwnMessages(true);
        dispatchers[i] = new MessageDispatcher(channels[i], new MyRequestHandler());
        dispatchers[i].setReceiver(new MyMembershipListener(channels[i]));
        channels[i].connect("DynamicDiscardTest");
        System.out.print(i + 1 + " ");
    }
    Util.waitUntilAllChannelsHaveSameView(10000, 1000, channels);
    // discard all messages (except those to self)
    DISCARD discard = new DISCARD().discardAll(true);
    channels[0].getProtocolStack().insertProtocol(discard, ProtocolStack.Position.ABOVE, TP.class);
    // send a RSVP message
    byte[] data = "message2".getBytes();
    ByteArray buf = new ByteArray(data, 0, data.length);
    RspList<Object> rsps = dispatchers[0].castMessage(null, new BytesMessage(null, buf), RequestOptions.SYNC().timeout(5000).flags(Message.Flag.RSVP, Message.Flag.OOB));
    Rsp<Object> objectRsp = rsps.get(channels[1].getAddress());
    assertFalse(objectRsp.wasReceived());
    assertTrue(objectRsp.wasSuspected());
}
Also used : GMS(org.jgroups.protocols.pbcast.GMS) NAKACK2(org.jgroups.protocols.pbcast.NAKACK2) MessageDispatcher(org.jgroups.blocks.MessageDispatcher) ByteArray(org.jgroups.util.ByteArray) STABLE(org.jgroups.protocols.pbcast.STABLE)

Example 4 with MessageDispatcher

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

the class MessageDispatcherRSVPTest method setUp.

@BeforeMethod
void setUp() throws Exception {
    System.out.print("Connecting channels: ");
    for (int i = 0; i < NUM; i++) {
        channels[i] = new JChannel(new SHARED_LOOPBACK(), new DISCARD(), new SHARED_LOOPBACK_PING(), new MERGE3().setMinInterval(1000).setMaxInterval(3000), new NAKACK2().useMcastXmit(false), new UNICAST3().setXmitTableNumRows(5).setXmitInterval(300), new RSVP().setTimeout(10000).throwExceptionOnTimeout(true), new GMS().printLocalAddress(false).setLeaveTimeout(100).setJoinTimeout(500).logViewWarnings(false).setViewAckCollectionTimeout(2000).logCollectMessages(false));
        channels[i].setName(String.valueOf((i + 1)));
        channels[i].getProtocolStack().getTransport().getDiagnosticsHandler().setEnabled(false);
        dispatchers[i] = new MessageDispatcher(channels[i]);
        channels[i].connect("MessageDispatcherRSVPTest");
        System.out.print(i + 1 + " ");
        if (i == 0)
            Util.sleep(1000);
    }
    Util.waitUntilAllChannelsHaveSameView(30000, 1000, channels);
    System.out.println();
}
Also used : NAKACK2(org.jgroups.protocols.pbcast.NAKACK2) MessageDispatcher(org.jgroups.blocks.MessageDispatcher) GMS(org.jgroups.protocols.pbcast.GMS) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 5 with MessageDispatcher

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

the class MessageDispatcherUnitTest method setUp.

@BeforeClass
protected void setUp() throws Exception {
    a = createChannel().name("A");
    GMS gms = a.getProtocolStack().findProtocol(GMS.class);
    if (gms != null)
        gms.printLocalAddress(false);
    da = new MessageDispatcher(a);
    a.connect("MessageDispatcherUnitTest");
}
Also used : MessageDispatcher(org.jgroups.blocks.MessageDispatcher) GMS(org.jgroups.protocols.pbcast.GMS) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

MessageDispatcher (org.jgroups.blocks.MessageDispatcher)6 BytesMessage (org.jgroups.BytesMessage)3 RequestOptions (org.jgroups.blocks.RequestOptions)3 GMS (org.jgroups.protocols.pbcast.GMS)3 NAKACK2 (org.jgroups.protocols.pbcast.NAKACK2)2 Rsp (org.jgroups.util.Rsp)2 STABLE (org.jgroups.protocols.pbcast.STABLE)1 ByteArray (org.jgroups.util.ByteArray)1 BeforeClass (org.testng.annotations.BeforeClass)1 BeforeMethod (org.testng.annotations.BeforeMethod)1