Skip to content

Apache Lucene open-source search software

Merging with trunk.

Dawid Weissbc43bebedf29
diff --cc lucene/analysis/common/src/test/org/apache/lucene/analysis/util/TestFilesystemResourceLoader.java
index d37acf104c8,8bf5dd1d44e..3f3d61dc10a
--- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/util/TestFilesystemResourceLoader.java
+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/util/TestFilesystemResourceLoader.java
@@@ -61,10 -62,10 +62,10 @@@ public class TestFilesystemResourceLoad
}
public void testBaseDir() throws Exception {
- final File base = TestUtil.getTempDir("fsResourceLoaderBase").getAbsoluteFile();
+ final File base = TestUtil.createTempDir("fsResourceLoaderBase").getAbsoluteFile();
try {
base.mkdirs();
- Writer os = new OutputStreamWriter(new FileOutputStream(new File(base, "template.txt")), IOUtils.CHARSET_UTF_8);
+ Writer os = new OutputStreamWriter(new FileOutputStream(new File(base, "template.txt")), StandardCharsets.UTF_8);
try {
os.write("foobar\n");
} finally {
@@@ -87,7 -88,7 +88,7 @@@
assertClasspathDelegation(rl);
assertNotFound(rl);
} finally {
-- TestUtil.rmDir(base);
++ TestUtil.rm(base);
}
}
diff --cc lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksParse.java
index 77674bd4549,7999a553de6..515c8f7b503
--- a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksParse.java
+++ b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksParse.java
@@@ -23,6 -23,9 +23,7 @@@ import java.io.FileInputStream
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringReader;
-import java.nio.charset.Charset;
+ import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import org.apache.lucene.benchmark.byTask.feeds.AbstractQueryMaker;
@@@ -121,10 -121,10 +122,10 @@@ public class TestPerfTasksParse extend
public boolean accept(File pathname) { return pathname.isFile() && pathname.getName().endsWith(".alg"); }
})) {
try {
- Config config = new Config(new InputStreamReader(new FileInputStream(algFile), "UTF-8"));
+ Config config = new Config(new InputStreamReader(new FileInputStream(algFile), StandardCharsets.UTF_8));
String contentSource = config.get("content.source", null);
if (contentSource != null) { Class.forName(contentSource); }
- config.set("work.dir", new File(TEMP_DIR,"work").getAbsolutePath());
+ config.set("work.dir", TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName()).getAbsolutePath());
config.set("content.source", MockContentSource.class.getName());
String dir = config.get("content.source", null);
if (dir != null) { Class.forName(dir); }
diff --cc lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/utils/StreamUtilsTest.java
index 8c4c50ca94f,15fb0c965f0..8a88e2049a9
--- a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/utils/StreamUtilsTest.java
+++ b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/utils/StreamUtilsTest.java
@@@ -136,14 -136,14 +136,14 @@@ public class StreamUtilsTest extends Be
public void setUp() throws Exception {
super.setUp();
testDir = new File(getWorkDir(),"ContentSourceTest");
-- TestUtil.rmDir(testDir);
++ TestUtil.rm(testDir);
assertTrue(testDir.mkdirs());
}
@Override
@After
public void tearDown() throws Exception {
-- TestUtil.rmDir(testDir);
++ TestUtil.rm(testDir);
super.tearDown();
}
diff --cc lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
index 3ba113c417e,c3b7dda44ea..4c82757e2c2
--- a/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
@@@ -292,13 -293,13 +293,13 @@@ public class TestBackwardsCompatibilit
ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
CheckIndex checker = new CheckIndex(dir);
- checker.setInfoStream(new PrintStream(bos, false, "UTF-8"));
+ checker.setInfoStream(new PrintStream(bos, false, IOUtils.UTF_8));
CheckIndex.Status indexStatus = checker.checkIndex();
assertFalse(indexStatus.clean);
- assertTrue(bos.toString("UTF-8").contains(IndexFormatTooOldException.class.getName()));
+ assertTrue(bos.toString(IOUtils.UTF_8).contains(IndexFormatTooOldException.class.getName()));
dir.close();
-- TestUtil.rmDir(oldIndxeDir);
++ TestUtil.rm(oldIndxeDir);
}
}
@@@ -597,7 -598,7 +598,7 @@@
public File createIndex(String dirName, boolean doCFS, boolean fullyMerged) throws IOException {
// we use a real directory name that is not cleaned up, because this method is only used to create backwards indexes:
File indexDir = new File("/tmp/idx", dirName);
-- TestUtil.rmDir(indexDir);
++ TestUtil.rm(indexDir);
Directory dir = newFSDirectory(indexDir);
LogByteSizeMergePolicy mp = new LogByteSizeMergePolicy();
mp.setNoCFSRatio(doCFS ? 1.0 : 0.0);
@@@ -645,8 -646,8 +646,8 @@@
public void testExactFileNames() throws IOException {
String outputDirName = "lucene.backwardscompat0.index";
- File outputDir = TestUtil.getTempDir(outputDirName);
- TestUtil.rmDir(outputDir);
+ File outputDir = TestUtil.createTempDir(outputDirName);
- TestUtil.rmDir(outputDir);
++ TestUtil.rm(outputDir);
try {
Directory dir = newFSDirectory(outputDir);
@@@ -704,7 -705,7 +705,7 @@@
}
dir.close();
} finally {
-- TestUtil.rmDir(outputDir);
++ TestUtil.rm(outputDir);
}
}
diff --cc lucene/core/src/test/org/apache/lucene/util/TestOfflineSorter.java
index 425059a267b,fc704cbb714..221d361d570
--- a/lucene/core/src/test/org/apache/lucene/util/TestOfflineSorter.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestOfflineSorter.java
@@@ -42,15 -43,15 +43,15 @@@ public class TestOfflineSorter extends
@Override
public void setUp() throws Exception {
super.setUp();
- tempDir = TestUtil.getTempDir("mergesort");
- TestUtil.rmDir(tempDir);
+ tempDir = TestUtil.createTempDir("mergesort");
- TestUtil.rmDir(tempDir);
++ TestUtil.rm(tempDir);
tempDir.mkdirs();
}
@Override
public void tearDown() throws Exception {
if (tempDir != null)
-- TestUtil.rmDir(tempDir);
++ TestUtil.rm(tempDir);
super.tearDown();
}
diff --cc lucene/test-framework/src/java/org/apache/lucene/index/BasePostingsFormatTestCase.java
index 5ef63464ffb,d96a4731ff6..10935a662f3
--- a/lucene/test-framework/src/java/org/apache/lucene/index/BasePostingsFormatTestCase.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/index/BasePostingsFormatTestCase.java
@@@ -1232,7 -1224,7 +1224,7 @@@ public abstract class BasePostingsForma
fieldsProducer.close();
dir.close();
-- TestUtil.rmDir(path);
++ TestUtil.rm(path);
}
public void testDocsOnly() throws Exception {
@@@ -1281,7 -1273,7 +1273,7 @@@
fieldsProducer = null;
dir.close();
-- TestUtil.rmDir(path);
++ TestUtil.rm(path);
}
}
diff --cc lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java
index b9cc69a4e1a,859d5e05197..6ef10cf99ac
--- a/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java
@@@ -103,42 -103,70 +103,38 @@@ public final class TestUtil
private static final int GET_TEMP_DIR_RETRY_THRESHOLD = 1000;
/**
- * Deletes a directory and everything underneath it.
- * Returns a temp directory, based on the given description. Creates the
- * directory.
++ * Deletes a file or a directory (and everything underneath it).
*/
- public static void rmDir(File dir) throws IOException {
- if (dir.exists()) {
- if (dir.isFile() && !dir.delete()) {
- throw new IOException("could not delete " + dir);
- }
- for (File f : dir.listFiles()) {
- if (f.isDirectory()) {
- rmDir(f);
- } else {
- if (!f.delete()) {
- throw new IOException("could not delete " + f);
- }
- }
- public static File getTempDir(String desc) {
- if (desc.length() < 3) {
- throw new IllegalArgumentException("description must be at least 3 characters");
++ public static void rm(File location) throws IOException {
++ if (!location.exists()) {
++ return;
+ }
- // always pull a long from master random. that way, the randomness of the test
- // is not affected by whether it initialized the counter (in genTempFile) or not.
- // note that the Random used by genTempFile is *not* the master Random, and therefore
- // does not affect the randomness of the test.
- final Random random = new Random(RandomizedContext.current().getRandom().nextLong());
- int attempt = 0;
- File f;
- do {
- f = genTempFile(random, desc, "tmp", LuceneTestCase.TEMP_DIR);
- } while (!f.mkdir() && (attempt++) < GET_TEMP_DIR_RETRY_THRESHOLD);
-
- if (attempt > GET_TEMP_DIR_RETRY_THRESHOLD) {
- throw new RuntimeException(
- "failed to get a temporary dir too many times. check your temp directory and consider manually cleaning it.");
- }
-
- LuceneTestCase.closeAfterSuite(new CloseableFile(f, LuceneTestCase.suiteFailureMarker));
- return f;
- }
+
- /**
- * Deletes a directory and everything underneath it.
- */
- public static void rmDir(File dir) throws IOException {
- if (dir.exists()) {
- if (dir.isFile() && !dir.delete()) {
- throw new IOException("could not delete " + dir);
++ if (location.isDirectory()) {
++ for (File f : location.listFiles()) {
++ rm(f);
}
- for (File f : dir.listFiles()) {
- if (f.isDirectory()) {
- rmDir(f);
- } else {
- if (!f.delete()) {
- throw new IOException("could not delete " + f);
- }
- }
- }
-- if (!dir.delete()) {
-- throw new IOException("could not delete " + dir);
++ } else {
++ if (!location.delete()) {
++ throw new IOException("Could not delete: " + location.getAbsolutePath());
}
}
++
++ assert !location.exists();
}
/**
-- * Convenience method: Unzip zipName + ".zip" under destDir, removing destDir first
++ * Convenience method: Unzip zipName + ".zip" into destDir, cleaning up
++ * destDir first.
*/
public static void unzip(File zipName, File destDir) throws IOException {
--
-- ZipFile zipFile = new ZipFile(zipName);
--
-- Enumeration<? extends ZipEntry> entries = zipFile.entries();
--
-- rmDir(destDir);
--
++ rm(destDir);
destDir.mkdir();
LuceneTestCase.closeAfterSuite(new CloseableFile(destDir, LuceneTestCase.suiteFailureMarker));
++ ZipFile zipFile = new ZipFile(zipName);
++ Enumeration<? extends ZipEntry> entries = zipFile.entries();
++
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
diff --cc solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestDocBuilder2.java
index f946af943ed,61d91393ee3..faa7dcfac29
--- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestDocBuilder2.java
+++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestDocBuilder2.java
@@@ -25,7 -19,14 +25,9 @@@ import org.apache.solr.request.LocalSol
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
-import org.apache.solr.request.LocalSolrQueryRequest;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.io.File;
+ import java.nio.charset.StandardCharsets;
+
/**
* <p>
* Test for DocBuilder using the test harness
diff --cc solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestFileListEntityProcessor.java
index 9ab861d7657,a7d3d52c55c..1fac521c9d4
--- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestFileListEntityProcessor.java
+++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestFileListEntityProcessor.java
@@@ -39,11 -38,13 +40,11 @@@ public class TestFileListEntityProcesso
@Test
@SuppressWarnings("unchecked")
public void testSimple() throws IOException {
- File tmpdir = File.createTempFile("test", "tmp", dataDir);
- tmpdir.delete();
- tmpdir.mkdir();
- tmpdir.deleteOnExit();
+ File tmpdir = createTempDir();
+
- createFile(tmpdir, "a.xml", "a.xml".getBytes("UTF-8"), false);
- createFile(tmpdir, "b.xml", "b.xml".getBytes("UTF-8"), false);
- createFile(tmpdir, "c.props", "c.props".getBytes("UTF-8"), false);
+ createFile(tmpdir, "a.xml", "a.xml".getBytes(StandardCharsets.UTF_8), false);
+ createFile(tmpdir, "b.xml", "b.xml".getBytes(StandardCharsets.UTF_8), false);
+ createFile(tmpdir, "c.props", "c.props".getBytes(StandardCharsets.UTF_8), false);
Map attrs = createMap(
FileListEntityProcessor.FILE_NAME, "xml$",
FileListEntityProcessor.BASE_DIR, tmpdir.getAbsolutePath());
@@@ -63,13 -64,13 +64,13 @@@
@Test
public void testBiggerSmallerFiles() throws IOException {
- File tmpdir = File.createTempFile("test", "tmp", dataDir);
+ File tmpdir = File.createTempFile("test", "tmp", createTempDir());
tmpdir.delete();
tmpdir.mkdir();
- tmpdir.deleteOnExit();
+
long minLength = Long.MAX_VALUE;
String smallestFile = "";
- byte[] content = "abcdefgij".getBytes("UTF-8");
+ byte[] content = "abcdefgij".getBytes(StandardCharsets.UTF_8);
createFile(tmpdir, "a.xml", content, false);
if (minLength > content.length) {
minLength = content.length;
@@@ -133,11 -134,13 +134,11 @@@
@Test
public void testNTOT() throws IOException {
- File tmpdir = File.createTempFile("test", "tmp", dataDir);
- tmpdir.delete();
- tmpdir.mkdir();
- tmpdir.deleteOnExit();
+ File tmpdir = createTempDir();
+
- createFile(tmpdir, "a.xml", "a.xml".getBytes("UTF-8"), true);
- createFile(tmpdir, "b.xml", "b.xml".getBytes("UTF-8"), true);
- createFile(tmpdir, "c.props", "c.props".getBytes("UTF-8"), true);
+ createFile(tmpdir, "a.xml", "a.xml".getBytes(StandardCharsets.UTF_8), true);
+ createFile(tmpdir, "b.xml", "b.xml".getBytes(StandardCharsets.UTF_8), true);
+ createFile(tmpdir, "c.props", "c.props".getBytes(StandardCharsets.UTF_8), true);
Map attrs = createMap(
FileListEntityProcessor.FILE_NAME, "xml$",
FileListEntityProcessor.BASE_DIR, tmpdir.getAbsolutePath(),
@@@ -167,12 -170,16 +168,12 @@@
@Test
public void testRECURSION() throws IOException {
- File tmpdir = File.createTempFile("test", "tmp", dataDir);
- tmpdir.delete();
- tmpdir.mkdir();
- tmpdir.deleteOnExit();
+ File tmpdir = createTempDir();
File childdir = new File(tmpdir + "/child" );
- childdir.mkdirs();
- childdir.deleteOnExit();
+ childdir.mkdir();
- createFile(childdir, "a.xml", "a.xml".getBytes("UTF-8"), true);
- createFile(childdir, "b.xml", "b.xml".getBytes("UTF-8"), true);
- createFile(childdir, "c.props", "c.props".getBytes("UTF-8"), true);
+ createFile(childdir, "a.xml", "a.xml".getBytes(StandardCharsets.UTF_8), true);
+ createFile(childdir, "b.xml", "b.xml".getBytes(StandardCharsets.UTF_8), true);
+ createFile(childdir, "c.props", "c.props".getBytes(StandardCharsets.UTF_8), true);
Map attrs = createMap(
FileListEntityProcessor.FILE_NAME, "^.*\\.xml$",
FileListEntityProcessor.BASE_DIR, childdir.getAbsolutePath(),
diff --cc solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestFileListWithLineEntityProcessor.java
index c07a6cf29a3,58a9eeeade9..5f0c58d0aa8
--- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestFileListWithLineEntityProcessor.java
+++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestFileListWithLineEntityProcessor.java
@@@ -1,9 -1,8 +1,10 @@@
package org.apache.solr.handler.dataimport;
import java.io.File;
+ import java.nio.charset.StandardCharsets;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.request.LocalSolrQueryRequest;
import org.junit.BeforeClass;
@@@ -31,10 -30,13 +32,10 @@@ public class TestFileListWithLineEntity
}
public void test() throws Exception {
- File tmpdir = File.createTempFile("test", "tmp", TEMP_DIR);
- tmpdir.delete();
- tmpdir.mkdir();
- tmpdir.deleteOnExit();
+ File tmpdir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
- createFile(tmpdir, "a.txt", "a line one\na line two\na line three".getBytes("UTF-8"), false);
- createFile(tmpdir, "b.txt", "b line one\nb line two".getBytes("UTF-8"), false);
- createFile(tmpdir, "c.txt", "c line one\nc line two\nc line three\nc line four".getBytes("UTF-8"), false);
+ createFile(tmpdir, "a.txt", "a line one\na line two\na line three".getBytes(StandardCharsets.UTF_8), false);
+ createFile(tmpdir, "b.txt", "b line one\nb line two".getBytes(StandardCharsets.UTF_8), false);
+ createFile(tmpdir, "c.txt", "c line one\nc line two\nc line three\nc line four".getBytes(StandardCharsets.UTF_8), false);
String config = generateConfig(tmpdir);
LocalSolrQueryRequest request = lrf.makeRequest(
diff --cc solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestXPathEntityProcessor.java
index c370223fdb8,28bd4c858a9..778d1913847
--- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestXPathEntityProcessor.java
+++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestXPathEntityProcessor.java
@@@ -42,9 -43,11 +43,9 @@@ public class TestXPathEntityProcessor e
@Test
public void withFieldsAndXpath() throws Exception {
- File tmpdir = File.createTempFile("test", "tmp", dataDir);
- tmpdir.delete();
- tmpdir.mkdir();
- tmpdir.deleteOnExit();
+ File tmpdir = createTempDir();
+
- createFile(tmpdir, "x.xsl", xsl.getBytes("UTF-8"), false);
+ createFile(tmpdir, "x.xsl", xsl.getBytes(StandardCharsets.UTF_8), false);
Map entityAttrs = createMap("name", "e", "url", "cd.xml",
XPathEntityProcessor.FOR_EACH, "/catalog/cd");
List fields = new ArrayList();
@@@ -331,10 -334,12 +332,10 @@@
@Test
public void withDefaultSolrAndXsl() throws Exception {
- File tmpdir = File.createTempFile("test", "tmp", dataDir);
- tmpdir.delete();
- tmpdir.mkdir();
- tmpdir.deleteOnExit();
+ File tmpdir = createTempDir();
- AbstractDataImportHandlerTestCase.createFile(tmpdir, "x.xsl", xsl.getBytes("UTF-8"),
+ AbstractDataImportHandlerTestCase.createFile(tmpdir, "x.xsl", xsl.getBytes(StandardCharsets.UTF_8),
false);
+
Map entityAttrs = createMap("name", "e",
XPathEntityProcessor.USE_SOLR_ADD_SCHEMA, "true", "xsl", ""
+ new File(tmpdir, "x.xsl").toURI(), "url", "cd.xml");
diff --cc solr/core/src/test/org/apache/solr/TestSolrCoreProperties.java
index 15ee5627780,b063728a398..17de9263d9b
--- a/solr/core/src/test/org/apache/solr/TestSolrCoreProperties.java
+++ b/solr/core/src/test/org/apache/solr/TestSolrCoreProperties.java
@@@ -27,8 -20,19 +27,9 @@@ import org.apache.lucene.util.IOUtils
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
-import org.apache.commons.io.FileUtils;
import org.junit.BeforeClass;
-import java.io.*;
+ import java.nio.charset.StandardCharsets;
-import java.util.Properties;
-
/**
* <p> Test for Loading core properties from a properties file </p>
diff --cc solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java
index 08bbd3e02bb,7548403f7c3..26f9894a566
--- a/solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java
@@@ -277,13 -277,11 +278,13 @@@ public class ZkCLITest extends SolrTest
@Test
public void testGetFile() throws Exception {
+ File tmpDir = createTempDir();
+
String getNode = "/getFileNode";
- byte [] data = new String("getFileNode-data").getBytes("UTF-8");
+ byte [] data = new String("getFileNode-data").getBytes(StandardCharsets.UTF_8);
this.zkClient.create(getNode, data, CreateMode.PERSISTENT, true);
- File file = new File(dataDir,
+ File file = new File(tmpDir,
"solrtest-getfile-" + this.getClass().getName() + "-" + System.currentTimeMillis());
String[] args = new String[] {"-zkhost", zkServer.getZkAddress(), "-cmd",
"getfile", getNode, file.getAbsolutePath()};
diff --cc solr/core/src/test/org/apache/solr/core/TestCoreContainer.java
index 65f872fd2cc,4a1cdf2d296..3f83e61cf5b
--- a/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java
+++ b/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java
@@@ -30,20 -41,9 +31,20 @@@ import java.util.List
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.core.IsInstanceOf.instanceOf;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.commons.io.FileUtils;
- import org.apache.lucene.util.IOUtils;
+import org.apache.lucene.util.TestUtil;
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.handler.admin.CollectionsHandler;
+import org.apache.solr.handler.admin.CoreAdminHandler;
+import org.apache.solr.handler.admin.InfoHandler;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.xml.sax.SAXException;
+
+
public class TestCoreContainer extends SolrTestCaseJ4 {
private static String oldSolrHome;
diff --cc solr/core/src/test/org/apache/solr/core/TestCoreDiscovery.java
index f7375fc5329,70c24fcc02b..60d2456fbcc
--- a/solr/core/src/test/org/apache/solr/core/TestCoreDiscovery.java
+++ b/solr/core/src/test/org/apache/solr/core/TestCoreDiscovery.java
@@@ -31,6 -25,13 +31,8 @@@ import org.junit.After
import org.junit.BeforeClass;
import org.junit.Test;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
+ import java.nio.charset.StandardCharsets;
-import java.util.Properties;
+
public class TestCoreDiscovery extends SolrTestCaseJ4 {
@BeforeClass
diff --cc solr/core/src/test/org/apache/solr/core/TestSolrXMLSerializer.java
index 57c427399ae,480acbaabb2..056f9745b46
--- a/solr/core/src/test/org/apache/solr/core/TestSolrXMLSerializer.java
+++ b/solr/core/src/test/org/apache/solr/core/TestSolrXMLSerializer.java
@@@ -79,10 -80,10 +80,10 @@@ public class TestSolrXMLSerializer exte
w.close();
}
- assertResults(((StringWriter) w).getBuffer().toString().getBytes("UTF-8"));
+ assertResults(w.toString().getBytes(StandardCharsets.UTF_8));
// again with default file
- File tmpFile = TestUtil.createTempFile("solr.xml", null, dataDir);
+ File tmpFile = TestUtil.createTempFile("solr.xml", null, createTempDir());
serializer.persistFile(tmpFile, solrXMLDef);
diff --cc solr/core/src/test/org/apache/solr/core/TestSolrXmlPersistence.java
index 683ce99cae6,648f8ecaa85..f9a5dad4fc2
--- a/solr/core/src/test/org/apache/solr/core/TestSolrXmlPersistence.java
+++ b/solr/core/src/test/org/apache/solr/core/TestSolrXmlPersistence.java
@@@ -17,20 -17,7 +17,21 @@@
package org.apache.solr.core;
+import static org.hamcrest.core.Is.is;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+ import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.lucene.util.IOUtils;
@@@ -52,8 -36,19 +53,8 @@@ import org.w3c.dom.Node
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
- import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
+import com.google.common.base.Charsets;
+ import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.hamcrest.core.Is.is;
public class TestSolrXmlPersistence extends SolrTestCaseJ4 {
diff --cc solr/core/src/test/org/apache/solr/handler/admin/CoreAdminCreateDiscoverTest.java
index 8b97f7124ad,532245db27f..33347f9a01d
--- a/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminCreateDiscoverTest.java
+++ b/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminCreateDiscoverTest.java
@@@ -17,14 -17,7 +17,13 @@@
package org.apache.solr.handler.admin;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.Properties;
+
import org.apache.commons.io.FileUtils;
- import org.apache.lucene.util.IOUtils;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.CoreAdminParams;
@@@ -35,6 -28,13 +34,8 @@@ import org.junit.AfterClass
import org.junit.BeforeClass;
import org.junit.Test;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
+ import java.nio.charset.StandardCharsets;
-import java.util.Properties;
+
public class CoreAdminCreateDiscoverTest extends SolrTestCaseJ4 {
private static File solrHomeDirectory = null;
diff --cc solr/core/src/test/org/apache/solr/rest/schema/analysis/TestManagedSynonymFilterFactory.java
index 00000000000,10ea732bce1..1c91ab9142e
mode 000000,100644..100644
--- a/solr/core/src/test/org/apache/solr/rest/schema/analysis/TestManagedSynonymFilterFactory.java
+++ b/solr/core/src/test/org/apache/solr/rest/schema/analysis/TestManagedSynonymFilterFactory.java
@@@ -1,0 -1,179 +1,178 @@@
+ package org.apache.solr.rest.schema.analysis;
+ /*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ import java.io.File;
+ import java.util.Arrays;
+ import java.util.HashMap;
+ import java.util.List;
+ import java.util.Map;
+ import java.util.SortedMap;
+ import java.util.TreeMap;
+
+ import org.apache.commons.io.FileUtils;
+ import org.apache.solr.util.RestTestBase;
+ import org.eclipse.jetty.servlet.ServletHolder;
+ import org.junit.After;
+ import org.junit.Before;
+ import org.junit.Test;
+ import org.noggit.JSONUtil;
+ import org.restlet.ext.servlet.ServerServlet;
+
+ public class TestManagedSynonymFilterFactory extends RestTestBase {
+
+ private static File tmpSolrHome;
+
+ /**
+ * Setup to make the schema mutable
+ */
+ @Before
+ public void before() throws Exception {
- tmpSolrHome = new File(dataDir + File.separator + TestManagedStopFilterFactory.class.getSimpleName()
- + System.currentTimeMillis());
++ tmpSolrHome = createTempDir();
+ FileUtils.copyDirectory(new File(TEST_HOME()), tmpSolrHome.getAbsoluteFile());
+
+ final SortedMap<ServletHolder,String> extraServlets = new TreeMap<>();
+ final ServletHolder solrRestApi = new ServletHolder("SolrSchemaRestApi", ServerServlet.class);
+ solrRestApi.setInitParameter("org.restlet.application", "org.apache.solr.rest.SolrSchemaRestApi");
+ extraServlets.put(solrRestApi, "/schema/*");
+
+ System.setProperty("managed.schema.mutable", "true");
+ System.setProperty("enable.update.log", "false");
+ createJettyAndHarness(tmpSolrHome.getAbsolutePath(), "solrconfig-managed-schema.xml", "schema-rest.xml",
+ "/solr", true, extraServlets);
+ }
+
+ @After
+ private void after() throws Exception {
+ jetty.stop();
+ jetty = null;
+ FileUtils.deleteDirectory(tmpSolrHome);
+ System.clearProperty("managed.schema.mutable");
+ System.clearProperty("enable.update.log");
+ }
+
+ @Test
+ public void testManagedSynonyms() throws Exception {
+ // this endpoint depends on at least one field type containing the following
+ // declaration in the schema-rest.xml:
+ //
+ // <filter class="solr.ManagedSynonymFilterFactory" managed="english" />
+ //
+ String endpoint = "/schema/analysis/synonyms/english";
+
+ assertJQ(endpoint,
+ "/synonymMappings/initArgs/ignoreCase==false",
+ "/synonymMappings/managedMap=={}");
+
+ // put a new mapping into the synonyms
+ Map<String,List<String>> syns = new HashMap<>();
+ syns.put("happy", Arrays.asList("glad","cheerful","joyful"));
+ assertJPut(endpoint,
+ JSONUtil.toJSON(syns),
+ "/responseHeader/status==0");
+
+ assertJQ(endpoint,
+ "/synonymMappings/managedMap/happy==['cheerful','glad','joyful']");
+
+ // request to a specific mapping
+ assertJQ(endpoint+"/happy",
+ "/happy==['cheerful','glad','joyful']");
+
+ // does not exist
+ assertJQ(endpoint+"/sad",
+ "/error/code==404");
+
+ // verify the user can update the ignoreCase initArg
+ assertJPut(endpoint,
+ json("{ 'initArgs':{ 'ignoreCase':true } }"),
+ "responseHeader/status==0");
+
+ assertJQ(endpoint,
+ "/synonymMappings/initArgs/ignoreCase==true");
+
+ syns = new HashMap<>();
+ syns.put("sad", Arrays.asList("unhappy"));
+ syns.put("SAD", Arrays.asList("Unhappy"));
+ assertJPut(endpoint,
+ JSONUtil.toJSON(syns),
+ "/responseHeader/status==0");
+
+ assertJQ(endpoint,
+ "/synonymMappings/managedMap/sad==['unhappy']");
+
+ // verify delete works
+ assertJDelete(endpoint+"/sad",
+ "/responseHeader/status==0");
+
+ assertJQ(endpoint,
+ "/synonymMappings/managedMap=={'happy':['cheerful','glad','joyful']}");
+
+ // should fail with 404 as foo doesn't exist
+ assertJDelete(endpoint+"/foo",
+ "/error/code==404");
+
+ // verify that a newly added synonym gets expanded on the query side after core reload
+
+ String newFieldName = "managed_en_field";
+ // make sure the new field doesn't already exist
+ assertQ("/schema/fields/" + newFieldName + "?indent=on&wt=xml",
+ "count(/response/lst[@name='field']) = 0",
+ "/response/lst[@name='responseHeader']/int[@name='status'] = '404'",
+ "/response/lst[@name='error']/int[@name='code'] = '404'");
+
+ // add the new field
+ assertJPut("/schema/fields/" + newFieldName, json("{'type':'managed_en'}"),
+ "/responseHeader/status==0");
+
+ // make sure the new field exists now
+ assertQ("/schema/fields/" + newFieldName + "?indent=on&wt=xml",
+ "count(/response/lst[@name='field']) = 1",
+ "/response/lst[@name='responseHeader']/int[@name='status'] = '0'");
+
+ assertU(adoc(newFieldName, "I am a happy test today but yesterday I was angry", "id", "5150"));
+ assertU(commit());
+
+ assertQ("/select?q=" + newFieldName + ":angry",
+ "/response/lst[@name='responseHeader']/int[@name='status'] = '0'",
+ "/response/result[@name='response'][@numFound='1']",
+ "/response/result[@name='response']/doc/str[@name='id'][.='5150']");
+
+ // add a mapping that will expand a query for "mad" to match docs with "angry"
+ syns = new HashMap<>();
+ syns.put("mad", Arrays.asList("angry"));
+ assertJPut(endpoint,
+ JSONUtil.toJSON(syns),
+ "/responseHeader/status==0");
+
+ assertJQ(endpoint,
+ "/synonymMappings/managedMap/mad==['angry']");
+
+ // should not match as the synonym mapping between mad and angry does not
+ // get applied until core reload
+ assertQ("/select?q=" + newFieldName + ":mad",
+ "/response/lst[@name='responseHeader']/int[@name='status'] = '0'",
+ "/response/result[@name='response'][@numFound='0']");
+
+ restTestHarness.reload();
+
+ // now query for mad and we should see our test doc
+ assertQ("/select?q=" + newFieldName + ":mad",
+ "/response/lst[@name='responseHeader']/int[@name='status'] = '0'",
+ "/response/result[@name='response'][@numFound='1']",
+ "/response/result[@name='response']/doc/str[@name='id'][.='5150']");
+ }
+ }
diff --cc solr/core/src/test/org/apache/solr/update/SolrIndexSplitterTest.java
index 28f594c25d8,c5662eecd08..e6df158e373
--- a/solr/core/src/test/org/apache/solr/update/SolrIndexSplitterTest.java
+++ b/solr/core/src/test/org/apache/solr/update/SolrIndexSplitterTest.java
@@@ -17,11 -17,9 +17,11 @@@ package org.apache.solr.update
* limitations under the License.
*/
-import com.google.common.collect.Lists;
+import java.io.File;
+import java.io.UnsupportedEncodingException;
+import java.util.List;
+
- import org.apache.commons.io.FileUtils;
+
-import org.apache.commons.io.FileUtils;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.Term;
import org.apache.lucene.store.Directory;
@@@ -40,7 -38,10 +40,8 @@@ import org.junit.Before
import org.junit.BeforeClass;
import org.junit.Test;
-import java.io.File;
-import java.io.UnsupportedEncodingException;
+import com.google.common.collect.Lists;
+ import java.nio.charset.StandardCharsets;
-import java.util.List;
public class SolrIndexSplitterTest extends SolrTestCaseJ4 {
File indexDir1 = null, indexDir2 = null, indexDir3 = null;