Class SolrTestCaseJ4
- Direct Known Subclasses:
AbstractBackupRepositoryTest,AbstractBadConfigTestBase,AbstractZkTestCase,BaseDistributedSearchTestCase,MultiSolrCloudTestCase,RestTestBase,SolrCloudTestCase,SolrTestCaseHS,UpdateProcessorTestBase
initCore(String, String, Path, String) method.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classstatic classprotected static classstatic classstatic classstatic classstatic classstatic classA builder that will randomize some internal settings.static @interfaceAnnotation for test classes that want to disable PointFields.static @interfaceAnnotation for test classes that want to disable SSLstatic classstatic classstatic classNecessary to make method signatures un-ambiguousNested classes/interfaces inherited from class org.apache.lucene.tests.util.LuceneTestCase
org.apache.lucene.tests.util.LuceneTestCase.AwaitsFix, org.apache.lucene.tests.util.LuceneTestCase.Concurrency, org.apache.lucene.tests.util.LuceneTestCase.Monster, org.apache.lucene.tests.util.LuceneTestCase.Nightly, org.apache.lucene.tests.util.LuceneTestCase.SuppressAssertingFormats, org.apache.lucene.tests.util.LuceneTestCase.SuppressCodecs, org.apache.lucene.tests.util.LuceneTestCase.SuppressFileSystems, org.apache.lucene.tests.util.LuceneTestCase.SuppressFsync, org.apache.lucene.tests.util.LuceneTestCase.SuppressReproduceLine, org.apache.lucene.tests.util.LuceneTestCase.SuppressSysoutChecks, org.apache.lucene.tests.util.LuceneTestCase.SuppressTempFileChecks, org.apache.lucene.tests.util.LuceneTestCase.ThrowingConsumer<T>, org.apache.lucene.tests.util.LuceneTestCase.ThrowingRunnable, org.apache.lucene.tests.util.LuceneTestCase.Weekly -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static Stringprotected static final Stringprotected static Stringstatic final Stringa "dead" host, if you try to connect to it, it will likely fail fast please consider using mocks and not real networking to simulate failurestatic final Stringa "dead" host, if you try to connect to it, it will likely fail fast please consider using mocks and not real networking to simulate failurestatic final Stringa "dead" host, if you try to connect to it, it will likely fail fast please consider using mocks and not real networking to simulate failurestatic intstatic final Stringstatic final Stringprotected static TestHarnessHarness initialized by create[Default]Core[Container].protected static TestHarness.LocalRequestFactoryLocalRequestFactory initialized by create[Default]Core[Container] using sensible defaults.static final StringThe name of a sysprop that will be eithertrueorfalseindicating if docValues should be used on a numeric field.static final StringThe name of a sysprop that will eithertrueorfalseindicating if numeric points fields are currently in use, depending on the user specified value ofUSE_NUMERIC_POINTS_SYSPROPand/or theSolrTestCaseJ4.SuppressPointFieldsannotation and/or randomization.static final SolrTestCaseJ4.IRangeA Map of "primitive" java "numeric" types and the string name of theclassused in the corresponding schema fieldType declaration.protected static Stringprotected static org.apache.solr.core.SolrConfigstatic SSLTestConfigstatic final Stringstatic final Stringprotected static ExecutorServiceprotected static Pathstatic final Stringstatic final StringThe name of a sysprop that can be set by users when running tests to force the types of numerics used for test classes that do not have theSolrTestCaseJ4.SuppressPointFieldsannotation: If unset, then a random variable will be used to decide the type of numerics.static final SolrTestCaseJ4.IRangestatic final SolrTestCaseJ4.IRangeFields inherited from class org.apache.solr.SolrTestCase
solrClassRules, solrTestRulesFields inherited from class org.apache.lucene.tests.util.LuceneTestCase
assertsAreEnabled, classRules, DEFAULT_LINE_DOCS_FILE, INFOSTREAM, JENKINS_LARGE_LINE_DOCS_FILE, LEAVE_TEMPORARY, MAYBE_CACHE_POLICY, RANDOM_MULTIPLIER, ruleChain, suiteFailureMarker, SYSPROP_AWAITSFIX, SYSPROP_FAILFAST, SYSPROP_MAXFAILURES, SYSPROP_MONSTER, SYSPROP_NIGHTLY, SYSPROP_WEEKLY, TEST_ASSERTS_ENABLED, TEST_AWAITSFIX, TEST_CODEC, TEST_DIRECTORY, TEST_DOCVALUESFORMAT, TEST_LINE_DOCS_FILE, TEST_MONSTER, TEST_NIGHTLY, TEST_POSTINGSFORMAT, TEST_THROTTLING, TEST_WEEKLY, VERBOSE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringadd(SolrTestCaseJ4.XmlDoc doc, String... args) Generates a <add><doc>...static LongaddAndGetVersion(org.apache.solr.common.SolrInputDocument sdoc, org.apache.solr.common.params.SolrParams params) static org.apache.solr.response.SolrQueryResponsestatic StringGenerates a simple <add><doc>...static Stringadoc(org.apache.solr.common.SolrInputDocument sdoc) Generates a simple <add><doc>...protected voidassertExceptionThrownWithMessageContaining(Class<? extends Throwable> expectedType, List<String> expectedStrings, org.apache.lucene.tests.util.LuceneTestCase.ThrowingRunnable runnable) static voidassertFailedU(String update) Validates an update XML String failedstatic voidassertFailedU(String message, String update) Validates an update XML String failedstatic voidassertFieldValues(org.apache.solr.common.SolrDocumentList documents, String fieldName, Object... expectedValues) Fails if the number of documents in the given SolrDocumentList differs from the given number of expected values, or if any of the values in the given field don't match the expected values in the same order.static StringValidates a JSON DSL request matches the given JSON test expressionsstatic StringValidates a query matches some JSON test expressions and closes the query.static StringValidates a query matches some JSON test expressions using the default double delta tolerance.static voidstatic voidValidates a query matches some XPath test expressions and closes the querystatic voidValidates a query matches some XPath test expressions and closes the querystatic voidassertQEx(String failMessage, String exceptionMessage, org.apache.solr.request.SolrQueryRequest req, org.apache.solr.common.SolrException.ErrorCode code) Makes sure a query throws a SolrException with the listed response code and expected messagestatic voidMakes sure a query throws a SolrException with the listed response codestatic voidassertQEx(String message, org.apache.solr.request.SolrQueryRequest req, org.apache.solr.common.SolrException.ErrorCode code) Makes sure a query throws a SolrException with the listed response codestatic voidassertResponseValues(org.apache.solr.client.solrj.response.SolrResponseBase rsp, Object... assertions) booleanassertSolrInputFieldEquals(Object expected, Object actual) static <T> StringassertThatJQ(org.apache.solr.request.SolrQueryRequest req, String message, org.hamcrest.Matcher<T> test) Validates a query completes and, using JSON deserialization, returns an object that passes the given Matcher test.static <T> StringassertThatJQ(org.apache.solr.request.SolrQueryRequest req, org.hamcrest.Matcher<T> test) static voidValidates an update XML String is successfulstatic voidValidates an update XML String is successfulstatic voidassertXmlFile(Path file, String... xpath) static voidAssumes that Mockito/Bytebuddy is available and can be used to mock classes (e.g., fails if Java version is too new).protected static StringbuildUrl(int port) voidDoes a low level delete of all docs in the index.static StringbooleancompareSolrDocument(Object expected, Object actual) booleancompareSolrDocumentList(Object expected, Object actual) booleancompareSolrInputDocument(Object expected, Object actual) static Pathstatic voidcopyMinConf(Path dstRoot) static voidcopyMinConf(Path dstRoot, String propertiesContent) Creates a minimal Solr configuration directory with default solrconfig.static voidcopyMinConf(Path dstRoot, String propertiesContent, String solrconfigXmlName) static voidcopySolrHomeToTemp(Path dstRoot, String collection) Deprecated.Use a basic config plus whatever is needed, or the default config, instead of copying the full collection1 test config.static Comparator<SolrTestCaseJ4.Doc> createComparator(String field, boolean asc, boolean sortMissingLast, boolean sortMissingFirst, boolean sortMissingAsZero) static Comparator<SolrTestCaseJ4.Doc> createComparator(List<Comparator<SolrTestCaseJ4.Doc>> comparators) static voidstatic org.apache.solr.core.CoreContainercreateCoreContainer(String coreName, String dataDir, String solrConfig, String schema) static org.apache.solr.core.CoreContainercreateCoreContainer(Path solrHome, String solrXML) static org.apache.solr.core.CoreContainercreateCoreContainer(org.apache.solr.core.NodeConfig config, org.apache.solr.core.CoresLocator locator) static org.apache.solr.core.CoreContainercreateDefaultCoreContainer(Path solrHome) static org.apache.solr.update.processor.DistributedUpdateProcessorcreateDistributedUpdateProcessor(org.apache.solr.request.SolrQueryRequest req, org.apache.solr.response.SolrQueryResponse rsp, org.apache.solr.update.processor.UpdateRequestProcessor next) static SolrTestCaseJ4.DoccreateDoc(List<SolrTestCaseJ4.FldType> descriptor) static Comparator<SolrTestCaseJ4.Doc> createSort(org.apache.solr.schema.IndexSchema schema, List<SolrTestCaseJ4.FldType> fieldTypes, String[] out) static LongdeleteAndGetVersion(String id, org.apache.solr.common.params.SolrParams params) static LongdeleteByQueryAndGetVersion(String q, org.apache.solr.common.params.SolrParams params) static voidShuts down the test harness and nulls out the values setup byinitCore(java.lang.String, java.lang.String)static StringGenerates a <delete>...static StringGenerates a <delete>...static SolrTestCaseJ4.XmlDocGenerates a simple <doc>...protected static Stringstatic PathGets a resource from the context classloader asPath.static Throwableprotected Stringstatic StringSubclasses must define this method to return the name of the schema.xml they wish to use.static StringSubclasses must define this method to return the name of the solrconfig.xml they wish to use.static Throwablestatic booleanhasInitException(Class<? extends Exception> exceptionType) static booleanhasInitException(String message) indexDocs(List<SolrTestCaseJ4.FldType> descriptor, Map<Comparable, SolrTestCaseJ4.Doc> model, int nDocs) protected static PathSubclasses may call this method to access the "dataDir" that will be used byinitCore(java.lang.String, java.lang.String)(either prior to or after the core is created).static voidinitCore()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.static voidCall initCore in @BeforeClass to instantiate a solr core in your test class.static voidCall initCore in @BeforeClass to instantiate a solr core in your test class.static voidCall initCore in @BeforeClass to instantiate a solr core in your test class.invertField(Map<Comparable, SolrTestCaseJ4.Doc> model, String field) Return a Map from field value to a list of document idsprotected static booleanstatic StringJQ(org.apache.solr.request.SolrQueryRequest req) Makes a query request and returns the JSON string responsestatic StringConverts "test JSON" strings into JSON parseable by our JSON parser.static Stringjson(org.apache.solr.common.SolrInputDocument doc) Creates JSON from a SolrInputDocument.static voidjson(org.apache.solr.common.SolrInputDocument doc, org.noggit.CharArr out) Appends to theoutarray with JSON from thedoc.static StringjsonAdd(org.apache.solr.common.SolrInputDocument... docs) Creates a JSON add command from a SolrInputDocument list.static StringCreates a JSON delete command from an id liststatic StringCreates a JSON deleteByQuery commandstatic voidSets system properties to allow generation of random configurations of solrconfig.xml and schema.xml.static Stringstatic org.apache.solr.common.params.ModifiableSolrParamsGenerates the correct SolrParams from an even list of strings.protected static <T> TpickRandom(T... options) voidSubclasses that override setUp can optionally call this method to log the fact that their setUp process has ended.voidSubclasses that override tearDown can optionally call this method to log the fact that the tearDown process has started.static StringReturns a randomly generated Date in the appropriate Solr external (input) formatstatic StringReturns a Date such that all results from this method always have the same values for year+month+day+hour+minute but the seconds are randomized.static StringWe want "realistic" Unicode strings beyond simple ascii, but because our updates use XML we need to ensure we don't get "special" code block.static org.apache.solr.request.SolrQueryRequestGenerates a SolrQueryRequest using the LocalRequestFactorystatic org.apache.solr.request.SolrQueryRequestGenerates a SolrQueryRequest using the LocalRequestFactorystatic org.apache.solr.request.SolrQueryRequestGenerates a SolrQueryRequeststatic org.apache.solr.request.SolrQueryRequestreqWithPath(String path, String... params) Generates a SolrQueryRequest representing the specified path and query paramsstatic org.apache.solr.request.SolrQueryRequestreqWithPath(String path, org.apache.solr.common.params.SolrParams params, String... moreParams) Generates a SolrQueryRequest representing the specified path and query paramsstatic voidstatic org.apache.solr.common.SolrInputDocumentstatic List<org.apache.solr.common.SolrInputDocument> sdocs(org.apache.solr.common.SolrInputDocument... docs) org.apache.solr.common.SolrInputDocumentsdocWithChildren(Integer id, String version, int childCount) org.apache.solr.common.SolrInputDocumentsdocWithChildren(String id, String version) org.apache.solr.common.SolrInputDocumentsdocWithChildren(String id, String version, int childCount) voidsetUp()static voidsetupNoCoreTest(Path solrHome, String xmlStr) Call this from @BeforeClass to set up the test harness and update handler with no cores.static voidstatic ObjectReturnslikelymost (1/10) of the time, otherwiseunlikelystatic voidprotected static voidvoidtearDown()static voidstatic Pathstatic Pathstatic Pathstatic StringtoJSON(SolrTestCaseJ4.Doc doc) static StringSend JSON update commandsstatic voiduseFactory(String factory) Use a different directory factory.static org.apache.solr.client.solrj.request.CollectionAdminRequest.RequestStatusResponsewaitForAsyncClusterRequest(org.apache.solr.client.solrj.SolrClient solrClient, String asyncId, Duration timeout) protected voidprotected static voidwaitForWarming(org.apache.solr.core.SolrCore core) protected static org.apache.lucene.tests.analysis.MockTokenizerwhitespaceMockTokenizer(String input) static org.apache.solr.request.SolrQueryRequestprotected voidwriteCoreProperties(Path coreDirectory, String coreName) static voidwriteCoreProperties(Path coreDirectory, Properties properties, String testname) Methods inherited from class org.apache.solr.SolrTestCase
afterClassSolrTestCase, assertJSONEquals, assertThat, assertThat, beforeSolrTestCase, checkSyspropForceBeforeAssumptionFailure, checkSyspropForceBeforeClassAssumptionFailureMethods inherited from class org.apache.lucene.tests.util.LuceneTestCase
addVirusChecker, assertDeletedDocsEquals, assertDocsAndPositionsEnumEquals, assertDocsEnumEquals, assertDocsSkippingEquals, assertDocValuesEquals, assertDocValuesEquals, assertDoubleUlpEquals, assertFieldInfosEquals, assertFloatUlpEquals, assertNormsEquals, assertPointsEquals, assertPositionsSkippingEquals, assertReaderEquals, assertReaderStatisticsEquals, assertStoredFieldEquals, assertStoredFieldsEquals, assertTermsEnumEquals, assertTermsEquals, assertTermsEquals, assertTermsStatisticsEquals, assertTermStatsEquals, assertTermVectorsEquals, asSet, assumeFalse, assumeNoException, assumeTrue, atLeast, atLeast, callStackContains, callStackContains, callStackContainsAnyOf, closeAfterSuite, closeAfterTest, collate, createTempDir, createTempDir, createTempFile, createTempFile, dumpArray, dumpIterator, ensureSaneIWCOnNightly, expectThrows, expectThrows, expectThrows, expectThrowsAnyOf, expectThrowsAnyOf, getDataInputStream, getDataPath, getJvmForkArguments, getOnlyLeafReader, getTestClass, getTestName, isTestThread, localeForLanguageTag, maybeChangeLiveIndexWriterConfig, maybeWrapReader, newAlcoholicMergePolicy, newAlcoholicMergePolicy, newBytesRef, newBytesRef, newBytesRef, newBytesRef, newBytesRef, newBytesRef, newDirectory, newDirectory, newDirectory, newDirectory, newDirectory, newField, newField, newFSDirectory, newFSDirectory, newIndexWriterConfig, newIndexWriterConfig, newIndexWriterConfig, newIOContext, newIOContext, newLogMergePolicy, newLogMergePolicy, newLogMergePolicy, newLogMergePolicy, newLogMergePolicy, newMaybeVirusCheckingDirectory, newMaybeVirusCheckingFSDirectory, newMergePolicy, newMergePolicy, newMergePolicy, newMockDirectory, newMockDirectory, newMockDirectory, newMockFSDirectory, newMockFSDirectory, newSearcher, newSearcher, newSearcher, newSearcher, newSearcher, newSnapshotIndexWriterConfig, newStringField, newStringField, newStringField, newStringField, newTextField, newTextField, newTieredMergePolicy, newTieredMergePolicy, overrideDefaultQueryCache, overrideTestDefaultQueryCache, random, randomLocale, randomTimeZone, randomVectorFormat, rarely, rarely, replaceMaxFailureRule, resetDefaultQueryCache, restoreCPUCoreCount, restoreIndexWriterMaxDocs, runWithRestrictedPermissions, setIndexWriterMaxDocs, setupCPUCoreCount, setUpExecutorService, shutdownExecutorService, slowFileExists, usually, usually, wrapReaderMethods inherited from class org.junit.Assert
assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertThrows, assertThrows, assertTrue, assertTrue, fail, fail
-
Field Details
-
DEFAULT_TEST_COLLECTION_NAME
- See Also:
-
DEFAULT_TEST_CORENAME
- See Also:
-
CORE_PROPERTIES_FILENAME
- See Also:
-
SYSTEM_PROPERTY_SOLR_TESTS_MERGEPOLICYFACTORY
- See Also:
-
TEST_URL_ALLOW_LIST
- See Also:
-
coreName
-
DEFAULT_CONNECTION_TIMEOUT
public static int DEFAULT_CONNECTION_TIMEOUT -
testExecutor
-
sslConfig
-
DEAD_HOST_1
a "dead" host, if you try to connect to it, it will likely fail fast please consider using mocks and not real networking to simulate failure- See Also:
-
DEAD_HOST_2
a "dead" host, if you try to connect to it, it will likely fail fast please consider using mocks and not real networking to simulate failure- See Also:
-
DEAD_HOST_3
a "dead" host, if you try to connect to it, it will likely fail fast please consider using mocks and not real networking to simulate failure- See Also:
-
configString
-
schemaString
-
testSolrHome
-
solrConfig
protected static org.apache.solr.core.SolrConfig solrConfig -
h
Harness initialized by create[Default]Core[Container].For use in test methods as needed.
-
lrf
LocalRequestFactory initialized by create[Default]Core[Container] using sensible defaults.For use in test methods as needed.
-
ZERO_ONE
-
ZERO_TWO
-
ONE_ONE
-
USE_NUMERIC_POINTS_SYSPROP
The name of a sysprop that can be set by users when running tests to force the types of numerics used for test classes that do not have theSolrTestCaseJ4.SuppressPointFieldsannotation:- If unset, then a random variable will be used to decide the type of numerics.
- If set to
truethen Points based numerics will be used. - If set to
false(or any other string) then Trie based numerics will be used.
- See Also:
-
NUMERIC_POINTS_SYSPROP
The name of a sysprop that will eithertrueorfalseindicating if numeric points fields are currently in use, depending on the user specified value ofUSE_NUMERIC_POINTS_SYSPROPand/or theSolrTestCaseJ4.SuppressPointFieldsannotation and/or randomization. Tests can useBoolean.getBoolean(NUMERIC_POINTS_SYSPROP).- See Also:
-
NUMERIC_DOCVALUES_SYSPROP
The name of a sysprop that will be eithertrueorfalseindicating if docValues should be used on a numeric field. This property string should be used in thedocValuesattribute of (most) numeric fieldTypes in schemas, and by default will be randomized by this class in a@BeforeClass. Subclasses that need to force specific behavior can useSystem.setProperty(NUMERIC_DOCVALUES_SYSPROP,"true")to override the default randomization.- See Also:
-
UPDATELOG_SYSPROP
- See Also:
-
RANDOMIZED_NUMERIC_FIELDTYPES
A Map of "primitive" java "numeric" types and the string name of theclassused in the corresponding schema fieldType declaration.Example:
java.util.Date => "solr.DatePointField"- See Also:
-
-
Constructor Details
-
SolrTestCaseJ4
public SolrTestCaseJ4()
-
-
Method Details
-
writeCoreProperties
- Throws:
IOException
-
writeCoreProperties
public static void writeCoreProperties(Path coreDirectory, Properties properties, String testname) throws IOException - Throws:
IOException
-
assertExceptionThrownWithMessageContaining
-
setupTestCases
public static void setupTestCases() -
teardownTestCases
- Throws:
Exception
-
assumeWorkingMockito
public static void assumeWorkingMockito()Assumes that Mockito/Bytebuddy is available and can be used to mock classes (e.g., fails if Java version is too new). -
isSSLMode
protected static boolean isSSLMode() -
useFactory
Use a different directory factory. Passing "null" sets to an FS-based factory- Throws:
Exception
-
resetFactory
public static void resetFactory() -
buildUrl
-
whitespaceMockTokenizer
protected static org.apache.lucene.tests.analysis.MockTokenizer whitespaceMockTokenizer(String input) -
setupNoCoreTest
Call this from @BeforeClass to set up the test harness and update handler with no cores.- Parameters:
solrHome- The solr home directory.xmlStr- - the text of an XML file to use. If null, use the what's the absolute minimal file.- Throws:
Exception- Lost of file-type things can go wrong.
-
newRandomConfig
public static void newRandomConfig()Sets system properties to allow generation of random configurations of solrconfig.xml and schema.xml. Sets properties used onLuceneTestCase.newIndexWriterConfig(org.apache.lucene.analysis.Analyzer)and base schema.xml (Point Fields) -
getWrappedException
-
setUp
- Overrides:
setUpin classorg.apache.lucene.tests.util.LuceneTestCase- Throws:
Exception
-
tearDown
- Overrides:
tearDownin classorg.apache.lucene.tests.util.LuceneTestCase- Throws:
Exception
-
initAndGetDataDir
Subclasses may call this method to access the "dataDir" that will be used byinitCore(java.lang.String, java.lang.String)(either prior to or after the core is created).If the dataDir has not yet been initialized when this method is called, this method will do so. Calling
deleteCore()will "reset" the value, such that subsequent calls will re-initialize a new value. All directories returned by any calls to this method will automatically be cleaned up perLuceneTestCase.createTempDir()NOTE: calling this method is not required, it will be implicitly called as needed when initializing cores. Callers that don't care about using
initCore(java.lang.String, java.lang.String)and just want a temporary directory to put data in should instead be usingLuceneTestCase.createTempDir()directly.- See Also:
-
initCore
Call initCore in @BeforeClass to instantiate a solr core in your test class. deleteCore will be called for you via SolrTestCaseJ4 @AfterClass- Throws:
Exception
-
initCore
Call initCore in @BeforeClass to instantiate a solr core in your test class. deleteCore will be called for you via SolrTestCaseJ4 @AfterClass- Throws:
Exception
-
initCore
public static void initCore(String config, String schema, Path solrHome, String pCoreName) throws Exception Call initCore in @BeforeClass to instantiate a solr core in your test class. deleteCore will be called for you via SolrTestCaseJ4 @AfterClass- Throws:
Exception
-
startTrackingSearchers
public static void startTrackingSearchers() -
getClassName
-
getSchemaFile
Subclasses must define this method to return the name of the schema.xml they wish to use. -
getSolrConfigFile
Subclasses must define this method to return the name of the solrconfig.xml they wish to use. -
initCore
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.
- Throws:
Exception
-
createCore
public static void createCore() -
createCoreContainer
-
createCoreContainer
public static org.apache.solr.core.CoreContainer createCoreContainer(org.apache.solr.core.NodeConfig config, org.apache.solr.core.CoresLocator locator) -
createCoreContainer
-
createDefaultCoreContainer
-
hasInitException
-
hasInitException
-
postSetUp
public void postSetUp()Subclasses that override setUp can optionally call this method to log the fact that their setUp process has ended. -
preTearDown
public void preTearDown()Subclasses that override tearDown can optionally call this method to log the fact that the tearDown process has started. This is necessary since subclasses will want to call super.tearDown() at the *end* of their tearDown method. -
deleteCore
public static void deleteCore()Shuts down the test harness and nulls out the values setup byinitCore(java.lang.String, java.lang.String) -
assertU
Validates an update XML String is successful -
assertU
Validates an update XML String is successful -
assertFailedU
Validates an update XML String failed -
assertFailedU
Validates an update XML String failed -
assertQ
Validates a query matches some XPath test expressions and closes the query -
assertQ
public 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 -
JQ
Makes a query request and returns the JSON string response- Throws:
Exception
-
assertJJQ
Validates a JSON DSL request matches the given JSON test expressions- Parameters:
jsonBody- The JSON DSL request body to send to Solrtests- JSON path expression + '==' + expected value- Returns:
- The request response as a JSON String if all test patterns pass
- Throws:
Exception- See Also:
-
assertJQ
public static String assertJQ(org.apache.solr.request.SolrQueryRequest req, String... tests) throws Exception Validates a query matches some JSON test expressions using the default double delta tolerance.- Returns:
- The request response as a JSON String if all test patterns pass
- Throws:
Exception- See Also:
-
assertJQ
public static String assertJQ(org.apache.solr.request.SolrQueryRequest req, double delta, String... tests) throws Exception Validates a query matches some JSON test expressions and closes the query. The text expression is of the form path:JSON. The Noggit JSON parser used accepts single quoted strings and bare strings to allow easy embedding in Java Strings.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.
- Parameters:
req- Solr request to executedelta- tolerance allowed in comparing float/double valuestests- JSON path expression + '==' + expected value- Returns:
- The request response as a JSON String if all test patterns pass
- Throws:
Exception
-
assertThatJQ
public static <T> String assertThatJQ(org.apache.solr.request.SolrQueryRequest req, org.hamcrest.Matcher<T> test) throws Exception - Throws:
Exception
-
assertThatJQ
public static <T> String assertThatJQ(org.apache.solr.request.SolrQueryRequest req, String message, org.hamcrest.Matcher<T> test) throws Exception Validates a query completes and, using JSON deserialization, returns an object that passes the given Matcher test.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.
- Parameters:
req- Solr request to executemessage- Failure message for testtest- Matcher for the given object returned from deserializing the response- Returns:
- The request response as a JSON String if the test matcher passes
- Throws:
Exception
-
assertQEx
public 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 -
assertQEx
public static void assertQEx(String message, org.apache.solr.request.SolrQueryRequest req, org.apache.solr.common.SolrException.ErrorCode code) Makes sure a query throws a SolrException with the listed response code -
assertQEx
public static void assertQEx(String failMessage, String exceptionMessage, org.apache.solr.request.SolrQueryRequest req, org.apache.solr.common.SolrException.ErrorCode code) Makes sure a query throws a SolrException with the listed response code and expected message- Parameters:
failMessage- The assert message to show when the query doesn't throw the expected exceptionexceptionMessage- A substring of the message expected in the exceptionreq- Solr requestcode- expected error code for the query
-
optimize
- See Also:
-
commit
- See Also:
-
adoc
Generates a simple <add><doc>... XML String with no options- Parameters:
fieldsAndValues- 0th and Even numbered args are fields names odds are field values.- See Also:
-
adoc
Generates a simple <add><doc>... XML String with no options -
addDoc
public static org.apache.solr.response.SolrQueryResponse addDoc(String doc, String updateRequestProcessorChain) throws Exception - Throws:
Exception
-
add
Generates a <add><doc>... XML String with options on the add.- Parameters:
doc- the Document to addargs- 0th and Even numbered args are param names, Odds are param values.- See Also:
-
delI
Generates a <delete>... XML string for an ID- See Also:
-
delQ
Generates a <delete>... XML string for an query- See Also:
-
doc
Generates a simple <doc>... XML String with no options- Parameters:
fieldsAndValues- 0th and Even numbered args are fields names, Odds are field values.- See Also:
-
params
Generates the correct SolrParams from an even list of strings. A string in an even position will represent the name of a parameter, while the following string at position (i+1) will be the assigned value.- Parameters:
params- an even list of strings- Returns:
- the ModifiableSolrParams generated from the given list of strings.
-
map
-
map
-
req
Generates a SolrQueryRequest using the LocalRequestFactory- See Also:
-
req
Generates a SolrQueryRequest using the LocalRequestFactory- See Also:
-
req
public static org.apache.solr.request.SolrQueryRequest req(org.apache.solr.common.params.SolrParams params, String... moreParams) Generates a SolrQueryRequest -
reqWithPath
Generates a SolrQueryRequest representing the specified path and query paramsPath information is used by
assertQ(SolrQueryRequest, String...)and similar helpers to look up the request handler to invoke. When used with these helpers, typically only the requestHandler path segment need by provided ("/select", "/export", etc.)- See Also:
-
reqWithPath
public static org.apache.solr.request.SolrQueryRequest reqWithPath(String path, org.apache.solr.common.params.SolrParams params, String... moreParams) Generates a SolrQueryRequest representing the specified path and query paramsPath information is used by
assertQ(SolrQueryRequest, String...)and similar helpers to look up the request handler to invoke. When used with these helpers, typically only the requestHandler path segment need by provided ("/select", "/export", etc.)- See Also:
-
withPath
public static org.apache.solr.request.SolrQueryRequest withPath(String path, org.apache.solr.request.SolrQueryRequest req) -
clearIndex
public void clearIndex()Does a low level delete of all docs in the index.The behavior of this method is slightly different from doing a normal
*:*DBQ because it takes advantage of internal methods to ensure all index data is wiped, regardless of optimistic concurrency version constraints -- making it suitable for tests that create synthetic versions, and/or require a completely pristine index w/o any field metadata.- See Also:
-
updateJ
public static String updateJ(String json, org.apache.solr.common.params.SolrParams args) throws Exception Send JSON update commands- Throws:
Exception
-
sdoc
-
sdocWithChildren
-
sdocWithChildren
-
sdocWithChildren
-
sdocs
public static List<org.apache.solr.common.SolrInputDocument> sdocs(org.apache.solr.common.SolrInputDocument... docs) -
json
Converts "test JSON" strings into JSON parseable by our JSON parser. For example, this method changed single quoted strings into double-quoted strings before the parser could natively handle them.This transformation is automatically applied to JSON test strings (like assertJQ).
-
json
Creates JSON from a SolrInputDocument. Doesn't currently handle boosts.- See Also:
-
json
public static void json(org.apache.solr.common.SolrInputDocument doc, org.noggit.CharArr out) Appends to theoutarray with JSON from thedoc. Doesn't currently handle boosts, but does recursively handle child documents -
jsonAdd
Creates a JSON add command from a SolrInputDocument list. Doesn't currently handle boosts. -
jsonDelId
Creates a JSON delete command from an id list -
jsonDelQ
Creates a JSON deleteByQuery command -
addAndGetVersion
public static Long addAndGetVersion(org.apache.solr.common.SolrInputDocument sdoc, org.apache.solr.common.params.SolrParams params) throws Exception - Throws:
Exception
-
deleteAndGetVersion
public static Long deleteAndGetVersion(String id, org.apache.solr.common.params.SolrParams params) throws Exception - Throws:
Exception
-
deleteByQueryAndGetVersion
public static Long deleteByQueryAndGetVersion(String q, org.apache.solr.common.params.SolrParams params) throws Exception - Throws:
Exception
-
assertResponseValues
public static void assertResponseValues(org.apache.solr.client.solrj.response.SolrResponseBase rsp, Object... assertions) -
indexDocs
public Map<Comparable,SolrTestCaseJ4.Doc> indexDocs(List<SolrTestCaseJ4.FldType> descriptor, Map<Comparable, SolrTestCaseJ4.Doc> model, int nDocs) throws Exception- Throws:
Exception
-
createDoc
-
createSort
public static Comparator<SolrTestCaseJ4.Doc> createSort(org.apache.solr.schema.IndexSchema schema, List<SolrTestCaseJ4.FldType> fieldTypes, String[] out) -
createComparator
public static Comparator<SolrTestCaseJ4.Doc> createComparator(String field, boolean asc, boolean sortMissingLast, boolean sortMissingFirst, boolean sortMissingAsZero) -
createComparator
public static Comparator<SolrTestCaseJ4.Doc> createComparator(List<Comparator<SolrTestCaseJ4.Doc>> comparators) -
toJSON
-
invertField
public Map<Comparable,List<Comparable>> invertField(Map<Comparable, SolrTestCaseJ4.Doc> model, String field) Return a Map from field value to a list of document ids -
getFile
Gets a resource from the context classloader asPath. This method should only be used, if a real file is needed. To get a stream, code should preferClass.getResourceAsStream(java.lang.String)usingthis.getClass(). -
TEST_HOME
-
TEST_PATH
-
TEST_COLL1_CONF
-
configset
-
getRootCause
-
assertXmlFile
- Throws:
IOExceptionSAXException
-
assertFieldValues
public static void assertFieldValues(org.apache.solr.common.SolrDocumentList documents, String fieldName, Object... expectedValues) Fails if the number of documents in the given SolrDocumentList differs from the given number of expected values, or if any of the values in the given field don't match the expected values in the same order. -
copyMinConf
- Throws:
IOException
-
copyMinConf
Creates a minimal Solr configuration directory with default solrconfig. Adds in a core.properties if propertiesContent is provided.- Parameters:
dstRoot- the destination directory where conf/ will be createdpropertiesContent- content for core.properties file, or null to skip creating it- Throws:
IOException
-
copyMinConf
public static void copyMinConf(Path dstRoot, String propertiesContent, String solrconfigXmlName) throws IOException - Throws:
IOException
-
copySolrHomeToTemp
@Deprecated(since="10.0") public static void copySolrHomeToTemp(Path dstRoot, String collection) throws IOException Deprecated.Use a basic config plus whatever is needed, or the default config, instead of copying the full collection1 test config.- Throws:
IOException
-
compareSolrDocument
-
compareSolrDocumentList
-
compareSolrInputDocument
-
assertSolrInputFieldEquals
-
skewed
Returnslikelymost (1/10) of the time, otherwiseunlikely -
waitForAsyncClusterRequest
public static org.apache.solr.client.solrj.request.CollectionAdminRequest.RequestStatusResponse waitForAsyncClusterRequest(org.apache.solr.client.solrj.SolrClient solrClient, String asyncId, Duration timeout) throws Exception - Throws:
Exception
-
randomDate
Returns a randomly generated Date in the appropriate Solr external (input) format- See Also:
-
randomSkewedDate
Returns a Date such that all results from this method always have the same values for year+month+day+hour+minute but the seconds are randomized. This can be helpful for indexing documents with random date values that are biased for a narrow window (one day) to test collisions/overlaps- See Also:
-
randomXmlUsableUnicodeString
We want "realistic" Unicode strings beyond simple ascii, but because our updates use XML we need to ensure we don't get "special" code block. -
waitForWarming
protected static void waitForWarming(org.apache.solr.core.SolrCore core) throws InterruptedException - Throws:
InterruptedException
-
waitForWarming
- Throws:
InterruptedException
-
getSaferTestName
-
assertNonBlockingRandomGeneratorAvailable
public static void assertNonBlockingRandomGeneratorAvailable() -
systemSetPropertySolrTestsMergePolicyFactory
-
pickRandom
-
createDistributedUpdateProcessor
public static org.apache.solr.update.processor.DistributedUpdateProcessor createDistributedUpdateProcessor(org.apache.solr.request.SolrQueryRequest req, org.apache.solr.response.SolrQueryResponse rsp, org.apache.solr.update.processor.UpdateRequestProcessor next)
-