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());
}
Aggregations