mirror of https://github.com/apache/lucene.git
Clean up SolrTestCaseJ4.recurseDelete a bit and remove hairy cases of removing the parent file in certain tests.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1598012 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3d703a16e9
commit
4c29d60c62
|
@ -121,7 +121,7 @@ public final class TestUtil {
|
|||
|
||||
private static LinkedHashSet<File> rm(LinkedHashSet<File> unremoved, File... locations) {
|
||||
for (File location : locations) {
|
||||
if (location.exists()) {
|
||||
if (location != null && location.exists()) {
|
||||
if (location.isDirectory()) {
|
||||
rm(unremoved, location.listFiles());
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue