Commit fb684f73 authored by Flavio Paiva Junqueira's avatar Flavio Paiva Junqueira
Browse files

ZOOKEEPER-1849. Need to properly tear down tests in various

  cases (Germán via fpj)



git-svn-id: https://svn.apache.org/repos/asf/zookeeper/branches/branch-3.4@1552447 13f79535-47bb-0310-9956-ffa450edef68
parent ed62ebc3
......@@ -199,9 +199,13 @@ BUGFIXES:
ZOOKEEPER-1841. problem in QuorumTest (Germán via fpj)
ZOOKEEPER-1733. FLETest#testLE is flaky on windows boxes
ZOOKEEPER-1733 FLETest#testLE is flaky oo.l windows boxes
(michim, Jeffrey Zhong via fpj)
ZOOKEEPER-1849. Need to properly tear down tests in various
cases (Germán via fpj)
IMPROVEMENTS:
ZOOKEEPER-1564. Allow JUnit test build with IBM Java
......
......@@ -50,6 +50,14 @@ public class JUnit4ZKTestRunner extends BlockJUnit4ClassRunner {
LOG.info("RUNNING TEST METHOD " + name);
try {
super.evaluate();
Runtime rt = Runtime.getRuntime();
long usedKB = (rt.totalMemory() - rt.freeMemory()) / 1024;
LOG.info("Memory used {}", usedKB);
ThreadGroup tg = Thread.currentThread().getThreadGroup();
while (tg.getParent() != null) {
tg = tg.getParent();
}
LOG.info("Number of threads {}", tg.activeCount());
} catch (Throwable t) {
LOG.info("TEST METHOD FAILED " + name, t);
throw t;
......
......@@ -131,6 +131,7 @@ public class CRCTest extends ZKTestCase implements Watcher {
zk.close();
}
f.shutdown();
zks.shutdown();
Assert.assertTrue("waiting for server down",
ClientBase.waitForServerDown(HOSTPORT,
ClientBase.CONNECTION_TIMEOUT));
......
......@@ -110,8 +110,8 @@ public class ACLCountTest extends ZKTestCase implements Watcher {
Assert.assertTrue(false);
}
Assert.assertTrue(true);
f.shutdown();
zks.shutdown();
}
......
......@@ -71,7 +71,7 @@ public class ACLTest extends ZKTestCase implements Watcher {
}
} finally {
f.shutdown();
zks.shutdown();
Assert.assertTrue("waiting for server down",
ClientBase.waitForServerDown(HOSTPORT,
ClientBase.CONNECTION_TIMEOUT));
......@@ -122,6 +122,7 @@ public class ACLTest extends ZKTestCase implements Watcher {
} finally {
// now shutdown the server and restart it
f.shutdown();
zks.shutdown();
Assert.assertTrue("waiting for server down",
ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
}
......@@ -157,7 +158,7 @@ public class ACLTest extends ZKTestCase implements Watcher {
zk.close();
} finally {
f.shutdown();
zks.shutdown();
Assert.assertTrue("waiting for server down",
ClientBase.waitForServerDown(HOSTPORT,
ClientBase.CONNECTION_TIMEOUT));
......
......@@ -99,6 +99,7 @@ public class ClientPortBindTest extends ZKTestCase implements Watcher {
zk.close();
} finally {
f.shutdown();
zks.shutdown();
Assert.assertTrue("waiting for server down",
ClientBase.waitForServerDown(HOSTPORT,
......
......@@ -107,6 +107,7 @@ public class InvalidSnapshotTest extends ZKTestCase implements Watcher {
zk.close();
}
f.shutdown();
zks.shutdown();
Assert.assertTrue("waiting for server down",
ClientBase.waitForServerDown(HOSTPORT,
ClientBase.CONNECTION_TIMEOUT));
......
......@@ -115,6 +115,7 @@ public class LoadFromLogTest extends ZKTestCase implements Watcher {
}while(itr.next());
Assert.assertTrue("processed all transactions. " + expectedZxid + " == " + TOTAL_TRANSACTIONS, (expectedZxid == TOTAL_TRANSACTIONS));
zks.shutdown();
}
......@@ -366,6 +367,7 @@ public class LoadFromLogTest extends ZKTestCase implements Watcher {
+ " expected " + NUM_MESSAGES,
(children.length == NUM_MESSAGES));
f.shutdown();
zks.shutdown();
}
/**
......@@ -433,5 +435,6 @@ public class LoadFromLogTest extends ZKTestCase implements Watcher {
.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
f.shutdown();
zks.shutdown();
}
}
\ No newline at end of file
......@@ -51,6 +51,7 @@ public class MaxCnxnsTest extends ClientBase {
}
public void run() {
SocketChannel sChannel = null;
try {
/*
* For future unwary socket programmers: although connect 'blocks' it
......@@ -58,7 +59,7 @@ public class MaxCnxnsTest extends ClientBase {
* you can not assume that all the sockets are connected at the end of
* this for loop.
*/
SocketChannel sChannel = SocketChannel.open();
sChannel = SocketChannel.open();
sChannel.connect(new InetSocketAddress(host,port));
// Construct a connection request
ConnectRequest conReq = new ConnectRequest(0, 0,
......@@ -97,6 +98,15 @@ public class MaxCnxnsTest extends ClientBase {
catch (IOException io) {
// "Connection reset by peer"
}
finally {
if (sChannel != null) {
try {
sChannel.close();
}
catch (Exception e) {
}
}
}
}
}
......
......@@ -98,6 +98,7 @@ public class OOMTest extends ZKTestCase implements Watcher {
hog.get(0)[0] = (byte) 1;
f.shutdown();
zks.shutdown();
Assert.assertTrue("waiting for server down",
ClientBase.waitForServerDown("127.0.0.1:" + PORT,
CONNECTION_TIMEOUT));
......
......@@ -78,6 +78,7 @@ public class PurgeTxnTest extends ZKTestCase implements Watcher {
}
}
Assert.assertTrue("exactly 3 snapshots ", (numSnaps == 3));
zks.shutdown();
}
public void process(WatchedEvent event) {
......
......@@ -105,6 +105,7 @@ public class RecoveryTest extends ZKTestCase implements Watcher {
}
f.shutdown();
zks.shutdown();
Assert.assertTrue("waiting for server down",
ClientBase.waitForServerDown(HOSTPORT,
CONNECTION_TIMEOUT));
......@@ -142,6 +143,7 @@ public class RecoveryTest extends ZKTestCase implements Watcher {
}
}
f.shutdown();
zks.shutdown();
Assert.assertTrue("waiting for server down",
ClientBase.waitForServerDown(HOSTPORT,
......@@ -181,6 +183,7 @@ public class RecoveryTest extends ZKTestCase implements Watcher {
zk.close();
f.shutdown();
zks.shutdown();
Assert.assertTrue("waiting for server down",
ClientBase.waitForServerDown(HOSTPORT,
......
......@@ -60,6 +60,7 @@ public class RepeatStartupTest extends ZKTestCase {
ClientBase.waitForServerUp("127.0.0.1:" + PORT,
QuorumTest.CONNECTION_TIMEOUT));
factory.shutdown();
zks.shutdown();
Assert.assertTrue("waiting for server down",
ClientBase.waitForServerDown("127.0.0.1:" + PORT,
QuorumTest.CONNECTION_TIMEOUT));
......
......@@ -70,6 +70,7 @@ public class RestoreCommittedLogTest extends ZKTestCase implements Watcher {
zk.close();
}
f.shutdown();
zks.shutdown();
Assert.assertTrue("waiting for server to shutdown",
ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
......@@ -80,6 +81,7 @@ public class RestoreCommittedLogTest extends ZKTestCase implements Watcher {
int logsize = committedLog.size();
LOG.info("committedLog size = " + logsize);
Assert.assertTrue("log size != 0", (logsize != 0));
zks.shutdown();
}
public void process(WatchedEvent event) {
......
......@@ -57,6 +57,7 @@ public class SessionTest extends ZKTestCase {
PortAssignment.unique();
private ServerCnxnFactory serverFactory;
private ZooKeeperServer zs;
private CountDownLatch startSignal;
......@@ -71,7 +72,7 @@ public class SessionTest extends ZKTestCase {
}
ClientBase.setupTestEnv();
ZooKeeperServer zs = new ZooKeeperServer(tmpDir, tmpDir, TICK_TIME);
zs = new ZooKeeperServer(tmpDir, tmpDir, TICK_TIME);
final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
serverFactory = ServerCnxnFactory.createFactory(PORT, -1);
......@@ -85,6 +86,7 @@ public class SessionTest extends ZKTestCase {
@After
public void tearDown() throws Exception {
serverFactory.shutdown();
zs.shutdown();
Assert.assertTrue("waiting for server down",
ClientBase.waitForServerDown(HOSTPORT,
CONNECTION_TIMEOUT));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment