mirror of https://github.com/apache/lucene.git
SOLR-2279: use Lucene's MockDirectoryWrapper in Solr tests
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1130042 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a890a8f5b0
commit
7f5305ecfc
|
@ -221,7 +221,7 @@ public abstract class LuceneTestCase extends Assert {
|
||||||
private static TimeZone timeZone;
|
private static TimeZone timeZone;
|
||||||
private static TimeZone savedTimeZone;
|
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"};
|
private static final String[] TEST_CODECS = new String[] {"MockSep", "MockFixedIntBlock", "MockVariableIntBlock", "MockRandom"};
|
||||||
|
|
||||||
|
|
|
@ -463,9 +463,8 @@
|
||||||
<sysproperty key="testmethod" value="${testmethod}"/>
|
<sysproperty key="testmethod" value="${testmethod}"/>
|
||||||
<!-- set whether or not nightly tests should run -->
|
<!-- set whether or not nightly tests should run -->
|
||||||
<sysproperty key="tests.nightly" value="${tests.nightly}"/>
|
<sysproperty key="tests.nightly" value="${tests.nightly}"/>
|
||||||
<!-- TODO: why is this unconditionally set to "" above? disable for now
|
<sysproperty key="tests.directory" value="${tests.directory}"/>
|
||||||
<jvmarg line="${dir.prop}"/>
|
<sysproperty key="solr.directoryFactory" value="org.apache.solr.core.MockDirectoryFactory"/>
|
||||||
-->
|
|
||||||
<jvmarg line="${args}"/>
|
<jvmarg line="${args}"/>
|
||||||
|
|
||||||
<formatter classname="${junit.details.formatter}" usefile="false" if="junit.details"/>
|
<formatter classname="${junit.details.formatter}" usefile="false" if="junit.details"/>
|
||||||
|
|
|
@ -68,6 +68,7 @@
|
||||||
<property name="tests.seed" value="random" />
|
<property name="tests.seed" value="random" />
|
||||||
<property name="tests.nightly" value="false" />
|
<property name="tests.nightly" value="false" />
|
||||||
<property name="tests.verbose" value="false" />
|
<property name="tests.verbose" value="false" />
|
||||||
|
<property name="tests.directory" value="random" />
|
||||||
|
|
||||||
<condition property="dir.prop" value="-Dsolr.directoryFactory=solr.StandardDirectoryFactory">
|
<condition property="dir.prop" value="-Dsolr.directoryFactory=solr.StandardDirectoryFactory">
|
||||||
<isset property="use.fsdir"/>
|
<isset property="use.fsdir"/>
|
||||||
|
|
|
@ -159,6 +159,8 @@
|
||||||
<sysproperty key="jetty.testMode" value="1"/>
|
<sysproperty key="jetty.testMode" value="1"/>
|
||||||
<sysproperty key="tempDir" file="${junit.output.dir}"/>
|
<sysproperty key="tempDir" file="${junit.output.dir}"/>
|
||||||
<sysproperty key="testmethod" value="${testmethod}"/>
|
<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}"/>
|
<jvmarg line="${args}"/>
|
||||||
<formatter classname="${junit.details.formatter}" usefile="false" if="junit.details"/>
|
<formatter classname="${junit.details.formatter}" usefile="false" if="junit.details"/>
|
||||||
<classpath refid="test.classpath"/>
|
<classpath refid="test.classpath"/>
|
||||||
|
|
|
@ -131,6 +131,8 @@
|
||||||
<sysproperty key="jetty.testMode" value="1"/>
|
<sysproperty key="jetty.testMode" value="1"/>
|
||||||
<sysproperty key="tempDir" file="${junit.output.dir}"/>
|
<sysproperty key="tempDir" file="${junit.output.dir}"/>
|
||||||
<sysproperty key="testmethod" value="${testmethod}"/>
|
<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}"/>
|
<jvmarg line="${args}"/>
|
||||||
<formatter classname="${junit.details.formatter}" usefile="false" if="junit.details"/>
|
<formatter classname="${junit.details.formatter}" usefile="false" if="junit.details"/>
|
||||||
<classpath refid="test.classpath"/>
|
<classpath refid="test.classpath"/>
|
||||||
|
|
|
@ -183,6 +183,8 @@
|
||||||
<sysproperty key="jetty.testMode" value="1"/>
|
<sysproperty key="jetty.testMode" value="1"/>
|
||||||
<sysproperty key="tempDir" file="${tempDir}"/>
|
<sysproperty key="tempDir" file="${tempDir}"/>
|
||||||
<sysproperty key="testmethod" value="${testmethod}"/>
|
<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}"/>
|
<jvmarg line="${args}"/>
|
||||||
<formatter classname="${junit.details.formatter}" usefile="false" if="junit.details"/>
|
<formatter classname="${junit.details.formatter}" usefile="false" if="junit.details"/>
|
||||||
<classpath refid="test.classpath"/>
|
<classpath refid="test.classpath"/>
|
||||||
|
@ -245,6 +247,8 @@
|
||||||
<sysproperty key="jetty.testMode" value="1"/>
|
<sysproperty key="jetty.testMode" value="1"/>
|
||||||
<sysproperty key="tempDir" file="${tempDir}"/>
|
<sysproperty key="tempDir" file="${tempDir}"/>
|
||||||
<sysproperty key="testmethod" value="${testmethod}"/>
|
<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}"/>
|
<jvmarg line="${args}"/>
|
||||||
<formatter classname="${junit.details.formatter}" usefile="false" if="junit.details"/>
|
<formatter classname="${junit.details.formatter}" usefile="false" if="junit.details"/>
|
||||||
<classpath refid="test.extras.classpath"/>
|
<classpath refid="test.extras.classpath"/>
|
||||||
|
|
|
@ -128,6 +128,8 @@
|
||||||
<sysproperty key="jetty.testMode" value="1"/>
|
<sysproperty key="jetty.testMode" value="1"/>
|
||||||
<sysproperty key="tempDir" file="${tempDir}"/>
|
<sysproperty key="tempDir" file="${tempDir}"/>
|
||||||
<sysproperty key="testmethod" value="${testmethod}"/>
|
<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}"/>
|
<jvmarg line="${args}"/>
|
||||||
<formatter classname="${junit.details.formatter}" usefile="false" if="junit.details"/>
|
<formatter classname="${junit.details.formatter}" usefile="false" if="junit.details"/>
|
||||||
<classpath refid="test.classpath"/>
|
<classpath refid="test.classpath"/>
|
||||||
|
|
|
@ -124,6 +124,8 @@
|
||||||
<sysproperty key="jetty.insecurerandom" value="1"/>
|
<sysproperty key="jetty.insecurerandom" value="1"/>
|
||||||
<sysproperty key="tempDir" file="${tempDir}"/>
|
<sysproperty key="tempDir" file="${tempDir}"/>
|
||||||
<sysproperty key="testmethod" value="${testmethod}"/>
|
<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}"/>
|
<jvmarg line="${args}"/>
|
||||||
<formatter classname="${junit.details.formatter}" usefile="false" if="junit.details"/>
|
<formatter classname="${junit.details.formatter}" usefile="false" if="junit.details"/>
|
||||||
<classpath refid="test.classpath"/>
|
<classpath refid="test.classpath"/>
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
package org.apache.solr;
|
package org.apache.solr;
|
||||||
|
|
||||||
|
|
||||||
|
import org.apache.lucene.store.MockDirectoryWrapper;
|
||||||
import org.apache.lucene.util.LuceneTestCase;
|
import org.apache.lucene.util.LuceneTestCase;
|
||||||
import org.apache.noggit.CharArr;
|
import org.apache.noggit.CharArr;
|
||||||
import org.apache.noggit.JSONUtil;
|
import org.apache.noggit.JSONUtil;
|
||||||
|
@ -73,6 +74,16 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
|
||||||
endTrackingSearchers();
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
@ -270,6 +281,7 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
|
||||||
public static void deleteCore() throws Exception {
|
public static void deleteCore() throws Exception {
|
||||||
log.info("###deleteCore" );
|
log.info("###deleteCore" );
|
||||||
if (h != null) { h.close(); }
|
if (h != null) { h.close(); }
|
||||||
|
closeDirectories();
|
||||||
if (dataDir != null) {
|
if (dataDir != null) {
|
||||||
String skip = System.getProperty("solr.test.leavedatadir");
|
String skip = System.getProperty("solr.test.leavedatadir");
|
||||||
if (null != skip && 0 != skip.trim().length()) {
|
if (null != skip && 0 != skip.trim().length()) {
|
||||||
|
|
|
@ -191,6 +191,7 @@ public abstract class AbstractSolrTestCase extends LuceneTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (h != null) { h.close(); }
|
if (h != null) { h.close(); }
|
||||||
|
SolrTestCaseJ4.closeDirectories();
|
||||||
String skip = System.getProperty("solr.test.leavedatadir");
|
String skip = System.getProperty("solr.test.leavedatadir");
|
||||||
if (null != skip && 0 != skip.trim().length()) {
|
if (null != skip && 0 != skip.trim().length()) {
|
||||||
System.err.println("NOTE: per solr.test.leavedatadir, dataDir will not be removed: " + dataDir.getAbsolutePath());
|
System.err.println("NOTE: per solr.test.leavedatadir, dataDir will not be removed: " + dataDir.getAbsolutePath());
|
||||||
|
|
|
@ -59,6 +59,7 @@ public class TestSolrCoreProperties extends LuceneTestCase {
|
||||||
@Override
|
@Override
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
solrJetty.stop();
|
solrJetty.stop();
|
||||||
|
SolrTestCaseJ4.closeDirectories();
|
||||||
AbstractSolrTestCase.recurseDelete(homeDir);
|
AbstractSolrTestCase.recurseDelete(homeDir);
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,6 +78,7 @@ public class JettyWebappTest extends LuceneTestCase
|
||||||
try {
|
try {
|
||||||
server.stop();
|
server.stop();
|
||||||
} catch( Exception ex ) {}
|
} catch( Exception ex ) {}
|
||||||
|
SolrTestCaseJ4.closeDirectories();
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,8 @@ public class MergeIndexesEmbeddedTest extends MergeIndexesExampleTestBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
// TODO: fix this test to use MockDirectoryFactory
|
||||||
|
System.clearProperty("solr.directoryFactory");
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
File home = new File(getSolrHome());
|
File home = new File(getSolrHome());
|
||||||
|
|
|
@ -38,6 +38,8 @@ public class MultiCoreExampleJettyTest extends MultiCoreExampleTestBase {
|
||||||
|
|
||||||
@Override public void setUp() throws Exception
|
@Override public void setUp() throws Exception
|
||||||
{
|
{
|
||||||
|
// TODO: fix this test to use MockDirectoryFactory
|
||||||
|
System.clearProperty("solr.directoryFactory");
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
jetty = new JettySolrRunner( context, 0 );
|
jetty = new JettySolrRunner( context, 0 );
|
||||||
|
|
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue