SOLR-13074: clean up static variables properly, avoiding NPEs.

This commit is contained in:
Dawid Weiss 2018-12-18 23:20:55 +01:00
parent f28c5bec9b
commit 71f024ac8f
1 changed files with 26 additions and 9 deletions

View File

@ -16,11 +16,14 @@
*/
package org.apache.solr.cloud;
import java.io.IOException;
import com.carrotsearch.randomizedtesting.ThreadFilter;
import com.carrotsearch.randomizedtesting.annotations.Nightly;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
import com.carrotsearch.randomizedtesting.annotations.TimeoutSuite;
import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.LuceneTestCase.AwaitsFix;
import org.apache.lucene.util.TimeUnits;
import org.apache.solr.cloud.hdfs.HdfsTestUtil;
@ -57,9 +60,27 @@ public class MoveReplicaHDFSTest extends MoveReplicaTest {
@AfterClass
public static void teardownClass() throws Exception {
cluster.shutdown(); // need to close before the MiniDFSCluster
HdfsTestUtil.teardownClass(dfsCluster);
dfsCluster = null;
try {
IOUtils.close(
() -> {
try {
if (cluster != null) cluster.shutdown();
} catch (Exception e) {
throw new IOException("Could not shut down the cluster.", e);
}
},
() -> {
try {
if (dfsCluster != null) HdfsTestUtil.teardownClass(dfsCluster);
} catch (Exception e) {
throw new IOException("Could not shut down dfs cluster.", e);
}
}
);
} finally {
cluster = null;
dfsCluster = null;
}
}
@Test
@ -89,15 +110,11 @@ public class MoveReplicaHDFSTest extends MoveReplicaTest {
}
public static class ForkJoinThreadsFilter implements ThreadFilter {
@Override
public boolean reject(Thread t) {
String name = t.getName();
if (name.startsWith("ForkJoinPool.commonPool")) {
return true;
}
return false;
return name.startsWith("ForkJoinPool.commonPool");
}
}
}