From 4794d1eb639d65459176fdb9765b3ef5ec25c47f Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Fri, 3 Sep 2010 19:14:03 +0000 Subject: [PATCH] LUCENE-2611: fix tests to run in IntelliJ, dont fork solr tests git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@992424 13f79535-47bb-0310-9956-ffa450edef68 --- lucene/CHANGES.txt | 5 ++- .../apache/lucene/util/LuceneTestCase.java | 3 +- .../apache/lucene/util/LuceneTestCaseJ4.java | 39 +++++++++---------- solr/build.xml | 1 + solr/contrib/clustering/build.xml | 1 + solr/contrib/dataimporthandler/build.xml | 2 + .../TestContentStreamDataSource.java | 26 +++++++++---- .../dataimport/TestVariableResolver.java | 12 ++++++ solr/contrib/extraction/build.xml | 1 + .../test/org/apache/solr/SolrTestCaseJ4.java | 2 +- .../apache/solr/TestSolrCoreProperties.java | 10 +++-- .../solr/client/solrj/SolrJettyTestBase.java | 1 + .../solr/schema/BadIndexSchemaTest.java | 3 ++ .../apache/solr/schema/TestBinaryField.java | 23 ++++------- 14 files changed, 77 insertions(+), 52 deletions(-) diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 72b969ab14d..f98221b4ca8 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -721,8 +721,9 @@ Test Cases access to "real" files from the test folder itsself, can use LuceneTestCase(J4).getDataFile(). (Uwe Schindler) -* LUCENE-2398: Improve tests to work better from IDEs such as Eclipse. - (Paolo Castagna via Robert Muir) +* LUCENE-2398, LUCENE-2611: Improve tests to work better from IDEs such + as Eclipse and IntelliJ. + (Paolo Castagna, Steven Rowe via Robert Muir) ================== Release 2.9.3 / 3.0.2 2010-06-18 ==================== diff --git a/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java b/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java index bbe8dbfc872..cae00bf8527 100644 --- a/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java +++ b/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java @@ -186,7 +186,8 @@ public abstract class LuceneTestCase extends TestCase { LuceneTestCaseJ4.removeTestCodecs(codec); Locale.setDefault(savedLocale); TimeZone.setDefault(savedTimeZone); - + System.clearProperty("solr.solr.home"); + System.clearProperty("solr.data.dir"); try { Thread.setDefaultUncaughtExceptionHandler(savedUncaughtExceptionHandler); if (!uncaughtExceptions.isEmpty()) { diff --git a/lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java b/lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java index 76002f9f8d8..113e5a0dcbd 100644 --- a/lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java +++ b/lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java @@ -23,23 +23,21 @@ import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.LogDocMergePolicy; import org.apache.lucene.index.LogMergePolicy; import org.apache.lucene.index.SerialMergeScheduler; +import org.apache.lucene.index.codecs.Codec; +import org.apache.lucene.index.codecs.CodecProvider; +import org.apache.lucene.index.codecs.mockintblock.MockFixedIntBlockCodec; +import org.apache.lucene.index.codecs.mockintblock.MockVariableIntBlockCodec; +import org.apache.lucene.index.codecs.mocksep.MockSepCodec; +import org.apache.lucene.index.codecs.preflex.PreFlexCodec; +import org.apache.lucene.index.codecs.preflexrw.PreFlexRWCodec; +import org.apache.lucene.index.codecs.pulsing.PulsingCodec; import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.FieldCache; import org.apache.lucene.search.FieldCache.CacheEntry; import org.apache.lucene.store.Directory; import org.apache.lucene.store.MMapDirectory; import org.apache.lucene.store.MockDirectoryWrapper; -import org.apache.lucene.store.RAMDirectory; import org.apache.lucene.util.FieldCacheSanityChecker.Insanity; -import org.apache.lucene.index.codecs.CodecProvider; -import org.apache.lucene.index.codecs.Codec; -import org.apache.lucene.index.codecs.preflexrw.PreFlexRWCodec; -import org.apache.lucene.index.codecs.preflex.PreFlexCodec; -import org.apache.lucene.index.codecs.pulsing.PulsingCodec; -import org.apache.lucene.index.codecs.mocksep.MockSepCodec; -import org.apache.lucene.index.codecs.mockintblock.MockFixedIntBlockCodec; -import org.apache.lucene.index.codecs.mockintblock.MockVariableIntBlockCodec; - import org.junit.After; import org.junit.AfterClass; import org.junit.Assert; @@ -58,24 +56,23 @@ import org.junit.runners.model.FrameworkMethod; import org.junit.runners.model.InitializationError; import java.io.File; -import java.io.PrintStream; import java.io.IOException; +import java.io.PrintStream; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.IdentityHashMap; import java.util.Iterator; -import java.util.Locale; -import java.util.Random; -import java.util.ArrayList; import java.util.List; +import java.util.Locale; import java.util.Map; +import java.util.Random; import java.util.TimeZone; import java.util.WeakHashMap; -import java.util.Collections; -import java.util.regex.Pattern; import java.util.regex.Matcher; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; +import java.util.regex.Pattern; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; @@ -116,7 +113,7 @@ import static org.junit.Assert.fail; // get from that override is provided by InterceptTestCaseEvents //@RunWith(RunBareWrapper.class) @RunWith(LuceneTestCaseJ4.LuceneTestCaseRunner.class) -public class LuceneTestCaseJ4 { +public abstract class LuceneTestCaseJ4 { /** * true iff tests are run in verbose mode. Note: if it is false, tests are not @@ -303,6 +300,8 @@ public class LuceneTestCaseJ4 { removeTestCodecs(codec); Locale.setDefault(savedLocale); TimeZone.setDefault(savedTimeZone); + System.clearProperty("solr.solr.home"); + System.clearProperty("solr.data.dir"); // now look for unclosed resources for (MockDirectoryWrapper d : stores.keySet()) { if (d.isOpen()) { diff --git a/solr/build.xml b/solr/build.xml index 3e222d51806..cb8cbb6d166 100644 --- a/solr/build.xml +++ b/solr/build.xml @@ -427,6 +427,7 @@ failureProperty="tests.failed" dir="src/test/test-files/" tempdir="@{tempDir}/@{threadNum}" + forkmode="perBatch" > diff --git a/solr/contrib/clustering/build.xml b/solr/contrib/clustering/build.xml index 090e1210df0..1fde0a65246 100644 --- a/solr/contrib/clustering/build.xml +++ b/solr/contrib/clustering/build.xml @@ -106,6 +106,7 @@ failureProperty="tests.failed" dir="src/test/resources/" tempdir="${junit.output.dir}" + forkmode="perBatch" > diff --git a/solr/contrib/dataimporthandler/build.xml b/solr/contrib/dataimporthandler/build.xml index 8ba2cbb9637..8e3080abafe 100644 --- a/solr/contrib/dataimporthandler/build.xml +++ b/solr/contrib/dataimporthandler/build.xml @@ -158,6 +158,7 @@ failureProperty="tests.failed" dir="src/test/resources/" tempdir="${tempDir}" + forkmode="perBatch" > @@ -214,6 +215,7 @@ failureProperty="tests.failed" dir="src/extras/test/resources/" tempdir="${tempDir}" + forkmode="perBatch" > diff --git a/solr/contrib/dataimporthandler/src/test/java/org/apache/solr/handler/dataimport/TestContentStreamDataSource.java b/solr/contrib/dataimporthandler/src/test/java/org/apache/solr/handler/dataimport/TestContentStreamDataSource.java index f713949b40f..fdc4f0c3b53 100644 --- a/solr/contrib/dataimporthandler/src/test/java/org/apache/solr/handler/dataimport/TestContentStreamDataSource.java +++ b/solr/contrib/dataimporthandler/src/test/java/org/apache/solr/handler/dataimport/TestContentStreamDataSource.java @@ -27,6 +27,10 @@ import org.apache.solr.common.SolrDocument; import org.apache.solr.common.SolrDocumentList; import org.apache.solr.common.params.ModifiableSolrParams; import org.apache.solr.util.AbstractSolrTestCase; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.*; import java.io.File; import java.util.List; @@ -37,19 +41,27 @@ import java.util.List; * @version $Id$ * @since solr 1.4 */ -public class TestContentStreamDataSource extends TestCase { +public class TestContentStreamDataSource extends SolrTestCaseJ4 { private static final String CONF_DIR = "." + File.separator + "solr" + File.separator + "conf" + File.separator; SolrInstance instance = null; JettySolrRunner jetty; - + @Before public void setUp() throws Exception { + super.setUp(); instance = new SolrInstance("inst", null); instance.setUp(); jetty = createJetty(instance); - + } + + @After + public void tearDown() throws Exception { + jetty.stop(); + instance.tearDown(); + super.tearDown(); } + @Test public void testSimple() throws Exception { DirectXmlRequest req = new DirectXmlRequest("/dataimport", xml); ModifiableSolrParams params = new ModifiableSolrParams(); @@ -69,12 +81,13 @@ public class TestContentStreamDataSource extends TestCase { assertEquals("Hello C1", ((List)doc.getFieldValue("desc")).get(0)); } - private class SolrInstance extends AbstractSolrTestCase { + private class SolrInstance { String name; Integer port; File homeDir; File confDir; - + File dataDir; + /** * if masterPort is null, this instance is a master -- otherwise this instance is a slave, and assumes the master is * on localhost at the specified port. @@ -88,7 +101,6 @@ public class TestContentStreamDataSource extends TestCase { return homeDir.toString(); } - @Override public String getSchemaFile() { return CONF_DIR + "dataimport-schema.xml"; } @@ -101,7 +113,6 @@ public class TestContentStreamDataSource extends TestCase { return dataDir.toString(); } - @Override public String getSolrConfigFile() { return CONF_DIR + "contentstream-solrconfig.xml"; } @@ -130,7 +141,6 @@ public class TestContentStreamDataSource extends TestCase { } public void tearDown() throws Exception { - super.tearDown(); AbstractSolrTestCase.recurseDelete(homeDir); } } diff --git a/solr/contrib/dataimporthandler/src/test/java/org/apache/solr/handler/dataimport/TestVariableResolver.java b/solr/contrib/dataimporthandler/src/test/java/org/apache/solr/handler/dataimport/TestVariableResolver.java index c711a238e6c..f4bd48b3ad4 100644 --- a/solr/contrib/dataimporthandler/src/test/java/org/apache/solr/handler/dataimport/TestVariableResolver.java +++ b/solr/contrib/dataimporthandler/src/test/java/org/apache/solr/handler/dataimport/TestVariableResolver.java @@ -113,6 +113,7 @@ public class TestVariableResolver extends SolrTestCaseJ4 { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); format.setTimeZone(TimeZone.getTimeZone("UTC")); + resetEvaluatorBagDateMathParser(); DateMathParser dmp = new DateMathParser(TimeZone.getDefault(), Locale.getDefault()); String s = vri.replaceTokens("${dataimporter.functions.formatDate('NOW/DAY','yyyy-MM-dd HH:mm')}"); @@ -154,6 +155,7 @@ public class TestVariableResolver extends SolrTestCaseJ4 { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); format.setTimeZone(TimeZone.getTimeZone("UTC")); + resetEvaluatorBagDateMathParser(); DateMathParser dmp = new DateMathParser(TimeZone.getDefault(), Locale.getDefault()); resolver.addNamespace("dataimporter.functions", EvaluatorBag @@ -174,4 +176,14 @@ public class TestVariableResolver extends SolrTestCaseJ4 { return "Hello World"; } } + + private void resetEvaluatorBagDateMathParser() { + EvaluatorBag.dateMathParser = new DateMathParser(TimeZone + .getDefault(), Locale.getDefault()){ + @Override + public Date getNow() { + return new Date(); + } + }; + } } diff --git a/solr/contrib/extraction/build.xml b/solr/contrib/extraction/build.xml index 805d3a1a7e2..ac85cd99d86 100644 --- a/solr/contrib/extraction/build.xml +++ b/solr/contrib/extraction/build.xml @@ -107,6 +107,7 @@ failureProperty="tests.failed" dir="src/test/resources/" tempdir="${tempDir}" + forkmode="perBatch" > diff --git a/solr/src/test/org/apache/solr/SolrTestCaseJ4.java b/solr/src/test/org/apache/solr/SolrTestCaseJ4.java index 3fdd75c0581..83c24950f0b 100755 --- a/solr/src/test/org/apache/solr/SolrTestCaseJ4.java +++ b/solr/src/test/org/apache/solr/SolrTestCaseJ4.java @@ -51,7 +51,7 @@ import static org.junit.Assert.fail; * Unlike AbstractSolrTestCase, a new core is not created for each test method. * */ -public class SolrTestCaseJ4 extends LuceneTestCaseJ4 { +public abstract class SolrTestCaseJ4 extends LuceneTestCaseJ4 { @BeforeClass public static void beforeClassSolrTestCase() throws Exception { diff --git a/solr/src/test/org/apache/solr/TestSolrCoreProperties.java b/solr/src/test/org/apache/solr/TestSolrCoreProperties.java index 6cda2ad7e5f..89d293628c4 100644 --- a/solr/src/test/org/apache/solr/TestSolrCoreProperties.java +++ b/solr/src/test/org/apache/solr/TestSolrCoreProperties.java @@ -16,6 +16,7 @@ */ package org.apache.solr; +import org.apache.lucene.util.LuceneTestCase; import org.apache.solr.util.AbstractSolrTestCase; import org.apache.solr.client.solrj.embedded.JettySolrRunner; import org.apache.solr.client.solrj.SolrServer; @@ -35,17 +36,18 @@ import java.util.Properties; * @version $Id$ * @since solr 1.4 */ -public class TestSolrCoreProperties extends AbstractSolrTestCase { +public class TestSolrCoreProperties extends LuceneTestCase { private static final String CONF_DIR = "." + File.separator + "solr" + File.separator + "conf" + File.separator; JettySolrRunner solrJetty; SolrServer client; @Override public void setUp() throws Exception { + super.setUp(); setUpMe(); System.setProperty("solr.solr.home", getHomeDir()); System.setProperty("solr.data.dir", getDataDir()); - + solrJetty = new JettySolrRunner("/solr", 0); solrJetty.start(); @@ -58,6 +60,7 @@ public class TestSolrCoreProperties extends AbstractSolrTestCase { public void tearDown() throws Exception { solrJetty.stop(); AbstractSolrTestCase.recurseDelete(homeDir); + super.tearDown(); } public void testSimple() throws SolrServerException { @@ -70,6 +73,7 @@ public class TestSolrCoreProperties extends AbstractSolrTestCase { File homeDir; File confDir; + File dataDir; /** * if masterPort is null, this instance is a master -- otherwise this instance is a slave, and assumes the master is @@ -81,7 +85,6 @@ public class TestSolrCoreProperties extends AbstractSolrTestCase { return homeDir.toString(); } - @Override public String getSchemaFile() { return CONF_DIR + "schema-replication1.xml"; } @@ -94,7 +97,6 @@ public class TestSolrCoreProperties extends AbstractSolrTestCase { return dataDir.toString(); } - @Override public String getSolrConfigFile() { return CONF_DIR + "solrconfig-solcoreproperties.xml"; } diff --git a/solr/src/test/org/apache/solr/client/solrj/SolrJettyTestBase.java b/solr/src/test/org/apache/solr/client/solrj/SolrJettyTestBase.java index 9eac8e926e7..2042a2577b3 100755 --- a/solr/src/test/org/apache/solr/client/solrj/SolrJettyTestBase.java +++ b/solr/src/test/org/apache/solr/client/solrj/SolrJettyTestBase.java @@ -50,6 +50,7 @@ abstract public class SolrJettyTestBase extends SolrTestCaseJ4 jetty.stop(); jetty = null; } + server = null; } diff --git a/solr/src/test/org/apache/solr/schema/BadIndexSchemaTest.java b/solr/src/test/org/apache/solr/schema/BadIndexSchemaTest.java index ccaa71632aa..96e506010bd 100644 --- a/solr/src/test/org/apache/solr/schema/BadIndexSchemaTest.java +++ b/solr/src/test/org/apache/solr/schema/BadIndexSchemaTest.java @@ -20,6 +20,7 @@ package org.apache.solr.schema; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrException.ErrorCode; +import org.apache.solr.core.SolrConfig; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -43,6 +44,8 @@ public class BadIndexSchemaTest extends SolrTestCaseJ4 { throw new SolrException (ErrorCode.SERVER_ERROR, "Unexpected error, expected error matching: " + errString, e); + } finally { + SolrConfig.severeErrors.clear(); } fail("Did not encounter any exception from: " + schema); } diff --git a/solr/src/test/org/apache/solr/schema/TestBinaryField.java b/solr/src/test/org/apache/solr/schema/TestBinaryField.java index 80fc7659dd8..99976215162 100644 --- a/solr/src/test/org/apache/solr/schema/TestBinaryField.java +++ b/solr/src/test/org/apache/solr/schema/TestBinaryField.java @@ -17,6 +17,8 @@ package org.apache.solr.schema; import junit.framework.TestCase; + +import org.apache.lucene.util.LuceneTestCase; import org.apache.solr.client.solrj.SolrQuery; import org.apache.solr.client.solrj.beans.Field; import org.apache.solr.client.solrj.embedded.JettySolrRunner; @@ -32,26 +34,19 @@ import java.nio.ByteBuffer; import java.io.File; import java.util.List; -public class TestBinaryField extends AbstractSolrTestCase { +public class TestBinaryField extends LuceneTestCase { CommonsHttpSolrServer server; JettySolrRunner jetty; int port = 0; static final String context = "/example"; - - public String getSchemaFile() { - return null; - } - public String getSolrConfigFile() { - return null; - } - @Override public void setUp() throws Exception { super.setUp(); - File home = dataDir; + File home = new File(TEMP_DIR, + "solrtest-TestBinaryField-" + System.currentTimeMillis()); File homeDir = new File(home, "example"); File dataDir = new File(homeDir, "data"); @@ -67,12 +62,10 @@ public class TestBinaryField extends AbstractSolrTestCase { f = new File(confDir, "schema.xml"); fname = "." + File.separator + "solr" + File.separator + "conf" + File.separator + "schema-binaryfield.xml"; FileUtils.copyFile(new File(fname), f); - - jetty = new JettySolrRunner("/solr", port); System.setProperty("solr.solr.home", homeDir.getAbsolutePath()); System.setProperty("solr.data.dir", dataDir.getAbsolutePath()); - jetty.start(); - + System.setProperty("solr.test.sys.prop1", "propone"); + System.setProperty("solr.test.sys.prop2", "proptwo"); jetty = new JettySolrRunner(context, 0); jetty.start(); @@ -80,8 +73,6 @@ public class TestBinaryField extends AbstractSolrTestCase { String url = "http://localhost:" + jetty.getLocalPort() + context; server = new CommonsHttpSolrServer(url); -// server.setRequestWriter(new BinaryRequestWriter()); - super.postSetUp(); } public void testSimple() throws Exception {