change test so that even if there is an exception in the ClientThread constructor, the zkclient is closed

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1236956 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2012-01-28 02:03:29 +00:00
parent d3fa5ea86e
commit 5a020a48d2
1 changed files with 14 additions and 7 deletions

View File

@ -55,8 +55,7 @@ public class LeaderElectionTest extends SolrTestCaseJ4 {
@AfterClass
public static void afterClass() throws InterruptedException {
// wait just a bit for any zk client threads to outlast timeout
Thread.sleep(2000);
}
@Override
@ -87,10 +86,18 @@ public class LeaderElectionTest extends SolrTestCaseJ4 {
public ClientThread(int nodeNumber) throws Exception {
super("Thread-" + nodeNumber);
boolean created = false;
this.zkClient = new SolrZkClient(server.getZkAddress(), TIMEOUT);
this.zkStateReader = new ZkStateReader(zkClient);
this.nodeNumber = nodeNumber;
props = new ZkNodeProps(ZkStateReader.BASE_URL_PROP, Integer.toString(nodeNumber), ZkStateReader.CORE_NAME_PROP, "");
try {
this.zkStateReader = new ZkStateReader(zkClient);
this.nodeNumber = nodeNumber;
props = new ZkNodeProps(ZkStateReader.BASE_URL_PROP, Integer.toString(nodeNumber), ZkStateReader.CORE_NAME_PROP, "");
created = true;
} finally {
if (!created) {
zkClient.close();
}
}
}
@Override
@ -371,11 +378,11 @@ public class LeaderElectionTest extends SolrTestCaseJ4 {
killThread.interrupt();
scheduleThread.join();
scheduler.shutdownNow();
connLossThread.join();
killThread.join();
scheduler.shutdownNow();
int seq = threads.get(getLeaderThread()).getSeq();
assertFalse("seq is -1 and we may have a zombie leader", seq == -1);