}
// write some messages
for (int i = 0; i < CLIENT_COUNT; i++) {
byte[] data = ("test:" + i).getBytes();
clients[i].send(new DatagramPacket(data, data.length, serverAddy));
}
// does the session open message was fired ?
assertTrue(openLatch.await(WAIT_TIME, TimeUnit.MILLISECONDS));
// test is message was received by the server
assertTrue(msgReadLatch.await(WAIT_TIME, TimeUnit.MILLISECONDS));
// does response was wrote and sent ?
assertTrue(msgSentLatch.await(WAIT_TIME, TimeUnit.MILLISECONDS));
// read the echos
final byte[] buffer = new byte[1024];
for (int i = 0; i < CLIENT_COUNT; i++) {
DatagramPacket dp = new DatagramPacket(buffer, buffer.length);
clients[i].receive(dp);
final String text = new String(buffer, 0, dp.getLength());
assertEquals("test:" + i, text);
}
msgReadLatch = new CountDownLatch(CLIENT_COUNT);
// try again
// write some messages again
for (int i = 0; i < CLIENT_COUNT; i++) {
byte[] data = ("test:" + i).getBytes();
clients[i].send(new DatagramPacket(data, data.length, serverAddy));
}
// test is message was received by the server
assertTrue(msgReadLatch.await(WAIT_TIME, TimeUnit.MILLISECONDS));