From 7f5305ecfc486c6b34fb399471f22ae99ace2d0b Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Wed, 1 Jun 2011 08:22:23 +0000 Subject: [PATCH] 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 --- .../apache/lucene/util/LuceneTestCase.java | 2 +- solr/build.xml | 5 ++- solr/common-build.xml | 1 + solr/contrib/analysis-extras/build.xml | 2 ++ solr/contrib/clustering/build.xml | 2 ++ solr/contrib/dataimporthandler/build.xml | 4 +++ solr/contrib/extraction/build.xml | 2 ++ solr/contrib/uima/build.xml | 2 ++ .../org/apache/solr/SolrTestCaseJ4.java | 12 +++++++ .../solr/util/AbstractSolrTestCase.java | 1 + .../apache/solr/TestSolrCoreProperties.java | 1 + .../solrj/embedded/JettyWebappTest.java | 1 + .../embedded/MergeIndexesEmbeddedTest.java | 2 ++ .../embedded/MultiCoreExampleJettyTest.java | 2 ++ .../solr/core/MockDirectoryFactory.java | 35 +++++++++++++++++++ 15 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 solr/src/test/org/apache/solr/core/MockDirectoryFactory.java diff --git a/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java b/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java index 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 stores; + protected static Map stores; private static final String[] TEST_CODECS = new String[] {"MockSep", "MockFixedIntBlock", "MockVariableIntBlock", "MockRandom"}; diff --git a/solr/build.xml b/solr/build.xml index a1f90570756..8ca35e2b0d1 100644 --- a/solr/build.xml +++ b/solr/build.xml @@ -463,9 +463,8 @@ - + + diff --git a/solr/common-build.xml b/solr/common-build.xml index cdda84e1936..d5671ea379d 100644 --- a/solr/common-build.xml +++ b/solr/common-build.xml @@ -68,6 +68,7 @@ + diff --git a/solr/contrib/analysis-extras/build.xml b/solr/contrib/analysis-extras/build.xml index 6ec8ecdbaa8..8fd22d099fb 100644 --- a/solr/contrib/analysis-extras/build.xml +++ b/solr/contrib/analysis-extras/build.xml @@ -159,6 +159,8 @@ + + diff --git a/solr/contrib/clustering/build.xml b/solr/contrib/clustering/build.xml index 9a0c67eaa2f..896b87ed8df 100644 --- a/solr/contrib/clustering/build.xml +++ b/solr/contrib/clustering/build.xml @@ -131,6 +131,8 @@ + + diff --git a/solr/contrib/dataimporthandler/build.xml b/solr/contrib/dataimporthandler/build.xml index 79a0524fcc7..a173dc0c5a7 100644 --- a/solr/contrib/dataimporthandler/build.xml +++ b/solr/contrib/dataimporthandler/build.xml @@ -183,6 +183,8 @@ + + @@ -245,6 +247,8 @@ + + diff --git a/solr/contrib/extraction/build.xml b/solr/contrib/extraction/build.xml index 50dcb4983d5..e0ea1ff00f6 100644 --- a/solr/contrib/extraction/build.xml +++ b/solr/contrib/extraction/build.xml @@ -128,6 +128,8 @@ + + diff --git a/solr/contrib/uima/build.xml b/solr/contrib/uima/build.xml index 16c7de67844..95e2060f7b3 100644 --- a/solr/contrib/uima/build.xml +++ b/solr/contrib/uima/build.xml @@ -124,6 +124,8 @@ + + diff --git a/solr/src/test-framework/org/apache/solr/SolrTestCaseJ4.java b/solr/src/test-framework/org/apache/solr/SolrTestCaseJ4.java index 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(); + } + } + } @Override public 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.java index 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.java index 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 { @Override public 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.java index 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 LuceneTestCase try { 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.java index 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 { @Override public 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.java index 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.java new file mode 100644 index 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)); + } +}