*
* @throws Throwable
*/
@Test
public void testClientCleanup() throws Throwable {
OSMXBean osMbean = new OSMXBean();
if (osMbean.getUnix() == false) {
LOG.warn("skipping testClientCleanup, only available on Unix");
return;
}
final int threadCount = 3;
final int clientCount = 10;
/* Log the number of fds used before and after a test is run. Verifies
* we are freeing resources correctly. Unfortunately this only works
* on unix systems (the only place sun has implemented as part of the
* mgmt bean api).
*/
long initialFdCount = osMbean.getOpenFileDescriptorCount();
VerifyClientCleanup threads[] = new VerifyClientCleanup[threadCount];
for (int i = 0; i < threads.length; i++) {
threads[i] = new VerifyClientCleanup("VCC" + i, clientCount);
threads[i].start();
}
for (int i = 0; i < threads.length; i++) {
threads[i].join(CONNECTION_TIMEOUT);
Assert.assertTrue(threads[i].current == threads[i].count);
}
// if this Assert.fails it means we are not cleaning up after the closed
// sessions.
long currentCount = osMbean.getOpenFileDescriptorCount();
final String logmsg = "open fds after test ({}) are not significantly higher than before ({})";
if (currentCount > initialFdCount + 10) {
// consider as error
LOG.error(logmsg,Long.valueOf(currentCount),Long.valueOf(initialFdCount));