|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.junit.Assert org.apache.lucene.util.LuceneTestCase org.apache.solr.SolrTestCaseJ4
public abstract class SolrTestCaseJ4
A junit4 Solr test harness that extends LuceneTestCaseJ4. To change which core is used when loading the schema and solrconfig.xml, simply
invoke the initCore(String, String, String, String)
method.
Unlike AbstractSolrTestCase
, a new core is not created for each test method.
Nested Class Summary | |
---|---|
static class |
SolrTestCaseJ4.CoreDescriptorBuilder
|
static class |
SolrTestCaseJ4.Doc
|
static class |
SolrTestCaseJ4.Fld
|
protected class |
SolrTestCaseJ4.FldType
|
static class |
SolrTestCaseJ4.FVal
|
static class |
SolrTestCaseJ4.IRange
|
static class |
SolrTestCaseJ4.IVals
|
static class |
SolrTestCaseJ4.SVal
|
static class |
SolrTestCaseJ4.Vals
|
static class |
SolrTestCaseJ4.XmlDoc
Necessary to make method signatures un-ambiguous |
Nested classes/interfaces inherited from class org.apache.lucene.util.LuceneTestCase |
---|
org.apache.lucene.util.LuceneTestCase.AwaitsFix, org.apache.lucene.util.LuceneTestCase.BadApple, org.apache.lucene.util.LuceneTestCase.Nightly, org.apache.lucene.util.LuceneTestCase.Slow, org.apache.lucene.util.LuceneTestCase.SuppressCodecs, org.apache.lucene.util.LuceneTestCase.Weekly |
Field Summary | |
---|---|
protected static String |
configString
|
protected static File |
dataDir
The directory used to story the index managed by the TestHarness h |
static int |
DEFAULT_CONNECTION_TIMEOUT
|
static org.apache.solr.SolrLogFormatter |
formatter
|
protected static TestHarness |
h
Harness initialized by initTestHarness. |
protected static String |
hdfsDataDir
|
static org.slf4j.Logger |
log
Initializes things your test might need Creates a dataDir in the "java.io.tmpdir" initializes the TestHarness h using this data directory, and getSchemaPath() initializes the LocalRequestFactory lrf using sensible defaults. |
protected static TestHarness.LocalRequestFactory |
lrf
LocalRequestFactory initialized by initTestHarness using sensible defaults. |
static SolrTestCaseJ4.IRange |
ONE_ONE
|
protected static String |
schemaString
|
static org.junit.rules.TestRule |
solrClassRules
|
protected static org.apache.solr.core.SolrConfig |
solrConfig
|
org.junit.rules.TestRule |
solrTestRules
|
protected static String |
testSolrHome
|
static SolrTestCaseJ4.IRange |
ZERO_ONE
|
static SolrTestCaseJ4.IRange |
ZERO_TWO
|
Fields inherited from class org.apache.lucene.util.LuceneTestCase |
---|
classRules, DEFAULT_LINE_DOCS_FILE, doesntSupportOffsets, INFOSTREAM, JENKINS_LARGE_LINE_DOCS_FILE, OLD_FORMAT_IMPERSONATION_IS_ACTIVE, PREFLEX_IMPERSONATION_IS_ACTIVE, RANDOM_MULTIPLIER, ruleChain, suiteFailureMarker, SYSPROP_AWAITSFIX, SYSPROP_BADAPPLES, SYSPROP_FAILFAST, SYSPROP_MAXFAILURES, SYSPROP_NIGHTLY, SYSPROP_SLOW, SYSPROP_WEEKLY, TEMP_DIR, TEST_AWAITSFIX, TEST_CODEC, TEST_DIRECTORY, TEST_DOCVALUESFORMAT, TEST_LINE_DOCS_FILE, TEST_NIGHTLY, TEST_POSTINGSFORMAT, TEST_SLOW, TEST_THROTTLING, TEST_VERSION_CURRENT, TEST_WEEKLY, VERBOSE |
Constructor Summary | |
---|---|
SolrTestCaseJ4()
|
Method Summary | |
---|---|
static String |
add(SolrTestCaseJ4.XmlDoc doc,
String... args)
Generates an <add><doc>... |
static Long |
addAndGetVersion(org.apache.solr.common.SolrInputDocument sdoc,
org.apache.solr.common.params.SolrParams params)
|
static String |
adoc(org.apache.solr.common.SolrInputDocument sdoc)
Generates a simple <add><doc>... |
static String |
adoc(String... fieldsAndValues)
Generates a simple <add><doc>... |
static void |
assertFailedU(String update)
Validates an update XML String failed |
static void |
assertFailedU(String message,
String update)
Validates an update XML String failed |
static void |
assertJQ(org.apache.solr.request.SolrQueryRequest req,
double delta,
String... tests)
Validates a query matches some JSON test expressions and closes the query. |
static void |
assertJQ(org.apache.solr.request.SolrQueryRequest req,
String... tests)
Validates a query matches some JSON test expressions using the default double delta tolerance. |
static void |
assertQ(org.apache.solr.request.SolrQueryRequest req,
String... tests)
Validates a query matches some XPath test expressions and closes the query |
static void |
assertQ(String message,
org.apache.solr.request.SolrQueryRequest req,
String... tests)
Validates a query matches some XPath test expressions and closes the query |
static void |
assertQEx(String message,
org.apache.solr.request.SolrQueryRequest req,
int code)
Makes sure a query throws a SolrException with the listed response code |
static void |
assertQEx(String message,
org.apache.solr.request.SolrQueryRequest req,
org.apache.solr.common.SolrException.ErrorCode code)
|
static void |
assertU(String update)
Validates an update XML String is successful |
static void |
assertU(String message,
String update)
Validates an update XML String is successful |
static void |
assertXmlFile(File file,
String... xpath)
|
static SolrTestCaseJ4.CoreDescriptorBuilder |
buildCoreDescriptor(org.apache.solr.core.CoreContainer container,
String name,
String instancedir)
|
void |
clearIndex()
|
static String |
commit(String... args)
|
static void |
copyMinConf(File dstRoot)
|
static void |
copyMinConf(File dstRoot,
String propertiesContent)
|
static void |
copyMinFullSetup(File dstRoot)
|
static void |
copySolrHomeToTemp(File dstRoot,
String collection)
|
static Comparator<SolrTestCaseJ4.Doc> |
createComparator(List<Comparator<SolrTestCaseJ4.Doc>> comparators)
|
static Comparator<SolrTestCaseJ4.Doc> |
createComparator(String field,
boolean asc,
boolean sortMissingLast,
boolean sortMissingFirst,
boolean sortMissingAsZero)
|
static void |
createCore()
|
static org.apache.solr.core.CoreContainer |
createCoreContainer(String solrHome,
String solrXML)
|
static org.apache.solr.core.CoreContainer |
createDefaultCoreContainer(String solrHome)
|
static SolrTestCaseJ4.Doc |
createDoc(List<SolrTestCaseJ4.FldType> descriptor)
|
static Comparator<SolrTestCaseJ4.Doc> |
createSort(org.apache.solr.schema.IndexSchema schema,
List<SolrTestCaseJ4.FldType> fieldTypes,
String[] out)
|
static void |
createTempDir()
|
static Long |
deleteAndGetVersion(String id,
org.apache.solr.common.params.SolrParams params)
|
static Long |
deleteByQueryAndGetVersion(String q,
org.apache.solr.common.params.SolrParams params)
|
static void |
deleteCore()
Shuts down the test harness, and makes the best attempt possible to delete dataDir, unless the system property "solr.test.leavedatadir" is set. |
static String |
delI(String id)
Generates a <delete>... |
static String |
delQ(String q)
Generates a <delete>... |
static SolrTestCaseJ4.XmlDoc |
doc(String... fieldsAndValues)
Generates a simple <doc>... |
static void |
endTrackingSearchers()
|
static void |
endTrackingZkClients()
|
protected static String |
getClassName()
|
static File |
getFile(String name)
Gets a resource from the context classloader as File . |
static Throwable |
getRootCause(Throwable t)
|
static String |
getSchemaFile()
Subclasses must define this method to return the name of the schema.xml they wish to use. |
protected static String |
getSimpleClassName()
|
static String |
getSolrConfigFile()
Subclasses must define this method to return the name of the solrconfig.xml they wish to use. |
static boolean |
hasInitException(Class<? extends Exception> exceptionType)
|
static boolean |
hasInitException(String message)
|
static void |
ignoreException(String pattern)
Causes an exception matching the regex pattern to not be logged. |
Map<Comparable,SolrTestCaseJ4.Doc> |
indexDocs(List<SolrTestCaseJ4.FldType> descriptor,
Map<Comparable,SolrTestCaseJ4.Doc> model,
int nDocs)
|
static void |
initCore()
|
static void |
initCore(String config,
String schema)
Call initCore in @BeforeClass to instantiate a solr core in your test class. |
static void |
initCore(String config,
String schema,
String solrHome)
Call initCore in @BeforeClass to instantiate a solr core in your test class. |
static void |
initCore(String config,
String schema,
String solrHome,
String pCoreName)
Call initCore in @BeforeClass to instantiate a solr core in your test class. |
Map<Comparable,List<Comparable>> |
invertField(Map<Comparable,SolrTestCaseJ4.Doc> model,
String field)
Return a Map from field value to a list of document ids |
static String |
JQ(org.apache.solr.request.SolrQueryRequest req)
Makes a query request and returns the JSON string response |
static String |
json(org.apache.solr.common.SolrInputDocument doc)
Creates JSON from a SolrInputDocument. |
static String |
json(String testJSON)
Converts "test JSON" and returns standard JSON. |
static String |
jsonAdd(org.apache.solr.common.SolrInputDocument... docs)
Creates a JSON add command from a SolrInputDocument list. |
static String |
jsonDelId(Object... ids)
Creates a JSON delete command from an id list |
static String |
jsonDelQ(String... queries)
Creates a JSON deleteByQuery command |
static Map |
map(Object... params)
|
static void |
newRandomConfig()
sets system properties based on LuceneTestCase.newIndexWriterConfig(org.apache.lucene.util.Version, org.apache.lucene.analysis.Analyzer)
configs can use these system properties to vary the indexwriter settings |
static String |
optimize(String... args)
|
static org.apache.solr.common.params.ModifiableSolrParams |
params(String... params)
|
void |
postSetUp()
Subclasses that override setUp can optionally call this method to log the fact that their setUp process has ended. |
void |
preTearDown()
Subclasses that override tearDown can optionally call this method to log the fact that the tearDown process has started. |
static boolean |
recurseDelete(File f)
|
static org.apache.solr.request.SolrQueryRequest |
req(org.apache.solr.common.params.SolrParams params,
String... moreParams)
Generates a SolrQueryRequest |
static org.apache.solr.request.SolrQueryRequest |
req(String... q)
Generates a SolrQueryRequest using the LocalRequestFactory |
static org.apache.solr.request.SolrQueryRequest |
req(String[] params,
String... moreParams)
Generates a SolrQueryRequest using the LocalRequestFactory |
static void |
resetExceptionIgnores()
|
static void |
resetFactory()
|
static org.apache.solr.common.SolrInputDocument |
sdoc(Object... fieldsAndValues)
|
static List<org.apache.solr.common.SolrInputDocument> |
sdocs(org.apache.solr.common.SolrInputDocument... docs)
|
static void |
setLoggingLevel(Level level)
|
void |
setUp()
|
static void |
setupLogging()
|
static void |
setupNoCoreTest(File solrHome,
String xmlStr)
Call this from @BeforeClass to set up the test harness and update handler with no cores. |
static void |
startTrackingSearchers()
|
static void |
startTrackingZkClients()
|
void |
tearDown()
|
static String |
TEST_HOME()
|
static String |
toJSON(SolrTestCaseJ4.Doc doc)
|
static void |
unIgnoreException(String pattern)
|
static String |
updateJ(String json,
org.apache.solr.common.params.SolrParams args)
Send JSON update commands |
static void |
useFactory(String factory)
Use a different directory factory. |
Methods inherited from class org.apache.lucene.util.LuceneTestCase |
---|
assertDeletedDocsEquals, assertDocsAndPositionsEnumEquals, assertDocsEnumEquals, assertDocsSkippingEquals, assertDocValuesEquals, assertDocValuesEquals, assertFieldInfosEquals, assertFieldsEquals, assertFieldStatisticsEquals, assertNormsEquals, assertPositionsSkippingEquals, assertReaderEquals, assertReaderStatisticsEquals, assertSaneFieldCaches, assertStoredFieldEquals, assertStoredFieldsEquals, assertTermsEnumEquals, assertTermsEquals, assertTermsStatisticsEquals, assertTermStatsEquals, assertTermVectorsEquals, asSet, assumeFalse, assumeNoException, assumeTrue, atLeast, atLeast, closeAfterSuite, closeAfterTest, defaultCodecSupportsDocsWithField, defaultCodecSupportsDocValues, defaultCodecSupportsSortedSet, dumpArray, dumpIterator, getDataFile, getOnlySegmentReader, getTestClass, getTestName, isTestThread, localeForName, maybeWrapReader, newAlcoholicMergePolicy, newAlcoholicMergePolicy, newDirectory, newDirectory, newDirectory, newDirectory, newField, newField, newFSDirectory, newFSDirectory, newIndexWriterConfig, newIndexWriterConfig, newIOContext, newIOContext, newLogMergePolicy, newLogMergePolicy, newLogMergePolicy, newLogMergePolicy, newLogMergePolicy, newMergePolicy, newMergePolicy, newMockDirectory, newMockDirectory, newMockFSDirectory, newSearcher, newSearcher, newStringField, newStringField, newTextField, newTextField, newTieredMergePolicy, newTieredMergePolicy, random, randomLocale, randomTimeZone, rarely, rarely, replaceMaxFailureRule, usually, usually |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static int DEFAULT_CONNECTION_TIMEOUT
public static org.junit.rules.TestRule solrClassRules
public org.junit.rules.TestRule solrTestRules
public static org.apache.solr.SolrLogFormatter formatter
protected static String configString
protected static String schemaString
protected static String testSolrHome
protected static org.apache.solr.core.SolrConfig solrConfig
protected static TestHarness h
For use in test methods as needed.
protected static TestHarness.LocalRequestFactory lrf
For use in test methods as needed.
protected static File dataDir
protected static String hdfsDataDir
public static org.slf4j.Logger log
public static final SolrTestCaseJ4.IRange ZERO_ONE
public static final SolrTestCaseJ4.IRange ZERO_TWO
public static final SolrTestCaseJ4.IRange ONE_ONE
Constructor Detail |
---|
public SolrTestCaseJ4()
Method Detail |
---|
public static void useFactory(String factory) throws Exception
Exception
public static void resetFactory() throws Exception
Exception
public static void setupNoCoreTest(File solrHome, String xmlStr) throws Exception
solrHome
- The solr home directory.xmlStr
- - the text of an XML file to use. If null, use the what's the absolute minimal file.
Exception
- Lost of file-type things can go wrong.public static void newRandomConfig()
LuceneTestCase.newIndexWriterConfig(org.apache.lucene.util.Version, org.apache.lucene.analysis.Analyzer)
configs can use these system properties to vary the indexwriter settings
public void setUp() throws Exception
setUp
in class org.apache.lucene.util.LuceneTestCase
Exception
public void tearDown() throws Exception
tearDown
in class org.apache.lucene.util.LuceneTestCase
Exception
public static void setupLogging()
public static void setLoggingLevel(Level level)
public static void initCore(String config, String schema) throws Exception
Exception
public static void initCore(String config, String schema, String solrHome) throws Exception
Exception
public static void initCore(String config, String schema, String solrHome, String pCoreName) throws Exception
Exception
public static void startTrackingSearchers()
public static void startTrackingZkClients()
public static void endTrackingSearchers()
public static void endTrackingZkClients()
public static void ignoreException(String pattern)
public static void unIgnoreException(String pattern)
public static void resetExceptionIgnores()
protected static String getClassName()
protected static String getSimpleClassName()
public static String getSchemaFile()
public static String getSolrConfigFile()
public static void createTempDir()
public static void initCore() throws Exception
Exception
public static void createCore()
public static org.apache.solr.core.CoreContainer createCoreContainer(String solrHome, String solrXML)
public static org.apache.solr.core.CoreContainer createDefaultCoreContainer(String solrHome)
public static boolean hasInitException(String message)
public static boolean hasInitException(Class<? extends Exception> exceptionType)
public void postSetUp()
public void preTearDown()
public static void deleteCore()
public static void assertU(String update)
public static void assertU(String message, String update)
public static void assertFailedU(String update)
public static void assertFailedU(String message, String update)
public static void assertQ(org.apache.solr.request.SolrQueryRequest req, String... tests)
public static void assertQ(String message, org.apache.solr.request.SolrQueryRequest req, String... tests)
public static String JQ(org.apache.solr.request.SolrQueryRequest req) throws Exception
Exception
public static void assertJQ(org.apache.solr.request.SolrQueryRequest req, String... tests) throws Exception
Exception
JSONTestUtil.DEFAULT_DELTA
,
assertJQ(SolrQueryRequest,double,String...)
public static void assertJQ(org.apache.solr.request.SolrQueryRequest req, double delta, String... tests) throws Exception
Please use this with care: this makes it easy to match complete structures, but doing so can result in fragile tests if you are matching more than what you want to test.
req
- Solr request to executedelta
- tolerance allowed in comparing float/double valuestests
- JSON path expression + '==' + expected value
Exception
public static void assertQEx(String message, org.apache.solr.request.SolrQueryRequest req, int code)
public static void assertQEx(String message, org.apache.solr.request.SolrQueryRequest req, org.apache.solr.common.SolrException.ErrorCode code)
public static String optimize(String... args)
BaseTestHarness.optimize(java.lang.String...)
public static String commit(String... args)
BaseTestHarness.commit(java.lang.String...)
public static String adoc(String... fieldsAndValues)
fieldsAndValues
- 0th and Even numbered args are fields names odds are field values.add(org.apache.solr.SolrTestCaseJ4.XmlDoc, java.lang.String...)
,
doc(java.lang.String...)
public static String adoc(org.apache.solr.common.SolrInputDocument sdoc)
public static String add(SolrTestCaseJ4.XmlDoc doc, String... args)
doc
- the Document to addargs
- 0th and Even numbered args are param names, Odds are param values.add(org.apache.solr.SolrTestCaseJ4.XmlDoc, java.lang.String...)
,
doc(java.lang.String...)
public static String delI(String id)
BaseTestHarness.deleteById(java.lang.String, java.lang.String...)
public static String delQ(String q)
BaseTestHarness.deleteByQuery(java.lang.String, java.lang.String...)
public static SolrTestCaseJ4.XmlDoc doc(String... fieldsAndValues)
fieldsAndValues
- 0th and Even numbered args are fields names, Odds are field values.BaseTestHarness.makeSimpleDoc(java.lang.String...)
public static org.apache.solr.common.params.ModifiableSolrParams params(String... params)
public static Map map(Object... params)
public static org.apache.solr.request.SolrQueryRequest req(String... q)
lrf
public static org.apache.solr.request.SolrQueryRequest req(String[] params, String... moreParams)
lrf
public static org.apache.solr.request.SolrQueryRequest req(org.apache.solr.common.params.SolrParams params, String... moreParams)
public static boolean recurseDelete(File f)
public void clearIndex()
public static String updateJ(String json, org.apache.solr.common.params.SolrParams args) throws Exception
Exception
public static org.apache.solr.common.SolrInputDocument sdoc(Object... fieldsAndValues)
public static List<org.apache.solr.common.SolrInputDocument> sdocs(org.apache.solr.common.SolrInputDocument... docs)
public static String json(String testJSON)
public static String json(org.apache.solr.common.SolrInputDocument doc)
public static String jsonAdd(org.apache.solr.common.SolrInputDocument... docs)
public static String jsonDelId(Object... ids)
public static String jsonDelQ(String... queries)
public static Long addAndGetVersion(org.apache.solr.common.SolrInputDocument sdoc, org.apache.solr.common.params.SolrParams params) throws Exception
Exception
public static Long deleteAndGetVersion(String id, org.apache.solr.common.params.SolrParams params) throws Exception
Exception
public static Long deleteByQueryAndGetVersion(String q, org.apache.solr.common.params.SolrParams params) throws Exception
Exception
public Map<Comparable,SolrTestCaseJ4.Doc> indexDocs(List<SolrTestCaseJ4.FldType> descriptor, Map<Comparable,SolrTestCaseJ4.Doc> model, int nDocs) throws Exception
Exception
public static SolrTestCaseJ4.Doc createDoc(List<SolrTestCaseJ4.FldType> descriptor)
public static Comparator<SolrTestCaseJ4.Doc> createSort(org.apache.solr.schema.IndexSchema schema, List<SolrTestCaseJ4.FldType> fieldTypes, String[] out)
public static Comparator<SolrTestCaseJ4.Doc> createComparator(String field, boolean asc, boolean sortMissingLast, boolean sortMissingFirst, boolean sortMissingAsZero)
public static Comparator<SolrTestCaseJ4.Doc> createComparator(List<Comparator<SolrTestCaseJ4.Doc>> comparators)
public static String toJSON(SolrTestCaseJ4.Doc doc)
public Map<Comparable,List<Comparable>> invertField(Map<Comparable,SolrTestCaseJ4.Doc> model, String field)
public static File getFile(String name)
File
. This method should only be used,
if a real file is needed. To get a stream, code should prefer
Class.getResourceAsStream(java.lang.String)
using this.getClass()
.
public static String TEST_HOME()
public static Throwable getRootCause(Throwable t)
public static void assertXmlFile(File file, String... xpath) throws IOException, SAXException
IOException
SAXException
public static void copyMinConf(File dstRoot) throws IOException
IOException
public static void copyMinConf(File dstRoot, String propertiesContent) throws IOException
IOException
public static void copyMinFullSetup(File dstRoot) throws IOException
IOException
public static void copySolrHomeToTemp(File dstRoot, String collection) throws IOException
IOException
public static SolrTestCaseJ4.CoreDescriptorBuilder buildCoreDescriptor(org.apache.solr.core.CoreContainer container, String name, String instancedir)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |