// TODO: make this work
@Test
public void testTooManyOpenFilesInSystem() throws Exception {
Peer master = null;
Peer slave = null;
try {
// since we have two peers, we need to reduce the connections -> we
// will have 300 * 2 (peer connection)
// plus 100 * 2 * 2. The last multiplication is due to discover,
// where the recipient creates a connection
// with its own limit. Since the limit is 1024 and we stop at 1000
// only for the connection, we may run into
// too many open files
PeerBuilder masterMaker = new PeerBuilder(new Number160(rnd)).ports(4001);
master = masterMaker.enableMaintenance(false).start();
PeerBuilder slaveMaker = new PeerBuilder(new Number160(rnd)).ports(4002);
slave = slaveMaker.enableMaintenance(false).start();
System.err.println("peers up and running");
slave.rawDataReply(new RawDataReply() {
@Override
public Buffer reply(PeerAddress sender, Buffer requestBuffer, boolean last) throws Exception {
final byte[] b1 = new byte[10000];
int i = requestBuffer.buffer().getInt(0);
ByteBuf buf = Unpooled.wrappedBuffer(b1);
buf.setInt(0, i);
return new Buffer(buf);
}
});
List<BaseFuture> list1 = new ArrayList<BaseFuture>();
List<BaseFuture> list2 = new ArrayList<BaseFuture>();
List<FuturePeerConnection> list3 = new ArrayList<FuturePeerConnection>();
for (int i = 0; i < 125; i++) {
final byte[] b = new byte[10000];
FuturePeerConnection pc = master.createPeerConnection(slave.peerAddress());
list1.add(master.sendDirect(pc).buffer(new Buffer(Unpooled.wrappedBuffer(b))).start());
list3.add(pc);
// pc.close();
}
for (int i = 0; i < 20000; i++) {
list2.add(master.discover().peerAddress(slave.peerAddress()).start());
final byte[] b = new byte[10000];
byte[] me = Utils.intToByteArray(i);
System.arraycopy(me, 0, b, 0, 4);
list2.add(master.sendDirect(slave.peerAddress()).buffer(new Buffer(Unpooled.wrappedBuffer(b)))
.start());
}
for (BaseFuture bf : list1) {
bf.awaitListenersUninterruptibly();
if (bf.isFailed()) {
System.err.println("WTF " + bf.failedReason());
} else {
System.err.print(",");
}
Assert.assertEquals(true, bf.isSuccess());
}
for (FuturePeerConnection pc : list3) {
pc.close().awaitListenersUninterruptibly();
}
for (BaseFuture bf : list2) {
bf.awaitListenersUninterruptibly();
if (bf.isFailed()) {
System.err.println("WTF " + bf.failedReason());
} else {
System.err.print(".");
}
Assert.assertEquals(true, bf.isSuccess());
}
System.err.println("done!!");
} catch (Exception e) {
e.printStackTrace();
} finally {
System.err.println("done!1!");
if (master != null) {
master.shutdown().await();
}
if (slave != null) {
slave.shutdown().await();
}
}
}