diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java b/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java index a634f02c73b..71648c595f2 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java +++ b/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java @@ -121,7 +121,7 @@ public final class TestUtil { private static LinkedHashSet rm(LinkedHashSet unremoved, File... locations) { for (File location : locations) { - if (location.exists()) { + if (location != null && location.exists()) { if (location.isDirectory()) { rm(unremoved, location.listFiles()); } diff --git a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestSolrEntityProcessorEndToEnd.java b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestSolrEntityProcessorEndToEnd.java index d7f36782e61..c1d233e886d 100644 --- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestSolrEntityProcessorEndToEnd.java +++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestSolrEntityProcessorEndToEnd.java @@ -26,6 +26,7 @@ import java.util.Map; import java.util.Map.Entry; import org.apache.commons.io.FileUtils; +import org.apache.lucene.util.TestUtil; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.embedded.JettySolrRunner; import org.apache.solr.client.solrj.impl.HttpSolrServer; @@ -291,7 +292,6 @@ public class TestSolrEntityProcessorEndToEnd extends AbstractDataImportHandlerTe } private static class SolrInstance { - File homeDir; File confDir; @@ -316,8 +316,7 @@ public class TestSolrEntityProcessorEndToEnd extends AbstractDataImportHandlerTe } public void setUp() throws Exception { - String home = createTempDir().getAbsolutePath(); - homeDir = new File(home + "inst"); + homeDir = createTempDir(); initCoreDataDir = new File(homeDir + "/collection1", "data"); confDir = new File(homeDir + "/collection1", "conf"); @@ -334,11 +333,10 @@ public class TestSolrEntityProcessorEndToEnd extends AbstractDataImportHandlerTe f = new File(confDir, "data-config.xml"); FileUtils.copyFile(getFile(SOURCE_CONF_DIR + "dataconfig-contentstream.xml"), f); } - + public void tearDown() throws Exception { - recurseDelete(homeDir); + TestUtil.rm(homeDir); } - } private JettySolrRunner createJetty(SolrInstance instance) throws Exception { diff --git a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java index 18df162669e..58693ee8ef7 100644 --- a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java +++ b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java @@ -26,6 +26,7 @@ import java.util.regex.Pattern; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.BasicResponseHandler; +import org.apache.lucene.util.TestUtil; import org.apache.solr.SolrTestCaseJ4.SuppressSSL; import org.apache.solr.client.solrj.SolrQuery; import org.apache.solr.client.solrj.SolrServer; @@ -487,7 +488,7 @@ public class BasicDistributedZk2Test extends AbstractFullDistribZkTestBase { assertEquals(Arrays.asList(files).toString(), 1, files.length); File snapDir = files[0]; - AbstractSolrTestCase.recurseDelete(snapDir); // clean up the snap dir + TestUtil.rm(snapDir); } private void addNewReplica() throws Exception { diff --git a/solr/core/src/test/org/apache/solr/cloud/SolrXmlInZkTest.java b/solr/core/src/test/org/apache/solr/cloud/SolrXmlInZkTest.java index 45f05b0eb4b..de2dca7fef6 100644 --- a/solr/core/src/test/org/apache/solr/cloud/SolrXmlInZkTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/SolrXmlInZkTest.java @@ -59,7 +59,6 @@ public class SolrXmlInZkTest extends SolrTestCaseJ4 { private void setUpZkAndDiskXml(boolean toZk, boolean leaveOnLocal) throws Exception { File tmpDir = createTempDir(); - recurseDelete(tmpDir); File solrHome = new File(tmpDir, "home"); copyMinConf(new File(solrHome, "myCollect")); if (leaveOnLocal) { diff --git a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java index 198dd9ff252..524eba52354 100644 --- a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java +++ b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java @@ -33,6 +33,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Date; +import java.util.List; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -1549,11 +1550,9 @@ public class TestReplicationHandler extends SolrTestCaseJ4 { fail(deleteBackupThread.fail); } } - }finally { - for (File dir : snapDir) if(dir !=null) AbstractSolrTestCase.recurseDelete(dir); + } finally { + TestUtil.rm(snapDir); } - - } /* character copy of file using UTF-8 */ @@ -1703,7 +1702,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 { } public void tearDown() throws Exception { - AbstractSolrTestCase.recurseDelete(homeDir.getParentFile()); + TestUtil.rm(homeDir); } public void copyConfigFile(String srcFile, String destFile) diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrServer.java b/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrServer.java index dc7f82bb3b5..d77cc171942 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrServer.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrServer.java @@ -302,11 +302,8 @@ public class TestLBHttpSolrServer extends SolrTestCaseJ4 { } public void tearDown() throws Exception { - try { - jetty.stop(); - } catch (Exception e) { - } - AbstractSolrTestCase.recurseDelete(homeDir); + if (jetty != null) jetty.stop(); + TestUtil.rm(homeDir); } public void startJetty() throws Exception { diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java index ac81050ac94..c1833b78763 100644 --- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java +++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java @@ -1012,17 +1012,18 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase { public String toString() { return xml; } } + /** + * @see TestUtil#rm(File...) + */ + @Deprecated() public static boolean recurseDelete(File f) { - if(f == null || !f.exists()) return false; - if (f.isDirectory()) { - for (File sub : f.listFiles()) { - if (!recurseDelete(sub)) { - System.err.println("!!!! WARNING: best effort to remove " + sub.getAbsolutePath() + " FAILED !!!!!"); - return false; - } - } + try { + TestUtil.rm(f); + return true; + } catch (IOException e) { + System.err.println(e.toString()); + return false; } - return f.delete(); } public void clearIndex() {