SOLR-5914: Polish up createTempDir calls.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/solr5914@1583163 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2014-03-30 17:37:31 +00:00
parent 64ad96afb1
commit 6bf76b1015
46 changed files with 100 additions and 287 deletions

View File

@ -16,13 +16,11 @@ import java.util.Locale;
import java.util.Map;
import java.util.Set;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.TestUtil;
import junit.framework.Assert;
import org.junit.After;
import org.junit.Before;
import junit.framework.Assert;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with

View File

@ -58,11 +58,6 @@ public class TestNonWritablePersistFile extends AbstractDataImportHandlerTestCas
new File(tmpSolrHome).getAbsolutePath());
}
@AfterClass
public static void destroyTempSolrHomeAndCore() throws Exception {
FileUtils.deleteDirectory(new File(tmpSolrHome).getAbsoluteFile());
}
@Test
@SuppressWarnings("unchecked")
public void testNonWritablePersistFile() throws Exception {

View File

@ -43,21 +43,10 @@ public class TestSimplePropertiesWriter extends AbstractDIHJdbcTestCase {
@Before
public void spwBefore() throws Exception {
File tmpdir = File.createTempFile("test", "tmp", createTempDir());
tmpdir.delete();
tmpdir.mkdir();
fileLocation = tmpdir.getPath();
fileLocation = createTempDir().getAbsolutePath();
fileName = "the.properties";
}
@After
public void spwAfter() throws Exception {
//If an Assume was tripped while setting up the test,
//the file might not ever have been created...
if(fileLocation!=null) {
new File(fileLocation + File.separatorChar + fileName).delete();
new File(fileLocation).delete();
}
}
@Test
public void testSimplePropertiesWriter() throws Exception {

View File

@ -331,9 +331,7 @@ public class TestXPathEntityProcessor extends AbstractDataImportHandlerTestCase
@Test
public void withDefaultSolrAndXsl() throws Exception {
File tmpdir = File.createTempFile("test", "tmp", createTempDir());
tmpdir.delete();
tmpdir.mkdir();
File tmpdir = createTempDir();
AbstractDataImportHandlerTestCase.createFile(tmpdir, "x.xsl", xsl.getBytes("UTF-8"),
false);

View File

@ -17,7 +17,6 @@ package org.apache.solr.handler.dataimport;
* limitations under the License.
*/
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
@ -50,8 +49,7 @@ public class TestZKPropertiesWriter extends AbstractDataImportHandlerTestCase {
@BeforeClass
public static void dihZk_beforeClass() throws Exception {
zkDir = createTempDir().getAbsolutePath() + File.separator
+ "zookeeper/server1/data";
zkDir = createTempDir("zkData").getAbsolutePath();
zkServer = new ZkTestServer(zkDir);
zkServer.run();

View File

@ -311,15 +311,6 @@ public class EditFileRequestHandler extends RequestHandlerBase {
rsp.setException(new SolrException(ErrorCode.SERVER_ERROR,
"Caught IO exception when trying to verify configs. " + ex.getMessage()));
return false;
} finally {
if (home != null) {
try {
FileUtils.deleteDirectory(home);
} catch (IOException e) {
log.warn("Caught IO exception trying to delete temporary directory " + home + e.getMessage());
return true; // Don't fail for this reason!
}
}
}
}

View File

@ -49,7 +49,7 @@ public class AnalysisAfterCoreReloadTest extends SolrTestCaseJ4 {
@AfterClass
public static void AfterClass() throws Exception {
FileUtils.deleteDirectory(new File(tmpSolrHome).getAbsoluteFile());
}
public void testStopwordsAfterCoreReload() throws Exception {

View File

@ -51,7 +51,7 @@ public class SolrTestCaseJ4Test extends SolrTestCaseJ4 {
@AfterClass
public static void AfterClass() throws Exception {
FileUtils.deleteDirectory(new File(tmpSolrHome).getAbsoluteFile());
}
@Test

View File

@ -73,12 +73,9 @@ public class ClusterStateUpdateTest extends SolrTestCaseJ4 {
@BeforeClass
public static void beforeClass() throws IOException {
solrHomeDirectory = new File(createTempDir(), "ZkControllerTest");
solrHomeDirectory = createTempDir();
System.setProperty("solrcloud.skip.autorecovery", "true");
System.setProperty("genericCoreNodeNames", "false");
if (solrHomeDirectory.exists()) {
FileUtils.deleteDirectory(solrHomeDirectory);
}
copyMinFullSetup(solrHomeDirectory);
}
@ -87,9 +84,6 @@ public class ClusterStateUpdateTest extends SolrTestCaseJ4 {
public static void afterClass() throws InterruptedException, IOException {
System.clearProperty("solrcloud.skip.autorecovery");
System.clearProperty("genericCoreNodeNames");
if (solrHomeDirectory.exists()) {
FileUtils.deleteDirectory(solrHomeDirectory);
}
}
@ -97,9 +91,8 @@ public class ClusterStateUpdateTest extends SolrTestCaseJ4 {
public void setUp() throws Exception {
super.setUp();
System.setProperty("zkClientTimeout", "3000");
File tmpDir = createTempDir();
zkDir = tmpDir.getAbsolutePath() + File.separator
+ "zookeeper/server1/data";
File tmpDir = createTempDir("zkData");
zkDir = tmpDir.getAbsolutePath();
zkServer = new ZkTestServer(zkDir);
zkServer.run();
System.setProperty("zkHost", zkServer.getZkAddress());

View File

@ -37,8 +37,7 @@ public class ConnectionManagerTest extends SolrTestCaseJ4 {
public void testConnectionManager() throws Exception {
// setup a SolrZkClient to do some getBaseUrlForNodeName testing
String zkDir = createTempDir().getAbsolutePath() + File.separator
+ "zookeeper/server1/data";
String zkDir = createTempDir("zkData").getAbsolutePath();
ZkTestServer server = new ZkTestServer(zkDir);
try {
@ -72,8 +71,7 @@ public class ConnectionManagerTest extends SolrTestCaseJ4 {
public void testLikelyExpired() throws Exception {
// setup a SolrZkClient to do some getBaseUrlForNodeName testing
String zkDir = createTempDir().getAbsolutePath() + File.separator
+ "zookeeper/server1/data";
String zkDir = createTempDir("zkData").getAbsolutePath();
ZkTestServer server = new ZkTestServer(zkDir);
try {

View File

@ -79,8 +79,7 @@ public class LeaderElectionIntegrationTest extends SolrTestCaseJ4 {
System.setProperty("zkClientTimeout", "8000");
zkDir = createTempDir().getAbsolutePath() + File.separator
+ "zookeeper/server1/data";
zkDir = createTempDir("zkData").getAbsolutePath();
zkServer = new ZkTestServer(zkDir);
zkServer.run();
System.setProperty("zkHost", zkServer.getZkAddress());

View File

@ -66,8 +66,7 @@ public class LeaderElectionTest extends SolrTestCaseJ4 {
@Override
public void setUp() throws Exception {
super.setUp();
String zkDir = createTempDir().getAbsolutePath() + File.separator
+ "zookeeper/server1/data";
String zkDir = createTempDir("zkData").getAbsolutePath();;
server = new ZkTestServer(zkDir);
server.setTheTickTime(1000);

View File

@ -203,8 +203,7 @@ public class OverseerTest extends SolrTestCaseJ4 {
@Test
public void testShardAssignment() throws Exception {
String zkDir = createTempDir().getAbsolutePath() + File.separator
+ "zookeeper/server1/data";
String zkDir = createTempDir("zkData").getAbsolutePath();
ZkTestServer server = new ZkTestServer(zkDir);
@ -259,8 +258,7 @@ public class OverseerTest extends SolrTestCaseJ4 {
@Test
public void testBadQueueItem() throws Exception {
String zkDir = createTempDir().getAbsolutePath() + File.separator
+ "zookeeper/server1/data";
String zkDir = createTempDir("zkData").getAbsolutePath();
ZkTestServer server = new ZkTestServer(zkDir);
@ -334,8 +332,7 @@ public class OverseerTest extends SolrTestCaseJ4 {
@Test
public void testShardAssignmentBigger() throws Exception {
String zkDir = createTempDir().getAbsolutePath() + File.separator
+ "zookeeper/server1/data";
String zkDir = createTempDir("zkData").getAbsolutePath();
final int nodeCount = random().nextInt(50)+50; //how many simulated nodes (num of threads)
final int coreCount = random().nextInt(100)+100; //how many cores to register
@ -505,8 +502,7 @@ public class OverseerTest extends SolrTestCaseJ4 {
@Test
public void testStateChange() throws Exception {
String zkDir = createTempDir().getAbsolutePath() + File.separator
+ "zookeeper/server1/data";
String zkDir = createTempDir("zkData").getAbsolutePath();
ZkTestServer server = new ZkTestServer(zkDir);
@ -602,8 +598,7 @@ public class OverseerTest extends SolrTestCaseJ4 {
@Test
public void testOverseerFailure() throws Exception {
String zkDir = createTempDir().getAbsolutePath() + File.separator
+ "zookeeper/server1/data";
String zkDir = createTempDir("zkData").getAbsolutePath();
ZkTestServer server = new ZkTestServer(zkDir);
@ -725,8 +720,7 @@ public class OverseerTest extends SolrTestCaseJ4 {
@Test
public void testShardLeaderChange() throws Exception {
String zkDir = createTempDir().getAbsolutePath() + File.separator
+ "zookeeper/server1/data";
String zkDir = createTempDir("zkData").getAbsolutePath();
final ZkTestServer server = new ZkTestServer(zkDir);
SolrZkClient controllerClient = null;
ZkStateReader reader = null;
@ -781,8 +775,7 @@ public class OverseerTest extends SolrTestCaseJ4 {
@Test
public void testDoubleAssignment() throws Exception {
String zkDir = createTempDir().getAbsolutePath() + File.separator
+ "zookeeper/server1/data";
String zkDir = createTempDir("zkData").getAbsolutePath();
ZkTestServer server = new ZkTestServer(zkDir);
@ -846,8 +839,7 @@ public class OverseerTest extends SolrTestCaseJ4 {
@Test
public void testPlaceholders() throws Exception {
String zkDir = createTempDir().getAbsolutePath() + File.separator
+ "zookeeper/server1/data";
String zkDir = createTempDir("zkData").getAbsolutePath();
ZkTestServer server = new ZkTestServer(zkDir);

View File

@ -77,8 +77,7 @@ public class SliceStateUpdateTest extends SolrTestCaseJ4 {
System.setProperty("zkClientTimeout", "3000");
zkDir = createTempDir().getAbsolutePath() + File.separator
+ "zookeeper/server1/data";
zkDir = createTempDir("zkData").getAbsolutePath();
zkServer = new ZkTestServer(zkDir);
zkServer.run();
System.setProperty("zkHost", zkServer.getZkAddress());
@ -99,9 +98,9 @@ public class SliceStateUpdateTest extends SolrTestCaseJ4 {
CreateMode.PERSISTENT, true);
zkClient.close();
dataDir1 = new File(createTempDir() + File.separator + "data1");
dataDir1 = createTempDir("data1");
dataDir2 = new File(createTempDir() + File.separator + "data2");
dataDir2 = createTempDir("data2");
// set some system properties for use by tests
System.setProperty("solr.test.sys.prop1", "propone");

View File

@ -43,8 +43,7 @@ public class TestZkChroot extends SolrTestCaseJ4 {
public void setUp() throws Exception {
super.setUp();
zkDir = createTempDir().getAbsolutePath() + File.separator
+ "zookeeper/server1/data";
zkDir = createTempDir("zkData").getAbsolutePath();
zkServer = new ZkTestServer(zkDir);
zkServer.run();
home = ExternalPaths.EXAMPLE_HOME;

View File

@ -81,8 +81,7 @@ public class ZkControllerTest extends SolrTestCaseJ4 {
ZkController.generateNodeName("foo-bar", "77", "/solr/sub_dir/"));
// setup a SolrZkClient to do some getBaseUrlForNodeName testing
String zkDir = createTempDir().getAbsolutePath() + File.separator
+ "zookeeper/server1/data";
String zkDir = createTempDir("zkData").getAbsolutePath();
ZkTestServer server = new ZkTestServer(zkDir);
try {
@ -152,8 +151,7 @@ public class ZkControllerTest extends SolrTestCaseJ4 {
@Test
public void testReadConfigName() throws Exception {
String zkDir = createTempDir().getAbsolutePath() + File.separator
+ "zookeeper/server1/data";
String zkDir = createTempDir("zkData").getAbsolutePath();
CoreContainer cc = null;
ZkTestServer server = new ZkTestServer(zkDir);
@ -208,8 +206,7 @@ public class ZkControllerTest extends SolrTestCaseJ4 {
@Test
public void testUploadToCloud() throws Exception {
String zkDir = createTempDir().getAbsolutePath() + File.separator
+ "zookeeper/server1/data";
String zkDir = createTempDir("zkData").getAbsolutePath();
ZkTestServer server = new ZkTestServer(zkDir);
ZkController zkController = null;
@ -261,8 +258,7 @@ public class ZkControllerTest extends SolrTestCaseJ4 {
@Test
public void testGetHostName() throws Exception {
String zkDir = createTempDir().getAbsolutePath() + File.separator
+ "zookeeper/server1/data";
String zkDir = createTempDir("zkData").getAbsolutePath();
CoreContainer cc = null;
ZkTestServer server = new ZkTestServer(zkDir);

View File

@ -40,8 +40,7 @@ public class ZkSolrClientTest extends AbstractSolrTestCase {
}
public void testConnect() throws Exception {
String zkDir = createTempDir().getAbsolutePath() + File.separator
+ "zookeeper/server1/data";
String zkDir = createTempDir("zkData").getAbsolutePath();
ZkTestServer server = null;
server = new ZkTestServer(zkDir);
@ -54,8 +53,7 @@ public class ZkSolrClientTest extends AbstractSolrTestCase {
}
public void testMakeRootNode() throws Exception {
String zkDir = createTempDir().getAbsolutePath() + File.separator
+ "zookeeper/server1/data";
String zkDir = createTempDir("zkData").getAbsolutePath();
ZkTestServer server = null;
server = new ZkTestServer(zkDir);
@ -73,8 +71,7 @@ public class ZkSolrClientTest extends AbstractSolrTestCase {
}
public void testClean() throws Exception {
String zkDir = createTempDir().getAbsolutePath() + File.separator
+ "zookeeper/server1/data";
String zkDir = createTempDir("zkData").getAbsolutePath();
ZkTestServer server = null;
server = new ZkTestServer(zkDir);
@ -99,8 +96,7 @@ public class ZkSolrClientTest extends AbstractSolrTestCase {
}
public void testReconnect() throws Exception {
String zkDir = createTempDir().getAbsolutePath() + File.separator
+ "zookeeper/server1/data";
String zkDir = createTempDir("zkData").getAbsolutePath();
ZkTestServer server = null;
SolrZkClient zkClient = null;
try {
@ -193,8 +189,7 @@ public class ZkSolrClientTest extends AbstractSolrTestCase {
}
public void testWatchChildren() throws Exception {
String zkDir = createTempDir().getAbsolutePath() + File.separator
+ "zookeeper/server1/data";
String zkDir = createTempDir("zkData").getAbsolutePath();
final AtomicInteger cnt = new AtomicInteger();
ZkTestServer server = new ZkTestServer(zkDir);

View File

@ -45,12 +45,7 @@ public class CoreContainerCoreInitFailuresTest extends SolrTestCaseJ4 {
cc = null;
}
if (null != solrHome) {
if (solrHome.exists()) {
FileUtils.deleteDirectory(solrHome);
}
solrHome = null;
}
solrHome = null;
}
public void testFlowWithEmpty() throws Exception {

View File

@ -86,7 +86,6 @@ public class OpenCloseCoreStressTest extends SolrTestCaseJ4 {
cumulativeDocs = 0;
solrHomeDirectory = createTempDir();
FileUtils.deleteDirectory(solrHomeDirectory); // Ensure that a failed test didn't leave something lying around.
jetty = new JettySolrRunner(solrHomeDirectory.getAbsolutePath(), "/solr", 0, null, null, true, null, sslConfig);
}
@ -94,7 +93,6 @@ public class OpenCloseCoreStressTest extends SolrTestCaseJ4 {
@After
public void tearDownServer() throws Exception {
if (jetty != null) jetty.stop();
FileUtils.deleteDirectory(solrHomeDirectory);
for(SolrServer server:indexingServers) {
server.shutdown();
}

View File

@ -40,7 +40,7 @@ public class SolrCoreCheckLockOnStartupTest extends SolrTestCaseJ4 {
System.setProperty("solr.directoryFactory", "org.apache.solr.core.SimpleFSDirectoryFactory");
IndexWriterConfig indexWriterConfig = new IndexWriterConfig(TEST_VERSION_CURRENT, null);
Directory directory = newFSDirectory(new File(createTempDir(), "index"));
Directory directory = newFSDirectory(createTempDir("index"));
//creates a new index on the known location
new IndexWriter(
directory,

View File

@ -33,8 +33,6 @@ import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.TestUtil;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.handler.SnapPuller;

View File

@ -41,9 +41,8 @@ public class TestConfigSets extends SolrTestCaseJ4 {
public static String solrxml = "<solr><str name=\"configSetBaseDir\">${configsets:configsets}</str></solr>";
public CoreContainer setupContainer(String testName, String configSetsBaseDir) {
File testDirectory = new File(createTempDir(), testName);
testDirectory.mkdirs();
public CoreContainer setupContainer(String configSetsBaseDir) {
File testDirectory = createTempDir();
System.setProperty("configsets", configSetsBaseDir);
@ -58,7 +57,7 @@ public class TestConfigSets extends SolrTestCaseJ4 {
public void testConfigSetServiceFindsConfigSets() {
CoreContainer container = null;
try {
container = setupContainer("findsConfigSets", getFile("solr/configsets").getAbsolutePath());
container = setupContainer(getFile("solr/configsets").getAbsolutePath());
String testDirectory = container.getResourceLoader().getInstanceDir();
SolrCore core1 = container.create("core1", testDirectory + "/core1", "configSet", "configset-2");
@ -77,7 +76,7 @@ public class TestConfigSets extends SolrTestCaseJ4 {
public void testNonExistentConfigSetThrowsException() {
CoreContainer container = null;
try {
container = setupContainer("badConfigSet", getFile("solr/configsets").getAbsolutePath());
container = setupContainer(getFile("solr/configsets").getAbsolutePath());
String testDirectory = container.getResourceLoader().getInstanceDir();
container.create("core1", testDirectory + "/core1", "configSet", "nonexistent");

View File

@ -34,7 +34,6 @@ import javax.xml.parsers.ParserConfigurationException;
import org.apache.commons.io.FileUtils;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.handler.admin.CollectionsHandler;
@ -184,7 +183,6 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
assertNull(ret);
} finally {
cores.shutdown();
FileUtils.deleteDirectory(solrHomeDirectory);
}
}
@ -194,22 +192,15 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
assertNotNull(h.getCoreContainer().getLogging());
}
private void SetUpHome(File solrHomeDirectory, String xmlFile) throws IOException {
if (solrHomeDirectory.exists()) {
FileUtils.deleteDirectory(solrHomeDirectory);
}
assertTrue("Failed to mkdirs workDir", solrHomeDirectory.mkdirs());
try {
File solrXmlFile = new File(solrHomeDirectory, "solr.xml");
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(solrXmlFile), IOUtils.CHARSET_UTF_8));
out.write(xmlFile);
out.close();
} catch (IOException e) {
FileUtils.deleteDirectory(solrHomeDirectory);
throw e;
}
private void SetUpHome(File solrHomeDirectory, String xmlFile)
throws IOException {
File solrXmlFile = new File(solrHomeDirectory, "solr.xml");
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(solrXmlFile), IOUtils.CHARSET_UTF_8));
out.write(xmlFile);
out.close();
//init
// init
System.setProperty(SOLR_HOME_PROP, solrHomeDirectory.getAbsolutePath());
}

View File

@ -110,9 +110,7 @@ public class TestCoreDiscovery extends SolrTestCaseJ4 {
@After
public void after() throws Exception {
if (solrHomeDirectory.exists()) {
FileUtils.deleteDirectory(solrHomeDirectory);
}
}
// Test the basic setup, create some dirs with core.properties files in them, but solr.xml has discoverCores
@ -208,12 +206,11 @@ public class TestCoreDiscovery extends SolrTestCaseJ4 {
assertNotNull(core2);
} finally {
cc.shutdown();
if (alt.exists()) FileUtils.deleteDirectory(alt);
}
}
@Test
public void testNoCoreDir() throws Exception {
File noCoreDir = new File(createTempDir(), "noCoreDir");
File noCoreDir = createTempDir();
setMeUp(noCoreDir.getAbsolutePath());
addCoreWithProps(makeCorePropFile("core1", false, true),
new File(noCoreDir, "core1" + File.separator + CorePropertiesLocator.PROPERTIES_FILENAME));
@ -226,7 +223,6 @@ public class TestCoreDiscovery extends SolrTestCaseJ4 {
assertNotNull(core2);
} finally {
cc.shutdown();
if (noCoreDir.exists()) FileUtils.deleteDirectory(noCoreDir);
}
}
// For testing whether finding a solr.xml overrides looking at solr.properties

View File

@ -98,9 +98,6 @@ public class TestSolrXmlPersistence extends SolrTestCaseJ4 {
origMatchesPersist(cc, SOLR_XML_LOTS_SYSVARS);
} finally {
cc.shutdown();
if (solrHomeDirectory.exists()) {
FileUtils.deleteDirectory(solrHomeDirectory);
}
}
}
@ -259,9 +256,6 @@ public class TestSolrXmlPersistence extends SolrTestCaseJ4 {
origMatchesPersist(cc, SOLR_XML_MINIMAL);
} finally {
cc.shutdown();
if (solrHomeDirectory.exists()) {
FileUtils.deleteDirectory(solrHomeDirectory);
}
}
}
@ -399,10 +393,6 @@ public class TestSolrXmlPersistence extends SolrTestCaseJ4 {
} finally {
cc.shutdown();
if (solrHomeDirectory.exists()) {
FileUtils.deleteDirectory(solrHomeDirectory);
}
}
}

View File

@ -64,30 +64,21 @@ public class TestSolrXmlPersistor extends SolrTestCaseJ4 {
final File solrHomeDirectory = createTempDir();
try {
if (solrHomeDirectory.exists()) {
FileUtils.deleteDirectory(solrHomeDirectory);
}
copyMinFullSetup(solrHomeDirectory);
copyMinFullSetup(solrHomeDirectory);
CoreContainer cc = new CoreContainer(solrHomeDirectory.getAbsolutePath());
CoreContainer cc = new CoreContainer(solrHomeDirectory.getAbsolutePath());
final CoreDescriptor cd = new CoreDescriptor(cc, "testcore", "instance/dir/");
List<CoreDescriptor> cds = ImmutableList.of(cd);
final CoreDescriptor cd = new CoreDescriptor(cc, "testcore",
"instance/dir/");
List<CoreDescriptor> cds = ImmutableList.of(cd);
SolrXMLCoresLocator persistor = new SolrXMLCoresLocator(solrxml, null);
String xml = persistor.buildSolrXML(cds);
SolrXMLCoresLocator persistor = new SolrXMLCoresLocator(solrxml, null);
String xml = persistor.buildSolrXML(cds);
assertTrue(xml.contains("<solr><cores>"));
assertTrue(xml.contains("name=\"testcore\""));
assertTrue(xml.contains("instanceDir=\"instance/dir/\""));
assertTrue(xml.contains("</cores></solr>"));
} finally {
if (solrHomeDirectory.exists()) {
FileUtils.deleteDirectory(solrHomeDirectory);
}
}
assertTrue(xml.contains("<solr><cores>"));
assertTrue(xml.contains("name=\"testcore\""));
assertTrue(xml.contains("instanceDir=\"instance/dir/\""));
assertTrue(xml.contains("</cores></solr>"));
}
@Test

View File

@ -50,10 +50,6 @@ public class CoreAdminCreateDiscoverTest extends SolrTestCaseJ4 {
useFactory(null); // I require FS-based indexes for this test.
solrHomeDirectory = createTempDir();
if (solrHomeDirectory.exists()) {
FileUtils.deleteDirectory(solrHomeDirectory);
}
assertTrue("Failed to mkdirs workDir", solrHomeDirectory.mkdirs());
setupNoCoreTest(solrHomeDirectory, null);
@ -63,9 +59,6 @@ public class CoreAdminCreateDiscoverTest extends SolrTestCaseJ4 {
@AfterClass
public static void afterClass() throws Exception {
admin = null; // Release it or the test harness complains.
if (solrHomeDirectory.exists()) {
FileUtils.deleteDirectory(solrHomeDirectory);
}
}
private static void setupCore(String coreName, boolean blivet) throws IOException {

View File

@ -122,20 +122,11 @@ public class CoreAdminHandlerTest extends SolrTestCaseJ4 {
assertTrue("Should have found index dir at " + test.getAbsolutePath(), test.exists());
test = new File(test,"segments.gen");
assertTrue("Should have found segments.gen at " + test.getAbsolutePath(), test.exists());
// Cleanup
FileUtils.deleteDirectory(workDir);
}
@Test
public void testCoreAdminHandler() throws Exception {
final File workDir = new File(initCoreDataDir, this.getClass().getName());
if (workDir.exists()) {
FileUtils.deleteDirectory(workDir);
}
assertTrue("Failed to mkdirs workDir", workDir.mkdirs());
final File workDir = createTempDir();
final CoreContainer cores = h.getCoreContainer();
@ -214,9 +205,6 @@ public class CoreAdminHandlerTest extends SolrTestCaseJ4 {
// :TODO: because of SOLR-3665 we can't ask for status from all cores
// cleanup
FileUtils.deleteDirectory(workDir);
}
@Test

View File

@ -73,11 +73,6 @@ public class CoreMergeIndexesAdminHandlerTest extends SolrTestCaseJ4 {
public void testMergeIndexesCoreAdminHandler() throws Exception {
final File workDir = createTempDir();
if (workDir.exists()) {
FileUtils.deleteDirectory(workDir);
}
assertTrue("Failed to mkdirs workDir", workDir.mkdirs());
final CoreContainer cores = h.getCoreContainer();
final CoreAdminHandler admin = new CoreAdminHandler(cores);
@ -104,8 +99,5 @@ public class CoreMergeIndexesAdminHandlerTest extends SolrTestCaseJ4 {
}
dirFactory.fail = false;
}
// cleanup
FileUtils.deleteDirectory(workDir);
}
}

View File

@ -49,7 +49,7 @@ public class DistributedDebugComponentTest extends SolrJettyTestBase {
}
private static File createSolrHome() throws Exception {
File workDir = new File(createTempDir(), DistributedDebugComponentTest.class.getName());
File workDir = createTempDir();
setupJettyTestHome(workDir, "collection1");
FileUtils.copyDirectory(new File(workDir, "collection1"), new File(workDir, "collection2"));
return workDir;
@ -57,7 +57,7 @@ public class DistributedDebugComponentTest extends SolrJettyTestBase {
@AfterClass
public static void afterTest() throws Exception {
cleanUpJettyHome(solrHome);
}
@Before

View File

@ -62,7 +62,7 @@ public class TestRemoteStreaming extends SolrJettyTestBase {
@AfterClass
public static void afterTest() throws Exception {
cleanUpJettyHome(solrHomeDirectory);
}
@Before

View File

@ -22,8 +22,6 @@ import java.util.SortedMap;
import java.util.TreeMap;
import org.apache.commons.io.FileUtils;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.TestUtil;
import org.apache.solr.util.RestTestBase;
import org.eclipse.jetty.servlet.ServletHolder;
import org.junit.After;
@ -46,8 +44,7 @@ public class TestManagedStopFilterFactory extends RestTestBase {
@Before
public void before() throws Exception {
tmpSolrHome = new File(createTempDir() + File.separator + TestManagedStopFilterFactory.class.getSimpleName()
+ System.currentTimeMillis());
tmpSolrHome = createTempDir();
tmpConfDir = new File(tmpSolrHome, confDir);
FileUtils.copyDirectory(new File(TEST_HOME()), tmpSolrHome.getAbsoluteFile());
@ -67,7 +64,6 @@ public class TestManagedStopFilterFactory extends RestTestBase {
private void after() throws Exception {
jetty.stop();
jetty = null;
FileUtils.deleteDirectory(tmpSolrHome);
System.clearProperty("managed.schema.mutable");
System.clearProperty("enable.update.log");
}

View File

@ -24,8 +24,6 @@ import java.util.ArrayList;
import org.apache.commons.codec.Charsets;
import org.apache.commons.io.FileUtils;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.util.ContentStream;
@ -54,7 +52,7 @@ public class ModifyConfFileTest extends SolrTestCaseJ4 {
System.setProperty("solr.test.sys.prop1", "propone");
System.setProperty("solr.test.sys.prop2", "proptwo");
solrHomeDirectory = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
solrHomeDirectory = createTempDir();
copySolrHomeToTemp(solrHomeDirectory, "core1", true);
FileUtils.write(new File(new File(solrHomeDirectory, "core1"), "core.properties"), "", Charsets.UTF_8.toString());
@ -148,9 +146,6 @@ public class ModifyConfFileTest extends SolrTestCaseJ4 {
} finally {
cc.shutdown();
if (solrHomeDirectory.exists()) {
FileUtils.deleteDirectory(solrHomeDirectory);
}
}
}

View File

@ -25,8 +25,6 @@ import java.util.regex.Pattern;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.TestUtil;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.CoreAdminParams;
import org.apache.solr.common.util.NamedList;
@ -48,8 +46,7 @@ public class TestManagedSchema extends AbstractBadConfigTestBase {
@Before
private void initManagedSchemaCore() throws Exception {
final String tmpSolrHomePath = createTempDir().getAbsolutePath();
tmpSolrHome = new File(tmpSolrHomePath).getAbsoluteFile();
tmpSolrHome = createTempDir();
tmpConfDir = new File(tmpSolrHome, confDir);
File testHomeConfDir = new File(TEST_HOME(), confDir);
FileUtils.copyFileToDirectory(new File(testHomeConfDir, "solrconfig-managed-schema.xml"), tmpConfDir);
@ -69,9 +66,8 @@ public class TestManagedSchema extends AbstractBadConfigTestBase {
}
@After
private void deleteCoreAndTempSolrHomeDirectory() throws Exception {
private void afterClass() throws Exception {
deleteCore();
FileUtils.deleteDirectory(tmpSolrHome);
System.clearProperty("managed.schema.mutable");
System.clearProperty("enable.update.log");
}

View File

@ -76,9 +76,7 @@ public class TestRecoveryHdfs extends SolrTestCaseJ4 {
@BeforeClass
public static void beforeClass() throws Exception {
dfsCluster = HdfsTestUtil.setupClass(new File(createTempDir(),
HdfsBasicDistributedZk2Test.class.getName() + "_"
+ System.currentTimeMillis()).getAbsolutePath());
dfsCluster = HdfsTestUtil.setupClass(createTempDir().getAbsolutePath());
hdfsUri = dfsCluster.getFileSystem().getUri().toString();
try {

View File

@ -66,8 +66,7 @@ public class TestSearcherReuse extends SolrTestCaseJ4 {
}
@AfterClass
private static void deleteCoreAndTempSolrHomeDirectory() throws Exception {
FileUtils.deleteDirectory(solrHome);
private static void afterClass() throws Exception {
solrHome = null;
}

View File

@ -45,14 +45,14 @@ public class CacheHeaderTest extends CacheHeaderTestBase {
@BeforeClass
public static void beforeTest() throws Exception {
solrHomeDirectory = new File(createTempDir(), "CacheHeaderTest");
solrHomeDirectory = createTempDir();
setupJettyTestHome(solrHomeDirectory, "collection1");
createJetty(solrHomeDirectory.getAbsolutePath(), null, null);
}
@AfterClass
public static void afterTest() throws Exception {
cleanUpJettyHome(solrHomeDirectory);
}
protected static final String CONTENTS = "id\n100\n101\n102";

View File

@ -106,7 +106,7 @@ public class FileBasedSpellCheckerTest extends SolrTestCaseJ4 {
spellchecker.add(AbstractLuceneSpellChecker.LOCATION, "spellings.txt");
spellchecker.add(AbstractLuceneSpellChecker.FIELD, "teststop");
spellchecker.add(FileBasedSpellChecker.SOURCE_FILE_CHAR_ENCODING, "UTF-8");
File indexDir = new File(createTempDir(), "spellingIdx");
File indexDir = createTempDir();
indexDir.mkdirs();
spellchecker.add(AbstractLuceneSpellChecker.INDEX_DIR, indexDir.getAbsolutePath());
spellchecker.add(SolrSpellChecker.FIELD_TYPE, "teststop");

View File

@ -186,7 +186,7 @@ public class IndexBasedSpellCheckerTest extends SolrTestCaseJ4 {
NamedList spellchecker = new NamedList();
spellchecker.add("classname", IndexBasedSpellChecker.class.getName());
File indexDir = new File(createTempDir(), "spellingIdx");
File indexDir = createTempDir();
indexDir.mkdirs();
spellchecker.add(AbstractLuceneSpellChecker.INDEX_DIR, indexDir.getAbsolutePath());
spellchecker.add(AbstractLuceneSpellChecker.FIELD, "title");
@ -244,7 +244,6 @@ public class IndexBasedSpellCheckerTest extends SolrTestCaseJ4 {
spellchecker.add("classname", IndexBasedSpellChecker.class.getName());
File indexDir = createTempDir();
indexDir.mkdirs();
spellchecker.add(AbstractLuceneSpellChecker.INDEX_DIR, indexDir.getAbsolutePath());
spellchecker.add(AbstractLuceneSpellChecker.FIELD, "title");
spellchecker.add(AbstractLuceneSpellChecker.SPELLCHECKER_ARG_NAME, spellchecker);

View File

@ -116,7 +116,6 @@ public class BlockDirectoryTest extends SolrTestCaseJ4 {
public void tearDown() throws Exception {
super.tearDown();
directory.close();
FileUtils.deleteDirectory(file);
}
@Test

View File

@ -17,7 +17,6 @@ package org.apache.solr.store.hdfs;
* limitations under the License.
*/
import java.io.File;
import java.io.IOException;
import java.net.URI;

View File

@ -57,28 +57,9 @@ public class SolrIndexSplitterTest extends SolrTestCaseJ4 {
super.setUp();
clearIndex();
assertU(commit());
File dataDir = createTempDir();
indexDir1 = new File(dataDir, this.getClass().getName()
+ "_testSplit1");
indexDir2 = new File(dataDir, this.getClass().getName()
+ "_testSplit2");
indexDir3 = new File(dataDir, this.getClass().getName()
+ "_testSplit3");
if (indexDir1.exists()) {
FileUtils.deleteDirectory(indexDir1);
}
assertTrue("Failed to mkdirs indexDir1 for split index", indexDir1.mkdirs());
if (indexDir2.exists()) {
FileUtils.deleteDirectory(indexDir2);
}
assertTrue("Failed to mkdirs indexDir2 for split index", indexDir2.mkdirs());
if (indexDir3.exists()) {
FileUtils.deleteDirectory(indexDir3);
}
assertTrue("Failed to mkdirs indexDir3 for split index", indexDir3.mkdirs());
indexDir1 = createTempDir("_testSplit1");
indexDir2 = createTempDir("_testSplit2");
indexDir3 = createTempDir("_testSplit3");
}
@Test
@ -272,10 +253,6 @@ public class SolrIndexSplitterTest extends SolrTestCaseJ4 {
@Test
public void testSplitByRouteKey() throws Exception {
File indexDir = createTempDir();
if (indexDir.exists()) {
FileUtils.deleteDirectory(indexDir);
}
indexDir.mkdirs();
CompositeIdRouter r1 = new CompositeIdRouter();
String splitKey = "sea-line!";

View File

@ -17,12 +17,12 @@
package org.apache.solr.update.processor;
import java.io.File;
import java.util.Date;
import org.apache.commons.io.FileUtils;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.TestUtil;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.schema.IndexSchema;
import org.apache.solr.schema.TestManagedSchema;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
@ -30,9 +30,6 @@ import org.joda.time.format.ISODateTimeFormat;
import org.junit.After;
import org.junit.Before;
import java.io.File;
import java.util.Date;
/**
* Tests for the field mutating update processors
* that parse Dates, Longs, Doubles, and Booleans.
@ -49,8 +46,7 @@ public class AddSchemaFieldsUpdateProcessorFactoryTest extends UpdateProcessorTe
@Before
private void initManagedSchemaCore() throws Exception {
final String tmpSolrHomePath = createTempDir().getAbsolutePath();
tmpSolrHome = new File(tmpSolrHomePath).getAbsoluteFile();
tmpSolrHome = createTempDir();
tmpConfDir = new File(tmpSolrHome, confDir);
File testHomeConfDir = new File(TEST_HOME(), confDir);
FileUtils.copyFileToDirectory(new File(testHomeConfDir, SOLRCONFIG_XML), tmpConfDir);
@ -61,12 +57,6 @@ public class AddSchemaFieldsUpdateProcessorFactoryTest extends UpdateProcessorTe
initCore(SOLRCONFIG_XML, SCHEMA_XML, tmpSolrHome.getPath());
}
@After
private void deleteCoreAndTempSolrHomeDirectory() throws Exception {
deleteCore();
FileUtils.deleteDirectory(tmpSolrHome);
}
public void testSingleField() throws Exception {
IndexSchema schema = h.getCore().getLatestSchema();
final String fieldName = "newfield1";
@ -220,4 +210,9 @@ public class AddSchemaFieldsUpdateProcessorFactoryTest extends UpdateProcessorTe
,"//arr[@name='" + fieldName3 + "']/str[.='" + field3String2 + "']"
,"//arr[@name='" + fieldName4 + "']/date[.='" + field4Value1String + "']");
}
@After
private void deleteCoreAndTempSolrHomeDirectory() throws Exception {
deleteCore();
}
}

View File

@ -99,15 +99,9 @@ public class TestCoreAdmin extends AbstractEmbeddedSolrServerTestCase {
SolrServer server = getSolrAdmin();
File tmp = createTempDir();
File dataDir = createTempDir("data");
log.info("Creating cores underneath {}", tmp);
File dataDir = new File(tmp, this.getTestName()
+ System.currentTimeMillis() + "-" + "data");
File newCoreInstanceDir = new File(tmp, this.getTestName()
+ System.currentTimeMillis() + "-" + "instance");
File newCoreInstanceDir = createTempDir("instance");
File instanceDir = new File(cores.getSolrHome());
FileUtils.copyDirectory(instanceDir, new File(newCoreInstanceDir,

View File

@ -121,9 +121,6 @@ abstract public class SolrJettyTestBase extends SolrTestCaseJ4
// Sets up the necessary config files for Jetty. At least some tests require that the solrconfig from the test
// file directory are used, but some also require that the solr.xml file be explicitly there as of SOLR-4817
public static void setupJettyTestHome(File solrHome, String collection) throws Exception {
if (solrHome.exists()) {
FileUtils.deleteDirectory(solrHome);
}
copySolrHomeToTemp(solrHome, collection);
}

View File

@ -63,8 +63,7 @@ public abstract class AbstractZkTestCase extends SolrTestCaseJ4 {
@BeforeClass
public static void azt_beforeClass() throws Exception {
zkDir = createTempDir().getAbsolutePath() + File.separator
+ "zookeeper/server1/data";
zkDir = createTempDir("zkData").getAbsolutePath();
zkServer = new ZkTestServer(zkDir);
zkServer.run();