Peer sender = null;
Peer recv1 = null;
try {
final CountConnectionOutboundHandler ccohTCP = new CountConnectionOutboundHandler();
final CountConnectionOutboundHandler ccohUDP = new CountConnectionOutboundHandler();
PipelineFilter pf = new PipelineFilter() {
@Override
public Map<String, Pair<EventExecutorGroup, ChannelHandler>> filter(Map<String, Pair<EventExecutorGroup, ChannelHandler>> channelHandlers, boolean tcp,
boolean client) {
Map<String, Pair<EventExecutorGroup, ChannelHandler>> retVal = new LinkedHashMap<String, Pair<EventExecutorGroup, ChannelHandler>>();
retVal.put("counter", new Pair<EventExecutorGroup, ChannelHandler>(null, tcp? ccohTCP:ccohUDP));
retVal.putAll(channelHandlers);
return retVal;
}
};
ChannelServerConfiguration csc = PeerBuilder.createDefaultChannelServerConfiguration();
ChannelClientConfiguration ccc = PeerBuilder.createDefaultChannelClientConfiguration();
csc.pipelineFilter(pf);
ccc.pipelineFilter(pf);
sender = new PeerBuilder(new Number160("0x50")).p2pId(55).enableMaintenance(false).ports(2424).channelClientConfiguration(ccc).channelServerConfiguration(csc).start();
recv1 = new PeerBuilder(new Number160("0x20")).p2pId(55).enableMaintenance(false).ports(8088).channelClientConfiguration(ccc).channelServerConfiguration(csc).start();
recv1.objectDataReply(new ObjectDataReply() {
@Override
public Object reply(PeerAddress sender, Object request) throws Exception {
return "yes";
}
});
FuturePeerConnection peerConnection = sender.createPeerConnection(recv1.peerAddress());
ccohTCP.reset();
ccohUDP.reset();
FutureDirect fd1 = sender.sendDirect(peerConnection).object("test")
.connectionTimeoutTCPMillis(2000).idleTCPSeconds(10 * 1000).start();
fd1.awaitListenersUninterruptibly();
Assert.assertEquals(true, fd1.isSuccess());
Assert.assertEquals(1, ccohTCP.total());
Assert.assertEquals(0, ccohUDP.total());
Thread.sleep(2000);
System.err.println("send second with the same connection");
FutureDirect fd2 = sender.sendDirect(peerConnection).object("test").start();
fd2.awaitUninterruptibly();
Assert.assertEquals(1, ccohTCP.total());
Assert.assertEquals(0, ccohUDP.total());
Assert.assertEquals(true, fd2.isSuccess());
peerConnection.close().await();
System.err.println("done");
} finally {
if (sender != null) {