use of org.apache.zookeeper.server.util.OSMXBean in project zookeeper by apache.
the class NIOConnectionFactoryFdLeakTest method testFileDescriptorLeak.
@Test
public void testFileDescriptorLeak() throws Exception {
OSMXBean osMbean = new OSMXBean();
if (osMbean.getUnix() != true) {
LOG.info("Unable to run test on non-unix system");
return;
}
long startFdCount = osMbean.getOpenFileDescriptorCount();
LOG.info("Start fdcount is: " + startFdCount);
for (int i = 0; i < 50; ++i) {
NIOServerCnxnFactory factory = new NIOServerCnxnFactory();
factory.configure(new InetSocketAddress("127.0.0.1", PortAssignment.unique()), 10);
factory.start();
Thread.sleep(100);
factory.shutdown();
}
long endFdCount = osMbean.getOpenFileDescriptorCount();
LOG.info("End fdcount is: " + endFdCount);
// On my box, if selector.close() is not called fd diff is > 700.
Assert.assertTrue("Possible fd leakage", ((endFdCount - startFdCount) < 50));
}
use of org.apache.zookeeper.server.util.OSMXBean in project zookeeper by apache.
the class ClientTest method testClientCleanup.
/**
* Verify that the client is cleaning up properly. Open/close a large
* number of sessions. Essentially looking to see if sockets/selectors
* are being cleaned up properly during close.
*
* @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));
} else {
LOG.info(logmsg, Long.valueOf(currentCount), Long.valueOf(initialFdCount));
}
}
use of org.apache.zookeeper.server.util.OSMXBean in project zookeeper by apache.
the class QuorumUtil method tearDown.
public void tearDown() throws Exception {
LOG.info("TearDown started");
OSMXBean osMbean = new OSMXBean();
if (osMbean.getUnix() == true) {
LOG.info("fdcount after test is: " + osMbean.getOpenFileDescriptorCount());
}
shutdownAll();
JMXEnv.tearDown();
}
use of org.apache.zookeeper.server.util.OSMXBean in project zookeeper by apache.
the class QuorumBase method setUp.
protected void setUp(boolean withObservers) throws Exception {
LOG.info("QuorumBase.setup " + getTestName());
setupTestEnv();
JMXEnv.setUp();
setUpAll();
port1 = PortAssignment.unique();
port2 = PortAssignment.unique();
port3 = PortAssignment.unique();
port4 = PortAssignment.unique();
port5 = PortAssignment.unique();
portLE1 = PortAssignment.unique();
portLE2 = PortAssignment.unique();
portLE3 = PortAssignment.unique();
portLE4 = PortAssignment.unique();
portLE5 = PortAssignment.unique();
portClient1 = PortAssignment.unique();
portClient2 = PortAssignment.unique();
portClient3 = PortAssignment.unique();
portClient4 = PortAssignment.unique();
portClient5 = PortAssignment.unique();
hostPort = "127.0.0.1:" + portClient1 + ",127.0.0.1:" + portClient2 + ",127.0.0.1:" + portClient3 + ",127.0.0.1:" + portClient4 + ",127.0.0.1:" + portClient5;
LOG.info("Ports are: " + hostPort);
s1dir = ClientBase.createTmpDir();
s2dir = ClientBase.createTmpDir();
s3dir = ClientBase.createTmpDir();
s4dir = ClientBase.createTmpDir();
s5dir = ClientBase.createTmpDir();
startServers(withObservers);
OSMXBean osMbean = new OSMXBean();
if (osMbean.getUnix() == true) {
LOG.info("Initial fdcount is: " + osMbean.getOpenFileDescriptorCount());
}
LOG.info("Setup finished");
}
Aggregations