Apache Lucene open-source search software
SOLR-2279: use Lucene's MockDirectoryWrapper in Solr tests
Robert Muir7f5305ecfc48
diff --git a/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java b/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.javaindex 557d6f64acd..4574d631fff 100644--- a/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java+++ b/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java@@ -221,7 +221,7 @@ public abstract class LuceneTestCase extends Assert {private static TimeZone timeZone;private static TimeZone savedTimeZone;- private static Map<MockDirectoryWrapper,StackTraceElement[]> stores;+ protected static Map<MockDirectoryWrapper,StackTraceElement[]> stores;private static final String[] TEST_CODECS = new String[] {"MockSep", "MockFixedIntBlock", "MockVariableIntBlock", "MockRandom"};diff --git a/solr/build.xml b/solr/build.xmlindex a1f90570756..8ca35e2b0d1 100644--- a/solr/build.xml+++ b/solr/build.xml@@ -463,9 +463,8 @@<sysproperty key="testmethod" value="${testmethod}"/><!-- set whether or not nightly tests should run --><sysproperty key="tests.nightly" value="${tests.nightly}"/>- <!-- TODO: why is this unconditionally set to "" above? disable for now- <jvmarg line="${dir.prop}"/>- -->+ <sysproperty key="tests.directory" value="${tests.directory}"/>+ <sysproperty key="solr.directoryFactory" value="org.apache.solr.core.MockDirectoryFactory"/><jvmarg line="${args}"/><formatter classname="${junit.details.formatter}" usefile="false" if="junit.details"/>diff --git a/solr/common-build.xml b/solr/common-build.xmlindex cdda84e1936..d5671ea379d 100644--- a/solr/common-build.xml+++ b/solr/common-build.xml@@ -68,6 +68,7 @@<property name="tests.seed" value="random" /><property name="tests.nightly" value="false" /><property name="tests.verbose" value="false" />+ <property name="tests.directory" value="random" /><condition property="dir.prop" value="-Dsolr.directoryFactory=solr.StandardDirectoryFactory"><isset property="use.fsdir"/>diff --git a/solr/contrib/analysis-extras/build.xml b/solr/contrib/analysis-extras/build.xmlindex 6ec8ecdbaa8..8fd22d099fb 100644--- a/solr/contrib/analysis-extras/build.xml+++ b/solr/contrib/analysis-extras/build.xml@@ -159,6 +159,8 @@<sysproperty key="jetty.testMode" value="1"/><sysproperty key="tempDir" file="${junit.output.dir}"/><sysproperty key="testmethod" value="${testmethod}"/>+ <sysproperty key="tests.directory" value="${tests.directory}"/>+ <sysproperty key="solr.directoryFactory" value="org.apache.solr.core.MockDirectoryFactory"/><jvmarg line="${args}"/><formatter classname="${junit.details.formatter}" usefile="false" if="junit.details"/><classpath refid="test.classpath"/>diff --git a/solr/contrib/clustering/build.xml b/solr/contrib/clustering/build.xmlindex 9a0c67eaa2f..896b87ed8df 100644--- a/solr/contrib/clustering/build.xml+++ b/solr/contrib/clustering/build.xml@@ -131,6 +131,8 @@<sysproperty key="jetty.testMode" value="1"/><sysproperty key="tempDir" file="${junit.output.dir}"/><sysproperty key="testmethod" value="${testmethod}"/>+ <sysproperty key="tests.directory" value="${tests.directory}"/>+ <sysproperty key="solr.directoryFactory" value="org.apache.solr.core.MockDirectoryFactory"/><jvmarg line="${args}"/><formatter classname="${junit.details.formatter}" usefile="false" if="junit.details"/><classpath refid="test.classpath"/>diff --git a/solr/contrib/dataimporthandler/build.xml b/solr/contrib/dataimporthandler/build.xmlindex 79a0524fcc7..a173dc0c5a7 100644--- a/solr/contrib/dataimporthandler/build.xml+++ b/solr/contrib/dataimporthandler/build.xml@@ -183,6 +183,8 @@<sysproperty key="jetty.testMode" value="1"/><sysproperty key="tempDir" file="${tempDir}"/><sysproperty key="testmethod" value="${testmethod}"/>+ <sysproperty key="tests.directory" value="${tests.directory}"/>+ <sysproperty key="solr.directoryFactory" value="org.apache.solr.core.MockDirectoryFactory"/><jvmarg line="${args}"/><formatter classname="${junit.details.formatter}" usefile="false" if="junit.details"/><classpath refid="test.classpath"/>@@ -245,6 +247,8 @@<sysproperty key="jetty.testMode" value="1"/><sysproperty key="tempDir" file="${tempDir}"/><sysproperty key="testmethod" value="${testmethod}"/>+ <sysproperty key="tests.directory" value="${tests.directory}"/>+ <sysproperty key="solr.directoryFactory" value="org.apache.solr.core.MockDirectoryFactory"/><jvmarg line="${args}"/><formatter classname="${junit.details.formatter}" usefile="false" if="junit.details"/><classpath refid="test.extras.classpath"/>diff --git a/solr/contrib/extraction/build.xml b/solr/contrib/extraction/build.xmlindex 50dcb4983d5..e0ea1ff00f6 100644--- a/solr/contrib/extraction/build.xml+++ b/solr/contrib/extraction/build.xml@@ -128,6 +128,8 @@<sysproperty key="jetty.testMode" value="1"/><sysproperty key="tempDir" file="${tempDir}"/><sysproperty key="testmethod" value="${testmethod}"/>+ <sysproperty key="tests.directory" value="${tests.directory}"/>+ <sysproperty key="solr.directoryFactory" value="org.apache.solr.core.MockDirectoryFactory"/><jvmarg line="${args}"/><formatter classname="${junit.details.formatter}" usefile="false" if="junit.details"/><classpath refid="test.classpath"/>diff --git a/solr/contrib/uima/build.xml b/solr/contrib/uima/build.xmlindex 16c7de67844..95e2060f7b3 100644--- a/solr/contrib/uima/build.xml+++ b/solr/contrib/uima/build.xml@@ -124,6 +124,8 @@<sysproperty key="jetty.insecurerandom" value="1"/><sysproperty key="tempDir" file="${tempDir}"/><sysproperty key="testmethod" value="${testmethod}"/>+ <sysproperty key="tests.directory" value="${tests.directory}"/>+ <sysproperty key="solr.directoryFactory" value="org.apache.solr.core.MockDirectoryFactory"/><jvmarg line="${args}"/><formatter classname="${junit.details.formatter}" usefile="false" if="junit.details"/><classpath refid="test.classpath"/>diff --git a/solr/src/test-framework/org/apache/solr/SolrTestCaseJ4.java b/solr/src/test-framework/org/apache/solr/SolrTestCaseJ4.javaindex d76996dd3ae..9a5ce81827b 100755--- a/solr/src/test-framework/org/apache/solr/SolrTestCaseJ4.java+++ b/solr/src/test-framework/org/apache/solr/SolrTestCaseJ4.java@@ -19,6 +19,7 @@package org.apache.solr;+import org.apache.lucene.store.MockDirectoryWrapper;import org.apache.lucene.util.LuceneTestCase;import org.apache.noggit.CharArr;import org.apache.noggit.JSONUtil;@@ -72,6 +73,16 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {resetExceptionIgnores();endTrackingSearchers();}++ // SOLR-2279: hack to shut these directories down+ // we still keep the ability to track open index files this way+ public static void closeDirectories() throws Exception {+ for (MockDirectoryWrapper d : stores.keySet()) {+ if (d.isOpen()) {+ d.close();+ }+ }+ }@Overridepublic void setUp() throws Exception {@@ -270,6 +281,7 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {public static void deleteCore() throws Exception {log.info("###deleteCore" );if (h != null) { h.close(); }+ closeDirectories();if (dataDir != null) {String skip = System.getProperty("solr.test.leavedatadir");if (null != skip && 0 != skip.trim().length()) {diff --git a/solr/src/test-framework/org/apache/solr/util/AbstractSolrTestCase.java b/solr/src/test-framework/org/apache/solr/util/AbstractSolrTestCase.javaindex 8f0382e131b..eb45e1870b8 100644--- a/solr/src/test-framework/org/apache/solr/util/AbstractSolrTestCase.java+++ b/solr/src/test-framework/org/apache/solr/util/AbstractSolrTestCase.java@@ -191,6 +191,7 @@ public abstract class AbstractSolrTestCase extends LuceneTestCase {}if (h != null) { h.close(); }+ SolrTestCaseJ4.closeDirectories();String skip = System.getProperty("solr.test.leavedatadir");if (null != skip && 0 != skip.trim().length()) {System.err.println("NOTE: per solr.test.leavedatadir, dataDir will not be removed: " + dataDir.getAbsolutePath());diff --git a/solr/src/test/org/apache/solr/TestSolrCoreProperties.java b/solr/src/test/org/apache/solr/TestSolrCoreProperties.javaindex d848d8e784c..28f6198420d 100644--- a/solr/src/test/org/apache/solr/TestSolrCoreProperties.java+++ b/solr/src/test/org/apache/solr/TestSolrCoreProperties.java@@ -59,6 +59,7 @@ public class TestSolrCoreProperties extends LuceneTestCase {@Overridepublic void tearDown() throws Exception {solrJetty.stop();+ SolrTestCaseJ4.closeDirectories();AbstractSolrTestCase.recurseDelete(homeDir);super.tearDown();}diff --git a/solr/src/test/org/apache/solr/client/solrj/embedded/JettyWebappTest.java b/solr/src/test/org/apache/solr/client/solrj/embedded/JettyWebappTest.javaindex ab67aad3fc2..161da30bd8a 100644--- a/solr/src/test/org/apache/solr/client/solrj/embedded/JettyWebappTest.java+++ b/solr/src/test/org/apache/solr/client/solrj/embedded/JettyWebappTest.java@@ -78,6 +78,7 @@ public class JettyWebappTest extends LuceneTestCasetry {server.stop();} catch( Exception ex ) {}+ SolrTestCaseJ4.closeDirectories();super.tearDown();}diff --git a/solr/src/test/org/apache/solr/client/solrj/embedded/MergeIndexesEmbeddedTest.java b/solr/src/test/org/apache/solr/client/solrj/embedded/MergeIndexesEmbeddedTest.javaindex 1a9164867bc..59bf574b607 100644--- a/solr/src/test/org/apache/solr/client/solrj/embedded/MergeIndexesEmbeddedTest.java+++ b/solr/src/test/org/apache/solr/client/solrj/embedded/MergeIndexesEmbeddedTest.java@@ -33,6 +33,8 @@ public class MergeIndexesEmbeddedTest extends MergeIndexesExampleTestBase {@Overridepublic void setUp() throws Exception {+ // TODO: fix this test to use MockDirectoryFactory+ System.clearProperty("solr.directoryFactory");super.setUp();File home = new File(getSolrHome());diff --git a/solr/src/test/org/apache/solr/client/solrj/embedded/MultiCoreExampleJettyTest.java b/solr/src/test/org/apache/solr/client/solrj/embedded/MultiCoreExampleJettyTest.javaindex 8fe4b69196f..2d637f06f35 100644--- a/solr/src/test/org/apache/solr/client/solrj/embedded/MultiCoreExampleJettyTest.java+++ b/solr/src/test/org/apache/solr/client/solrj/embedded/MultiCoreExampleJettyTest.java@@ -38,6 +38,8 @@ public class MultiCoreExampleJettyTest extends MultiCoreExampleTestBase {@Override public void setUp() throws Exception{+ // TODO: fix this test to use MockDirectoryFactory+ System.clearProperty("solr.directoryFactory");super.setUp();jetty = new JettySolrRunner( context, 0 );diff --git a/solr/src/test/org/apache/solr/core/MockDirectoryFactory.java b/solr/src/test/org/apache/solr/core/MockDirectoryFactory.javanew file mode 100644index 00000000000..c488c416e18--- /dev/null+++ b/solr/src/test/org/apache/solr/core/MockDirectoryFactory.java@@ -0,0 +1,35 @@+package org.apache.solr.core;++/**+ * 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.io.IOException;++import org.apache.lucene.store.Directory;+import org.apache.lucene.util.LuceneTestCase;++/**+ * Opens a directory with {@link LuceneTestCase#newFSDirectory(File)}+ */+public class MockDirectoryFactory extends DirectoryFactory {++ @Override+ public Directory open(String path) throws IOException {+ return LuceneTestCase.newFSDirectory(new File(path));+ }+}