mirror of https://github.com/apache/lucene.git
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
This commit is contained in:
parent
495e614234
commit
4794d1eb63
|
@ -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 ====================
|
||||
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -427,6 +427,7 @@
|
|||
failureProperty="tests.failed"
|
||||
dir="src/test/test-files/"
|
||||
tempdir="@{tempDir}/@{threadNum}"
|
||||
forkmode="perBatch"
|
||||
>
|
||||
<sysproperty key="java.util.logging.config.file" value="${common-solr.dir}/testlogging.properties"/>
|
||||
<sysproperty key="tests.luceneMatchVersion" value="${tests.luceneMatchVersion}"/>
|
||||
|
|
|
@ -106,6 +106,7 @@
|
|||
failureProperty="tests.failed"
|
||||
dir="src/test/resources/"
|
||||
tempdir="${junit.output.dir}"
|
||||
forkmode="perBatch"
|
||||
>
|
||||
<sysproperty key="java.util.logging.config.file" value="${common-solr.dir}/testlogging.properties"/>
|
||||
<sysproperty key="tests.luceneMatchVersion" value="${tests.luceneMatchVersion}"/>
|
||||
|
|
|
@ -158,6 +158,7 @@
|
|||
failureProperty="tests.failed"
|
||||
dir="src/test/resources/"
|
||||
tempdir="${tempDir}"
|
||||
forkmode="perBatch"
|
||||
>
|
||||
<sysproperty key="java.util.logging.config.file" value="${common-solr.dir}/testlogging.properties"/>
|
||||
<sysproperty key="tests.luceneMatchVersion" value="${tests.luceneMatchVersion}"/>
|
||||
|
@ -214,6 +215,7 @@
|
|||
failureProperty="tests.failed"
|
||||
dir="src/extras/test/resources/"
|
||||
tempdir="${tempDir}"
|
||||
forkmode="perBatch"
|
||||
>
|
||||
<sysproperty key="java.util.logging.config.file" value="${common-solr.dir}/testlogging.properties"/>
|
||||
<sysproperty key="tests.luceneMatchVersion" value="${tests.luceneMatchVersion}"/>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -107,6 +107,7 @@
|
|||
failureProperty="tests.failed"
|
||||
dir="src/test/resources/"
|
||||
tempdir="${tempDir}"
|
||||
forkmode="perBatch"
|
||||
>
|
||||
<sysproperty key="java.util.logging.config.file" value="${common-solr.dir}/testlogging.properties"/>
|
||||
<sysproperty key="tests.luceneMatchVersion" value="${tests.luceneMatchVersion}"/>
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
|
|
|
@ -50,6 +50,7 @@ abstract public class SolrJettyTestBase extends SolrTestCaseJ4
|
|||
jetty.stop();
|
||||
jetty = null;
|
||||
}
|
||||
server = null;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue