import java.net.InetAddress;
import java.util.ArrayList;
import java.util.List;
import junit.framework.TestCase;
import dijjer.io.comm.Message;
import dijjer.io.comm.MessageFilter;
import dijjer.io.comm.Peer;
import dijjer.io.comm.RoutingTable;
import dijjer.io.comm.UdpSocketManager;
/**
* Mason : Nov 28, 2004 : 3:54:37 PM
*/
public class RoutingTableTest extends TestCase {
public static final String VERSION = "$Id: RoutingTableTest.java,v 1.9 2005/04/12 13:04:16 sanity Exp $";
public void testRouting() throws Exception {
TestUdpSocketManager usm = new TestUdpSocketManager(-1);
RoutingTable rt = new RoutingTable(100, usm, null, false);
Peer p = new Peer(InetAddress.getByAddress(new byte[]{5, 6, 7, 8}), 105);
rt.joinSeed(p);
assertEquals(p, usm._sentPeers.get(0));
}
public static class TestUdpSocketManager extends UdpSocketManager {
public TestUdpSocketManager(int listenPort) throws Exception {
super(listenPort);
}
public List _sentPeers = new ArrayList();
public List _sentMessage = new ArrayList();
public List _waitFilters = new ArrayList();
public void send(Peer destination, Message m) {
_sentPeers.add(destination);
_sentMessage.add(m);
}
public Message waitFor(MessageFilter filter) {
_waitFilters.add(filter);
return null;
}
}
}