mirror of https://github.com/apache/lucene.git
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:
parent
d3fa5ea86e
commit
5a020a48d2
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue