Search in sources :

Example 6 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)

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