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:
Robert Muir 2011-06-01 08:22:23 +00:00
parent a890a8f5b0
commit 7f5305ecfc
15 changed files with 70 additions and 4 deletions

View File

@ -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"};

View File

@ -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"/>

View File

@ -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"/>

View File

@ -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"/>

View File

@ -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"/>

View File

@ -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"/>

View File

@ -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"/>

View File

@ -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"/>

View File

@ -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;
@ -73,6 +74,16 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
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
public void setUp() throws Exception {
super.setUp();
@ -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()) {

View File

@ -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());

View File

@ -59,6 +59,7 @@ public class TestSolrCoreProperties extends LuceneTestCase {
@Override
public void tearDown() throws Exception {
solrJetty.stop();
SolrTestCaseJ4.closeDirectories();
AbstractSolrTestCase.recurseDelete(homeDir);
super.tearDown();
}

View File

@ -78,6 +78,7 @@ public class JettyWebappTest extends LuceneTestCase
try {
server.stop();
} catch( Exception ex ) {}
SolrTestCaseJ4.closeDirectories();
super.tearDown();
}

View File

@ -33,6 +33,8 @@ public class MergeIndexesEmbeddedTest extends MergeIndexesExampleTestBase {
@Override
public void setUp() throws Exception {
// TODO: fix this test to use MockDirectoryFactory
System.clearProperty("solr.directoryFactory");
super.setUp();
File home = new File(getSolrHome());

View File

@ -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 );

View File

@ -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));
}
}