public static final int PORT_UDP = 5002;
@Test
public void testNeigbhor() throws Exception {
Peer sender = null;
Peer recv1 = null;
try {
sender = new PeerBuilder(new Number160("0x50")).p2pId(55).ports(2424).start();
PeerAddress[] pa = Utils2.createDummyAddress(300, PORT_TCP, PORT_UDP);
for (int i = 0; i < pa.length; i++) {
sender.peerBean().peerMap().peerFound(pa[i], null, null);
}
new NeighborRPC(sender.peerBean(), sender.connectionBean());
recv1 = new PeerBuilder(new Number160("0x20")).p2pId(55).ports(8088).start();
NeighborRPC neighbors2 = new NeighborRPC(recv1.peerBean(), recv1.connectionBean());
FutureChannelCreator fcc = recv1.connectionBean().reservation().create(1, 0);
fcc.awaitUninterruptibly();
ChannelCreator cc = fcc.channelCreator();
SearchValues v = new SearchValues(new Number160("0x1"), null);
FutureResponse fr = neighbors2.closeNeighbors(sender.peerAddress(), v,
Type.REQUEST_2, cc, new DefaultConnectionConfiguration());
fr.awaitUninterruptibly();
// Thread.sleep(10000000);
Assert.assertEquals(true, fr.isSuccess());
NeighborSet pas = fr.responseMessage().neighborsSet(0);
// we are able to fit 40 neighbors into 1400 bytes
Assert.assertEquals(33, pas.size());
Assert.assertEquals(new Number160("0x1"), pas.neighbors().iterator().next().peerId());
Assert.assertEquals(PORT_TCP, pas.neighbors().iterator().next().tcpPort());
Assert.assertEquals(PORT_UDP, pas.neighbors().iterator().next().udpPort());
cc.shutdown();
} finally {
if (sender != null) {
sender.shutdown().await();
}
if (recv1 != null) {
recv1.shutdown().await();
}
}
}