@Override 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()); } shutdownServers(); for (String hp : hostPort.split(",")) { Assert.assertTrue("waiting for server down", ClientBase.waitForServerDown(hp, ClientBase.CONNECTION_TIMEOUT)); LOG.info(hp + " is no longer accepting client connections"); } JMXEnv.tearDown(); }
@Before public void setUp() throws Exception { /* some useful information - log the number of fds used before * and after a test is run. Helps to verify 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. */ OSMXBean osMbean = new OSMXBean(); if (osMbean.getUnix() == true) { initialFdCount = osMbean.getOpenFileDescriptorCount(); LOG.info("Initial fdcount is: " + initialFdCount); } setupTestEnv(); JMXEnv.setUp(); setUpAll(); tmpDir = createTmpDir(BASETEST); startServer(); LOG.info("Client test setup finished"); }
@Before public void setUp() throws Exception { /* some useful information - log the number of fds used before * and after a test is run. Helps to verify 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. */ OSMXBean osMbean = new OSMXBean(); if (osMbean.getUnix() == true) { initialFdCount = osMbean.getOpenFileDescriptorCount(); LOG.info("Initial fdcount is: " + initialFdCount); } setupTestEnv(); JMXEnv.setUp(); setUpAll(); tmpDir = createTmpDir(BASETEST, true); startServer(); LOG.info("Client test setup finished"); }
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(); }
@After public void tearDown() throws Exception { LOG.info("tearDown starting"); tearDownAll(); stopServer(); if (tmpDir != null) { Assert.assertTrue("delete " + tmpDir.toString(), recursiveDelete(tmpDir)); } // This has to be set to null when the same instance of this class is reused between test cases serverFactory = null; JMXEnv.tearDown(); /* some useful information - log the number of fds used before * and after a test is run. Helps to verify 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. */ OSMXBean osMbean = new OSMXBean(); if (osMbean.getUnix() == true) { long fdCount = osMbean.getOpenFileDescriptorCount(); String message = "fdcount after test is: " + fdCount + " at start it was " + initialFdCount; LOG.info(message); if (fdCount > initialFdCount) { LOG.info("sleeping for 20 secs"); //Thread.sleep(60000); //assertTrue(message, fdCount <= initialFdCount); } } }
@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)); }
@Override public void commandRun() { if(zkServer == null) { pw.println(ZK_NOT_SERVING); return; } ZKDatabase zkdb = zkServer.getZKDatabase(); ServerStats stats = zkServer.serverStats(); print("version", Version.getFullVersion()); print("avg_latency", stats.getAvgLatency()); print("max_latency", stats.getMaxLatency()); print("min_latency", stats.getMinLatency()); print("packets_received", stats.getPacketsReceived()); print("packets_sent", stats.getPacketsSent()); print("num_alive_connections", stats.getNumAliveClientConnections()); print("outstanding_requests", stats.getOutstandingRequests()); print("server_state", stats.getServerState()); print("znode_count", zkdb.getNodeCount()); print("watch_count", zkdb.getDataTree().getWatchCount()); print("ephemerals_count", zkdb.getDataTree().getEphemeralsCount()); print("approximate_data_size", zkdb.getDataTree().approximateDataSize()); OSMXBean osMbean = new OSMXBean(); if (osMbean != null && osMbean.getUnix() == true) { print("open_file_descriptor_count", osMbean.getOpenFileDescriptorCount()); print("max_file_descriptor_count", osMbean.getMaxFileDescriptorCount()); } if(stats.getServerState().equals("leader")) { Leader leader = ((LeaderZooKeeperServer)zkServer).getLeader(); print("followers", leader.getLearners().size()); print("synced_followers", leader.getForwardingFollowers().size()); print("pending_syncs", leader.getNumPendingSyncs()); } }
@Before public void initialize() { this.osMbean = new OSMXBean(); Assert.assertNotNull("Could not initialize OSMXBean object!", osMbean); }
/** * 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)); } }
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(); hostPort = "127.0.0.1:" + port1 + ",127.0.0.1:" + port2 + ",127.0.0.1:" + port3 + ",127.0.0.1:" + port4 + ",127.0.0.1:" + port5; 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"); }