package org.jgroups.protocols; import org.jgroups.Address; import org.jgroups.Channel; import org.jgroups.Event; import org.jgroups.JChannel; import org.jgroups.Message; import org.jgroups.Receiver; import org.jgroups.View; import org.junit.Test; /** * Demonstration of the problem with NAKACK's window creation. * * @author graywatson */ public class NAKACKEarlyTest { @Test public void testQuickSend() throws Throwable { Channel ch0 = null; Channel ch1 = null; try { ch0 = startReceiver(); ch1 = startReceiver(); } finally { if (ch0 != null) ch0.close(); if (ch1 != null) ch1.close(); } } private Channel startReceiver() throws Throwable { JChannel channel = new JChannel("udp.xml"); Receiver receiver = new OurReceiver(channel); channel.setReceiver(receiver); channel.connect("foo"); return channel; } public static class OurReceiver implements Receiver { private Channel channel; public OurReceiver(Channel channel) { this.channel = channel; } public void receive(Message msg) { if (msg.getDest() == null) { System.out.println(channel.getLocalAddress() + ": received multicast message from remote " + msg.getSrc()); } else { System.out.println(channel.getLocalAddress() + ": received unicast message from remote " + msg.getSrc()); // send out a broadcast response channel.down(new Event(Event.MSG, new Message(null))); } } public byte[] getState() { return null; } public void setState(byte[] state) { } public void block() { } public void suspect(Address suspected_mbr) { } public void viewAccepted(View new_view) { // as soon as we get new members, investigate their status for (Address address : new_view.getMembers()) { channel.down(new Event(Event.MSG, new Message(address))); } } } }