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: ...@@ -199,9 +199,13 @@ BUGFIXES:
ZOOKEEPER-1841. problem in QuorumTest (Germán via fpj) 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) (michim, Jeffrey Zhong via fpj)
ZOOKEEPER-1849. Need to properly tear down tests in various
cases (Germán via fpj)
IMPROVEMENTS: IMPROVEMENTS:
ZOOKEEPER-1564. Allow JUnit test build with IBM Java ZOOKEEPER-1564. Allow JUnit test build with IBM Java
......
...@@ -50,6 +50,14 @@ public class JUnit4ZKTestRunner extends BlockJUnit4ClassRunner { ...@@ -50,6 +50,14 @@ public class JUnit4ZKTestRunner extends BlockJUnit4ClassRunner {
LOG.info("RUNNING TEST METHOD " + name); LOG.info("RUNNING TEST METHOD " + name);
try { try {
super.evaluate(); 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) { } catch (Throwable t) {
LOG.info("TEST METHOD FAILED " + name, t); LOG.info("TEST METHOD FAILED " + name, t);
throw t; throw t;
......
...@@ -131,6 +131,7 @@ public class CRCTest extends ZKTestCase implements Watcher { ...@@ -131,6 +131,7 @@ public class CRCTest extends ZKTestCase implements Watcher {
zk.close(); zk.close();
} }
f.shutdown(); f.shutdown();
zks.shutdown();
Assert.assertTrue("waiting for server down", Assert.assertTrue("waiting for server down",
ClientBase.waitForServerDown(HOSTPORT, ClientBase.waitForServerDown(HOSTPORT,
ClientBase.CONNECTION_TIMEOUT)); ClientBase.CONNECTION_TIMEOUT));
......
...@@ -110,8 +110,8 @@ public class ACLCountTest extends ZKTestCase implements Watcher { ...@@ -110,8 +110,8 @@ public class ACLCountTest extends ZKTestCase implements Watcher {
Assert.assertTrue(false); Assert.assertTrue(false);
} }
Assert.assertTrue(true); f.shutdown();
zks.shutdown();
} }
......
...@@ -71,7 +71,7 @@ public class ACLTest extends ZKTestCase implements Watcher { ...@@ -71,7 +71,7 @@ public class ACLTest extends ZKTestCase implements Watcher {
} }
} finally { } finally {
f.shutdown(); f.shutdown();
zks.shutdown();
Assert.assertTrue("waiting for server down", Assert.assertTrue("waiting for server down",
ClientBase.waitForServerDown(HOSTPORT, ClientBase.waitForServerDown(HOSTPORT,
ClientBase.CONNECTION_TIMEOUT)); ClientBase.CONNECTION_TIMEOUT));
...@@ -122,6 +122,7 @@ public class ACLTest extends ZKTestCase implements Watcher { ...@@ -122,6 +122,7 @@ public class ACLTest extends ZKTestCase implements Watcher {
} finally { } finally {
// now shutdown the server and restart it // now shutdown the server and restart it
f.shutdown(); f.shutdown();
zks.shutdown();
Assert.assertTrue("waiting for server down", Assert.assertTrue("waiting for server down",
ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT)); ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
} }
...@@ -157,7 +158,7 @@ public class ACLTest extends ZKTestCase implements Watcher { ...@@ -157,7 +158,7 @@ public class ACLTest extends ZKTestCase implements Watcher {
zk.close(); zk.close();
} finally { } finally {
f.shutdown(); f.shutdown();
zks.shutdown();
Assert.assertTrue("waiting for server down", Assert.assertTrue("waiting for server down",
ClientBase.waitForServerDown(HOSTPORT, ClientBase.waitForServerDown(HOSTPORT,
ClientBase.CONNECTION_TIMEOUT)); ClientBase.CONNECTION_TIMEOUT));
......
...@@ -99,6 +99,7 @@ public class ClientPortBindTest extends ZKTestCase implements Watcher { ...@@ -99,6 +99,7 @@ public class ClientPortBindTest extends ZKTestCase implements Watcher {
zk.close(); zk.close();
} finally { } finally {
f.shutdown(); f.shutdown();
zks.shutdown();
Assert.assertTrue("waiting for server down", Assert.assertTrue("waiting for server down",
ClientBase.waitForServerDown(HOSTPORT, ClientBase.waitForServerDown(HOSTPORT,
......
...@@ -107,6 +107,7 @@ public class InvalidSnapshotTest extends ZKTestCase implements Watcher { ...@@ -107,6 +107,7 @@ public class InvalidSnapshotTest extends ZKTestCase implements Watcher {
zk.close(); zk.close();
} }
f.shutdown(); f.shutdown();
zks.shutdown();
Assert.assertTrue("waiting for server down", Assert.assertTrue("waiting for server down",
ClientBase.waitForServerDown(HOSTPORT, ClientBase.waitForServerDown(HOSTPORT,
ClientBase.CONNECTION_TIMEOUT)); ClientBase.CONNECTION_TIMEOUT));
......
...@@ -115,6 +115,7 @@ public class LoadFromLogTest extends ZKTestCase implements Watcher { ...@@ -115,6 +115,7 @@ public class LoadFromLogTest extends ZKTestCase implements Watcher {
}while(itr.next()); }while(itr.next());
Assert.assertTrue("processed all transactions. " + expectedZxid + " == " + TOTAL_TRANSACTIONS, (expectedZxid == TOTAL_TRANSACTIONS)); Assert.assertTrue("processed all transactions. " + expectedZxid + " == " + TOTAL_TRANSACTIONS, (expectedZxid == TOTAL_TRANSACTIONS));
zks.shutdown();
} }
...@@ -366,6 +367,7 @@ public class LoadFromLogTest extends ZKTestCase implements Watcher { ...@@ -366,6 +367,7 @@ public class LoadFromLogTest extends ZKTestCase implements Watcher {
+ " expected " + NUM_MESSAGES, + " expected " + NUM_MESSAGES,
(children.length == NUM_MESSAGES)); (children.length == NUM_MESSAGES));
f.shutdown(); f.shutdown();
zks.shutdown();
} }
/** /**
...@@ -433,5 +435,6 @@ public class LoadFromLogTest extends ZKTestCase implements Watcher { ...@@ -433,5 +435,6 @@ public class LoadFromLogTest extends ZKTestCase implements Watcher {
.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT)); .waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
f.shutdown(); f.shutdown();
zks.shutdown();
} }
} }
\ No newline at end of file
...@@ -51,6 +51,7 @@ public class MaxCnxnsTest extends ClientBase { ...@@ -51,6 +51,7 @@ public class MaxCnxnsTest extends ClientBase {
} }
public void run() { public void run() {
SocketChannel sChannel = null;
try { try {
/* /*
* For future unwary socket programmers: although connect 'blocks' it * For future unwary socket programmers: although connect 'blocks' it
...@@ -58,7 +59,7 @@ public class MaxCnxnsTest extends ClientBase { ...@@ -58,7 +59,7 @@ public class MaxCnxnsTest extends ClientBase {
* you can not assume that all the sockets are connected at the end of * you can not assume that all the sockets are connected at the end of
* this for loop. * this for loop.
*/ */
SocketChannel sChannel = SocketChannel.open(); sChannel = SocketChannel.open();
sChannel.connect(new InetSocketAddress(host,port)); sChannel.connect(new InetSocketAddress(host,port));
// Construct a connection request // Construct a connection request
ConnectRequest conReq = new ConnectRequest(0, 0, ConnectRequest conReq = new ConnectRequest(0, 0,
...@@ -97,6 +98,15 @@ public class MaxCnxnsTest extends ClientBase { ...@@ -97,6 +98,15 @@ public class MaxCnxnsTest extends ClientBase {
catch (IOException io) { catch (IOException io) {
// "Connection reset by peer" // "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 { ...@@ -98,6 +98,7 @@ public class OOMTest extends ZKTestCase implements Watcher {
hog.get(0)[0] = (byte) 1; hog.get(0)[0] = (byte) 1;
f.shutdown(); f.shutdown();
zks.shutdown();
Assert.assertTrue("waiting for server down", Assert.assertTrue("waiting for server down",
ClientBase.waitForServerDown("127.0.0.1:" + PORT, ClientBase.waitForServerDown("127.0.0.1:" + PORT,
CONNECTION_TIMEOUT)); CONNECTION_TIMEOUT));
......
...@@ -78,6 +78,7 @@ public class PurgeTxnTest extends ZKTestCase implements Watcher { ...@@ -78,6 +78,7 @@ public class PurgeTxnTest extends ZKTestCase implements Watcher {
} }
} }
Assert.assertTrue("exactly 3 snapshots ", (numSnaps == 3)); Assert.assertTrue("exactly 3 snapshots ", (numSnaps == 3));
zks.shutdown();
} }
public void process(WatchedEvent event) { public void process(WatchedEvent event) {
......
...@@ -105,6 +105,7 @@ public class RecoveryTest extends ZKTestCase implements Watcher { ...@@ -105,6 +105,7 @@ public class RecoveryTest extends ZKTestCase implements Watcher {
} }
f.shutdown(); f.shutdown();
zks.shutdown();
Assert.assertTrue("waiting for server down", Assert.assertTrue("waiting for server down",
ClientBase.waitForServerDown(HOSTPORT, ClientBase.waitForServerDown(HOSTPORT,
CONNECTION_TIMEOUT)); CONNECTION_TIMEOUT));
...@@ -142,6 +143,7 @@ public class RecoveryTest extends ZKTestCase implements Watcher { ...@@ -142,6 +143,7 @@ public class RecoveryTest extends ZKTestCase implements Watcher {
} }
} }
f.shutdown(); f.shutdown();
zks.shutdown();
Assert.assertTrue("waiting for server down", Assert.assertTrue("waiting for server down",
ClientBase.waitForServerDown(HOSTPORT, ClientBase.waitForServerDown(HOSTPORT,
...@@ -181,6 +183,7 @@ public class RecoveryTest extends ZKTestCase implements Watcher { ...@@ -181,6 +183,7 @@ public class RecoveryTest extends ZKTestCase implements Watcher {
zk.close(); zk.close();
f.shutdown(); f.shutdown();
zks.shutdown();
Assert.assertTrue("waiting for server down", Assert.assertTrue("waiting for server down",
ClientBase.waitForServerDown(HOSTPORT, ClientBase.waitForServerDown(HOSTPORT,
......
...@@ -60,6 +60,7 @@ public class RepeatStartupTest extends ZKTestCase { ...@@ -60,6 +60,7 @@ public class RepeatStartupTest extends ZKTestCase {
ClientBase.waitForServerUp("127.0.0.1:" + PORT, ClientBase.waitForServerUp("127.0.0.1:" + PORT,
QuorumTest.CONNECTION_TIMEOUT)); QuorumTest.CONNECTION_TIMEOUT));
factory.shutdown(); factory.shutdown();
zks.shutdown();
Assert.assertTrue("waiting for server down", Assert.assertTrue("waiting for server down",
ClientBase.waitForServerDown("127.0.0.1:" + PORT, ClientBase.waitForServerDown("127.0.0.1:" + PORT,
QuorumTest.CONNECTION_TIMEOUT)); QuorumTest.CONNECTION_TIMEOUT));
......
...@@ -70,6 +70,7 @@ public class RestoreCommittedLogTest extends ZKTestCase implements Watcher { ...@@ -70,6 +70,7 @@ public class RestoreCommittedLogTest extends ZKTestCase implements Watcher {
zk.close(); zk.close();
} }
f.shutdown(); f.shutdown();
zks.shutdown();
Assert.assertTrue("waiting for server to shutdown", Assert.assertTrue("waiting for server to shutdown",
ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT)); ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
...@@ -80,6 +81,7 @@ public class RestoreCommittedLogTest extends ZKTestCase implements Watcher { ...@@ -80,6 +81,7 @@ public class RestoreCommittedLogTest extends ZKTestCase implements Watcher {
int logsize = committedLog.size(); int logsize = committedLog.size();
LOG.info("committedLog size = " + logsize); LOG.info("committedLog size = " + logsize);
Assert.assertTrue("log size != 0", (logsize != 0)); Assert.assertTrue("log size != 0", (logsize != 0));
zks.shutdown();
} }
public void process(WatchedEvent event) { public void process(WatchedEvent event) {
......
...@@ -57,6 +57,7 @@ public class SessionTest extends ZKTestCase { ...@@ -57,6 +57,7 @@ public class SessionTest extends ZKTestCase {
PortAssignment.unique(); PortAssignment.unique();
private ServerCnxnFactory serverFactory; private ServerCnxnFactory serverFactory;
private ZooKeeperServer zs;
private CountDownLatch startSignal; private CountDownLatch startSignal;
...@@ -71,7 +72,7 @@ public class SessionTest extends ZKTestCase { ...@@ -71,7 +72,7 @@ public class SessionTest extends ZKTestCase {
} }
ClientBase.setupTestEnv(); 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]); final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
serverFactory = ServerCnxnFactory.createFactory(PORT, -1); serverFactory = ServerCnxnFactory.createFactory(PORT, -1);
...@@ -85,6 +86,7 @@ public class SessionTest extends ZKTestCase { ...@@ -85,6 +86,7 @@ public class SessionTest extends ZKTestCase {
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
serverFactory.shutdown(); serverFactory.shutdown();
zs.shutdown();
Assert.assertTrue("waiting for server down", Assert.assertTrue("waiting for server down",
ClientBase.waitForServerDown(HOSTPORT, ClientBase.waitForServerDown(HOSTPORT,
CONNECTION_TIMEOUT)); 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