Class LuceneTestCase
- Direct Known Subclasses:
BaseBitSetTestCase,BaseDirectoryTestCase,BaseDocIdSetTestCase,BaseExplanationTestCase,BaseGeoPointTestCase,BaseIndexFileFormatTestCase,BaseLiveDocsFormatTestCase,BaseLockFactoryTestCase,BaseMergePolicyTestCase,BaseRangeFieldQueryTestCase,BaseSimilarityTestCase,BaseTestCheckIndex,BaseTokenStreamTestCase,BaseXYPointTestCase,CollationTestBase,MatchesTestBase,MockFileSystemTestCase,SearchEquivalenceTestBase,ShardSearchingTestBase,ThreadedIndexingAndSearchingTestCase
Class and instance setup.
The preferred way to specify class (suite-level) setup/cleanup is to use static methods
annotated with BeforeClass and AfterClass. Any code in these methods is executed
within the test framework's control and ensure proper setup has been made. Try not to use
static initializers (including complex final field initializers). Static initializers are
executed before any setup rules are fired and may cause you (or somebody else) headaches.
For instance-level setup, use Before and After annotated methods. If you
override either setUp() or tearDown() in your subclass, make sure you call
super.setUp() and super.tearDown(). This is detected and enforced.
Specifying test cases
Any test method with a testXXX prefix is considered a test case. Any test method
annotated with Test is considered a test case.
Randomized execution and test facilities
LuceneTestCase uses RandomizedRunner to execute test cases. RandomizedRunner has built-in support for tests randomization including access to a repeatable
Random instance. See random() method. Any test using Random acquired
from random() should be fully reproducible (assuming no race conditions between threads
etc.). The initial seed for a test case is reported in many ways:
- as part of any exception thrown from its body (inserted as a dummy stack trace entry),
- as part of the main thread executing the test case (if your test hangs, just dump the stack trace of all threads and you'll see the seed),
- the master seed can also be accessed manually by getting the current context (
RandomizedContext.current()) and then callingRandomizedContext.getRunnerSeedAsString().
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic @interfaceAnnotation for tests which exhibit a known issue and are temporarily disabled.static enumWhat level of concurrency is supported by the searcher being createdstatic @interfaceAnnotation for monster tests that require special setup (e.g.static @interfaceAnnotation for tests that should only be run during nightly builds.static @interfaceAnnotation for test classes that should avoid certain codec types (because they are expensive, for example).static @interfaceAnnotation for test classes that should avoid mock filesystem types (because they test a bug that only happens on linux, for example).static @interfaceAnnotation for test classes that should avoid always omit actual fsync calls from reaching the filesystem.static @interfaceSuppress the defaultreproduce with: ant test...Your own listener can be added as needed for your build.static @interfaceIgnoreTestRuleLimitSysoutsfor any suite which is known to print over the default limit of bytes toSystem.outorSystem.err.static @interfaceMarks any suites which are known not to close all the temporary files.static interfaceAConsumerthat can throw any checked exception.static interfaceA runnable that can throw any checked exception.static @interfaceAnnotation for tests that should only be run during weekly builds -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanTrue if assertions (-ea) are enabled (at least for this class).static final org.junit.rules.TestRuleThis controls how suite-level rules are nested.static final StringThe default (embedded resource) lines file.static final booleanEnables or disables dumping ofInfoStreammessages.static final StringRandom sample from enwiki used in tests.static final booleanLeave temporary files on disk, even on successful runs.static final QueryCachingPolicyAQueryCachingPolicythat randomly caches.static final intA random multiplier which you should use when writing random tests: multiply it by the number of iterations to scale your tests (for nightly builds).final org.junit.rules.TestRuleThis controls how individual test rules are nested.protected static TestRuleMarkFailureSuite failure marker (any error in the test or suite scope).static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final booleanstatic final booleanWhether or notLuceneTestCase.AwaitsFixtests should run.static final StringGets the codec to run tests with.static final StringGets the directory to run tests withstatic final StringGets the docValuesFormat to run tests withstatic final StringThe line file used in tests (byLineFileDocs).static final booleanWhether or notLuceneTestCase.Monstertests should run.static final booleanWhether or notLuceneTestCase.Nightlytests should run.static final StringGets the postingsFormat to run tests with.static final MockDirectoryWrapper.ThrottlingThrottling, seeMockDirectoryWrapper.setThrottling(Throttling).static final booleanWhether or notLuceneTestCase.Weeklytests should run.static final booleanTrue if and only if tests are run in verbose mode. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic PathaddVirusChecker(Path path) voidassertDeletedDocsEquals(String info, IndexReader leftReader, IndexReader rightReader) voidassertDocsAndPositionsEnumEquals(String info, PostingsEnum leftDocs, PostingsEnum rightDocs) checks docs + freqs + positions + payloads, sequentiallyvoidassertDocsEnumEquals(String info, PostingsEnum leftDocs, PostingsEnum rightDocs, boolean hasFreqs) checks docs + freqs, sequentiallyvoidassertDocsSkippingEquals(String info, IndexReader leftReader, int docFreq, PostingsEnum leftDocs, PostingsEnum rightDocs, boolean hasFreqs) checks advancing docsvoidassertDocValuesEquals(String info, int num, NumericDocValues leftDocValues, NumericDocValues rightDocValues) voidassertDocValuesEquals(String info, IndexReader leftReader, IndexReader rightReader) checks that docvalues across all fields are equivalentstatic voidassertDoubleUlpEquals(double x, double y, int maxUlps) voidassertFieldInfosEquals(String info, IndexReader leftReader, IndexReader rightReader) static voidassertFloatUlpEquals(float x, float y, short maxUlps) voidassertNormsEquals(String info, IndexReader leftReader, IndexReader rightReader) checks that norms are the same across all fieldsvoidassertPointsEquals(String info, IndexReader leftReader, IndexReader rightReader) voidassertPositionsSkippingEquals(String info, IndexReader leftReader, int docFreq, PostingsEnum leftDocs, PostingsEnum rightDocs) checks advancing docs + positionsvoidassertReaderEquals(String info, IndexReader leftReader, IndexReader rightReader) voidassertReaderStatisticsEquals(String info, IndexReader leftReader, IndexReader rightReader) checks that reader-level statistics are the samevoidassertStoredFieldEquals(String info, IndexableField leftField, IndexableField rightField) checks that two stored fields are equivalentvoidassertStoredFieldsEquals(String info, IndexReader leftReader, IndexReader rightReader) checks that stored fields of all documents are the samevoidassertTermsEnumEquals(String info, IndexReader leftReader, TermsEnum leftTermsEnum, TermsEnum rightTermsEnum, boolean deep) checks the terms enum sequentially if deep is false, it does a 'shallow' test that doesnt go down to the docsenumsvoidassertTermsEquals(String info, IndexReader leftReader, IndexReader rightReader, boolean deep) Fields api equivalencyvoidassertTermsEquals(String info, IndexReader leftReader, Terms leftTerms, Terms rightTerms, boolean deep) Terms api equivalencyvoidassertTermsStatisticsEquals(String info, Terms leftTerms, Terms rightTerms) checks collection-level statistics on TermsvoidassertTermStatsEquals(String info, TermsEnum leftTermsEnum, TermsEnum rightTermsEnum) checks term-level statisticsvoidassertTermVectorsEquals(String info, IndexReader leftReader, IndexReader rightReader) checks that term vectors across all fields are equivalentstatic <T> Set<T> asSet(T... args) Returnargsas aSetinstance.static voidassumeFalse(String msg, boolean condition) static voidassumeNoException(String msg, Exception e) static voidassumeTrue(String msg, boolean condition) static intatLeast(int i) static intReturns a number of at leastistatic booleancallStackContains(Class<?> clazz) Inspects stack trace if the given class called us.static booleancallStackContains(Class<?> clazz, String methodName) Inspects stack trace to figure out if a method of a specific class called us.static booleancallStackContainsAnyOf(String... methodNames) Inspects stack trace to figure out if one of the given method names (no class restriction) called us.static <T extends Closeable>
TcloseAfterSuite(T resource) Registers aCloseableresource that should be closed after the suite completes.<T extends Closeable>
TcloseAfterTest(T resource) Registers aCloseableresource that should be closed after the test completes.static intCompares two strings with a collator, also looking to see if the strings are impacted by jdk bugs.static PathCreates an empty, temporary folder (when the name of the folder is of no importance).static PathcreateTempDir(String prefix) Creates an empty, temporary folder with the given name prefix.static PathCreates an empty temporary file.static PathcreateTempFile(String prefix, String suffix) Creates an empty file with the given prefix and suffix.static voiddumpArray(String label, Object[] objs, PrintStream stream) Convenience method for logging an array.static voiddumpIterator(String label, Iterator<?> iter, PrintStream stream) Convenience method for logging an iterator.protected static IndexWriterConfigEnsures that the MergePolicy has sane values for tests that test with lots of documents.static <T extends Throwable>
TexpectThrows(Class<T> expectedType, String noExceptionMessage, LuceneTestCase.ThrowingRunnable runnable) Checks a specific exception class is thrown by the given runnable, and returns it.static <T extends Throwable>
TexpectThrows(Class<T> expectedType, LuceneTestCase.ThrowingRunnable runnable) Checks a specific exception class is thrown by the given runnable, and returns it.expectThrows(Class<TO> expectedOuterType, Class<TW> expectedWrappedType, LuceneTestCase.ThrowingRunnable runnable) Checks that specific wrapped and outer exception classes are thrown by the given runnable, and returns the wrapped exception.expectThrowsAnyOf(LinkedHashMap<Class<? extends TO>, List<Class<? extends TW>>> expectedOuterToWrappedTypes, LuceneTestCase.ThrowingRunnable runnable) Checks that one of the specified wrapped and outer exception classes are thrown by the given runnable, and returns the outer exception.static <T extends Throwable>
TexpectThrowsAnyOf(List<Class<? extends T>> expectedTypes, LuceneTestCase.ThrowingRunnable runnable) Checks a specific exception class is thrown by the given runnable, and returns it.protected InputStreamgetDataInputStream(String name) Gets a resource from the test's classpath asInputStream.protected PathgetDataPath(String name) Gets a resource from the test's classpath asPath.Returns a set of JVM arguments to fork a JVM with the same class or module path (including any associated JVM options).static LeafReadergetOnlyLeafReader(IndexReader reader) Some tests expect the directory to contain a single segment, and want to do tests on that segment's reader.static Class<?> Return the current class being tested.Return the name of the currently executing test case.protected booleanReturns true if and only if the calling thread is the primary thread executing the test case.static LocalelocaleForLanguageTag(String languageTag) return a Locale object equivalent to its programmatic namestatic voidstatic IndexReaderSometimes wrap the IndexReader as slow, parallel or filter reader (or combinations of that)static AlcoholicMergePolicystatic AlcoholicMergePolicystatic BytesRefCreates a random empty BytesRef that sometimes uses a non-zerooffset, and non-zero end-padding, to tickle latent bugs that fail to look atBytesRef.offset.static BytesRefnewBytesRef(byte[] b) Creates a random BytesRef from the incoming bytes that sometimes uses a non-zerooffset, and non-zero end-padding, to tickle latent bugs that fail to look atBytesRef.offset.static BytesRefnewBytesRef(byte[] bytesIn, int offset, int length) Creates a copy of the incoming bytes slice that sometimes uses a non-zerooffset, and non-zero end-padding, to tickle latent bugs that fail to look atBytesRef.offset.static BytesRefnewBytesRef(int byteLength) Creates a random empty BytesRef, with at least the requested length of bytes free, that sometimes uses a non-zerooffset, and non-zero end-padding, to tickle latent bugs that fail to look atBytesRef.offset.static BytesRefCreates aBytesRefholding UTF-8 bytes for the incoming String, that sometimes uses a non-zerooffset, and non-zero end-padding, to tickle latent bugs that fail to look atBytesRef.offset.static BytesRefCreates a copy of the incomingBytesRefthat sometimes uses a non-zerooffset, and non-zero end-padding, to tickle latent bugs that fail to look atBytesRef.offset.static BaseDirectoryWrapperReturns a new Directory instance.static BaseDirectoryWrapperReturns a new Directory instance, using the specified random.static BaseDirectoryWrappernewDirectory(Random r, Directory d) Returns a new Directory instance, using the specified random with contents copied from the provided directory.static BaseDirectoryWrappernewDirectory(Random r, LockFactory lf) Returns a new Directory instance, using the specified random.static BaseDirectoryWrapperReturns a new Directory instance, with contents copied from the provided directory.static Fieldstatic Fieldstatic BaseDirectoryWrapperReturns a new FSDirectory instance over the given file, which must be a folder.static BaseDirectoryWrappernewFSDirectory(Path f, LockFactory lf) Returns a new FSDirectory instance over the given file, which must be a folder.static IndexWriterConfigcreate a new index writer config with random defaultsstatic IndexWriterConfigcreate a new index writer config with random defaults using the specified randomstatic IndexWriterConfigcreate a new index writer config with random defaultsstatic IOContextnewIOContext(Random random) TODO: javadocstatic IOContextnewIOContext(Random random, IOContext oldContext) TODO: javadocstatic LogMergePolicystatic MergePolicynewLogMergePolicy(boolean useCFS) static LogMergePolicynewLogMergePolicy(boolean useCFS, int mergeFactor) static LogMergePolicynewLogMergePolicy(int mergeFactor) static LogMergePolicystatic BaseDirectoryWrapperLikenewDirectory()except randomly theVirusCheckingFSmay be installedstatic BaseDirectoryWrapperLikenewFSDirectory(Path), but randomly insertVirusCheckingFSstatic MergePolicystatic MergePolicystatic MergePolicynewMergePolicy(Random r, boolean includeMockMP) static MockDirectoryWrapperstatic MockDirectoryWrapperstatic MockDirectoryWrappernewMockDirectory(Random r, LockFactory lf) static MockDirectoryWrapperstatic MockDirectoryWrappernewMockFSDirectory(Path f, LockFactory lf) static IndexSearcherCreate a new searcher over the reader.static IndexSearchernewSearcher(IndexReader r, boolean maybeWrap) Create a new searcher over the reader.static IndexSearchernewSearcher(IndexReader r, boolean maybeWrap, boolean wrapWithAssertions) Create a new searcher over the reader.static IndexSearchernewSearcher(IndexReader r, boolean maybeWrap, boolean wrapWithAssertions, boolean useThreads) Create a new searcher over the reader.static IndexSearchernewSearcher(IndexReader r, boolean maybeWrap, boolean wrapWithAssertions, LuceneTestCase.Concurrency concurrency) static IndexWriterConfignewSnapshotIndexWriterConfig(Analyzer analyzer) create a new index writer config with a snapshot deletion policystatic FieldnewStringField(String name, String value, Field.Store stored) static FieldnewStringField(String name, BytesRef value, Field.Store stored) static FieldnewStringField(Random random, String name, String value, Field.Store stored) static FieldnewStringField(Random random, String name, BytesRef value, Field.Store stored) static FieldnewTextField(String name, String value, Field.Store stored) static FieldnewTextField(Random random, String name, String value, Field.Store stored) static TieredMergePolicystatic TieredMergePolicystatic voidvoidstatic Randomrandom()Access to the currentRandomizedContext's Random instance.static LocalerandomLocale(Random random) Return a random Locale from the available locales on the system.static TimeZonerandomTimeZone(Random random) Return a random TimeZone from the available timezones on the systemprotected static KnnVectorsFormatrandomVectorFormat(VectorEncoding vectorEncoding) static booleanrarely()static booleanReturns true if something should happen rarely,Temporarily substitute the globalTestRuleIgnoreAfterMaxFailures.static voidstatic voidvoidReturns to the defaultIndexWriter.MAX_DOCSlimit.static <T> TrunWithRestrictedPermissions(PrivilegedExceptionAction<T> action, Permission... permissions) Runs a code part with restricted permissions (be sure to add all required permissions, because it would start with empty permissions).voidsetIndexWriterMaxDocs(int limit) TellsIndexWriterto enforce the specified limit as the maximum number of documents in one index; callrestoreIndexWriterMaxDocs()once your test is done.voidsetUp()For subclasses to override.static voidstatic voidstatic voidstatic booleanslowFileExists(Directory dir, String fileName) Returns true if the file exists (can be opened), false if it cannot be opened, and (unlike Java's File.exists) throws IOException if there's some unexpected error.voidtearDown()For subclasses to override.static booleanusually()static booleanstatic IndexReaderMethods 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, assertThat, assertThat, assertThrows, assertThrows, assertTrue, assertTrue, fail, fail
-
Field Details
-
SYSPROP_NIGHTLY
- See Also:
-
SYSPROP_WEEKLY
- See Also:
-
SYSPROP_MONSTER
- See Also:
-
SYSPROP_AWAITSFIX
- See Also:
-
SYSPROP_MAXFAILURES
- See Also:
-
SYSPROP_FAILFAST
- See Also:
-
VERBOSE
public static final boolean VERBOSETrue if and only if tests are run in verbose mode. If this flag is false tests are not expected to print any messages. Enforced withTestRuleLimitSysouts. -
INFOSTREAM
public static final boolean INFOSTREAMEnables or disables dumping ofInfoStreammessages. -
TEST_ASSERTS_ENABLED
public static final boolean TEST_ASSERTS_ENABLED -
DEFAULT_LINE_DOCS_FILE
The default (embedded resource) lines file.- See Also:
-
JENKINS_LARGE_LINE_DOCS_FILE
Random sample from enwiki used in tests. Seehelp/tests.txt. gradle task downloading this data set:gradlew getEnWikiRandomLines.- See Also:
-
TEST_CODEC
Gets the codec to run tests with. -
TEST_POSTINGSFORMAT
Gets the postingsFormat to run tests with. -
TEST_DOCVALUESFORMAT
Gets the docValuesFormat to run tests with -
TEST_DIRECTORY
Gets the directory to run tests with -
TEST_LINE_DOCS_FILE
The line file used in tests (byLineFileDocs). -
TEST_NIGHTLY
public static final boolean TEST_NIGHTLYWhether or notLuceneTestCase.Nightlytests should run. -
TEST_WEEKLY
public static final boolean TEST_WEEKLYWhether or notLuceneTestCase.Weeklytests should run. -
TEST_MONSTER
public static final boolean TEST_MONSTERWhether or notLuceneTestCase.Monstertests should run. -
TEST_AWAITSFIX
public static final boolean TEST_AWAITSFIXWhether or notLuceneTestCase.AwaitsFixtests should run. -
TEST_THROTTLING
Throttling, seeMockDirectoryWrapper.setThrottling(Throttling). -
RANDOM_MULTIPLIER
public static final int RANDOM_MULTIPLIERA random multiplier which you should use when writing random tests: multiply it by the number of iterations to scale your tests (for nightly builds). -
LEAVE_TEMPORARY
public static final boolean LEAVE_TEMPORARYLeave temporary files on disk, even on successful runs. -
MAYBE_CACHE_POLICY
AQueryCachingPolicythat randomly caches. -
suiteFailureMarker
Suite failure marker (any error in the test or suite scope). -
classRules
public static final org.junit.rules.TestRule classRulesThis controls how suite-level rules are nested. It is important that _all_ rules declared inLuceneTestCaseare executed in proper order if they depend on each other. -
ruleChain
public final org.junit.rules.TestRule ruleChainThis controls how individual test rules are nested. It is important that _all_ rules declared inLuceneTestCaseare executed in proper order if they depend on each other. -
assertsAreEnabled
public static final boolean assertsAreEnabledTrue if assertions (-ea) are enabled (at least for this class).
-
-
Constructor Details
-
LuceneTestCase
public LuceneTestCase()
-
-
Method Details
-
replaceMaxFailureRule
public static TestRuleIgnoreAfterMaxFailures replaceMaxFailureRule(TestRuleIgnoreAfterMaxFailures newValue) Temporarily substitute the globalTestRuleIgnoreAfterMaxFailures. SeeignoreAfterMaxFailuresDelegatefor some explanation why this method is needed. -
setUp
For subclasses to override. Overrides must callsuper.setUp().- Throws:
Exception
-
tearDown
For subclasses to override. Overrides must callsuper.tearDown().- Throws:
Exception
-
setIndexWriterMaxDocs
public void setIndexWriterMaxDocs(int limit) TellsIndexWriterto enforce the specified limit as the maximum number of documents in one index; callrestoreIndexWriterMaxDocs()once your test is done. -
restoreIndexWriterMaxDocs
public void restoreIndexWriterMaxDocs()Returns to the defaultIndexWriter.MAX_DOCSlimit. -
random
Access to the currentRandomizedContext's Random instance. It is safe to use this method from multiple threads, etc., but it should be called while within a runner's scope (so no static initializers). The returnedRandominstance will be different when this method is called inside aBeforeClasshook (static suite scope) and withinBefore/Afterhooks or test methods.The returned instance must not be shared with other threads or cross a single scope's boundary. For example, a
Randomacquired within a test method shouldn't be reused for another test case.There is an overhead connected with getting the
Randomfor a particular context and thread. It is better to cache theRandomlocally if tight loops with multiple invocations are present or create a derivative localRandomfor millions of calls like this:Random random = new Random(random().nextLong()); // tight loop with many invocations.
-
closeAfterTest
Registers aCloseableresource that should be closed after the test completes.- Returns:
resource(for call chaining).
-
closeAfterSuite
Registers aCloseableresource that should be closed after the suite completes.- Returns:
resource(for call chaining).
-
getTestClass
Return the current class being tested. -
getTestName
Return the name of the currently executing test case. -
getOnlyLeafReader
Some tests expect the directory to contain a single segment, and want to do tests on that segment's reader. This is an utility method to help them. -
isTestThread
protected boolean isTestThread()Returns true if and only if the calling thread is the primary thread executing the test case. -
atLeast
Returns a number of at leastiThe actual number returned will be influenced by whether
TEST_NIGHTLYis active andRANDOM_MULTIPLIER, but also with some random fudge. -
atLeast
public static int atLeast(int i) -
rarely
Returns true if something should happen rarely,The actual number returned will be influenced by whether
TEST_NIGHTLYis active andRANDOM_MULTIPLIER. -
rarely
public static boolean rarely() -
usually
-
usually
public static boolean usually() -
assumeTrue
-
assumeFalse
-
assumeNoException
-
assertFloatUlpEquals
public static void assertFloatUlpEquals(float x, float y, short maxUlps) -
assertDoubleUlpEquals
public static void assertDoubleUlpEquals(double x, double y, int maxUlps) -
asSet
Returnargsas aSetinstance. The order of elements is not preserved in iterators. -
dumpIterator
Convenience method for logging an iterator.- Parameters:
label- String logged before/after the items in the iteratoriter- Each next() is toString()ed and logged on its own line. If iter is null this is logged differently then an empty iterator.stream- Stream to log messages to.
-
dumpArray
Convenience method for logging an array. Wraps the array in an iterator and delegates- See Also:
-
newSnapshotIndexWriterConfig
create a new index writer config with a snapshot deletion policy -
newIndexWriterConfig
create a new index writer config with random defaults -
newIndexWriterConfig
create a new index writer config with random defaults -
newIndexWriterConfig
create a new index writer config with random defaults using the specified random -
newMergePolicy
-
newMergePolicy
-
newMergePolicy
-
newLogMergePolicy
-
newTieredMergePolicy
-
newAlcoholicMergePolicy
-
newAlcoholicMergePolicy
-
newLogMergePolicy
-
newTieredMergePolicy
-
newLogMergePolicy
-
newLogMergePolicy
-
newLogMergePolicy
-
maybeChangeLiveIndexWriterConfig
-
newDirectory
Returns a new Directory instance. Use this when the test does not care about the specific Directory implementation (most tests).The Directory is wrapped with
BaseDirectoryWrapper. this means usually it will be picky, such as ensuring that you properly close it and all open files in your test. It will emulate some features of Windows, such as not allowing open files to be overwritten. -
newMaybeVirusCheckingDirectory
LikenewDirectory()except randomly theVirusCheckingFSmay be installed -
newDirectory
Returns a new Directory instance, using the specified random. SeenewDirectory()for more information. -
newDirectory
Returns a new Directory instance, using the specified random. SeenewDirectory()for more information. -
newMockDirectory
-
newMockDirectory
-
newMockDirectory
-
newMockFSDirectory
-
newMockFSDirectory
-
addVirusChecker
-
newDirectory
Returns a new Directory instance, with contents copied from the provided directory. SeenewDirectory()for more information.- Throws:
IOException
-
newFSDirectory
Returns a new FSDirectory instance over the given file, which must be a folder. -
newMaybeVirusCheckingFSDirectory
LikenewFSDirectory(Path), but randomly insertVirusCheckingFS -
newFSDirectory
Returns a new FSDirectory instance over the given file, which must be a folder. -
newDirectory
Returns a new Directory instance, using the specified random with contents copied from the provided directory. SeenewDirectory()for more information.- Throws:
IOException
-
newStringField
-
newStringField
-
newTextField
-
newStringField
-
newStringField
-
newTextField
-
newField
-
newField
-
randomLocale
Return a random Locale from the available locales on the system.- See Also:
-
randomTimeZone
Return a random TimeZone from the available timezones on the system- See Also:
-
localeForLanguageTag
return a Locale object equivalent to its programmatic name -
wrapReader
- Throws:
IOException
-
maybeWrapReader
Sometimes wrap the IndexReader as slow, parallel or filter reader (or combinations of that)- Throws:
IOException
-
newIOContext
TODO: javadoc -
newIOContext
TODO: javadoc -
overrideTestDefaultQueryCache
public void overrideTestDefaultQueryCache() -
overrideDefaultQueryCache
public static void overrideDefaultQueryCache() -
resetDefaultQueryCache
public static void resetDefaultQueryCache() -
setupCPUCoreCount
public static void setupCPUCoreCount() -
restoreCPUCoreCount
public static void restoreCPUCoreCount() -
setUpExecutorService
public static void setUpExecutorService() -
shutdownExecutorService
public static void shutdownExecutorService() -
newSearcher
Create a new searcher over the reader. This searcher might randomly use threads. -
newSearcher
Create a new searcher over the reader. This searcher might randomly use threads. -
newSearcher
public static IndexSearcher newSearcher(IndexReader r, boolean maybeWrap, boolean wrapWithAssertions) Create a new searcher over the reader. This searcher might randomly use threads. ifmaybeWrapis true, this searcher might wrap the reader with one that returns null for getSequentialSubReaders. IfwrapWithAssertionsis true, this searcher might be anAssertingIndexSearcherinstance. -
newSearcher
public static IndexSearcher newSearcher(IndexReader r, boolean maybeWrap, boolean wrapWithAssertions, boolean useThreads) Create a new searcher over the reader. IfmaybeWrapis true, this searcher might wrap the reader with one that returns null for getSequentialSubReaders. IfwrapWithAssertionsis true, this searcher might be anAssertingIndexSearcherinstance. The searcher will use threads ifuseThreadsis set to true. -
newSearcher
public static IndexSearcher newSearcher(IndexReader r, boolean maybeWrap, boolean wrapWithAssertions, LuceneTestCase.Concurrency concurrency) -
getDataPath
Gets a resource from the test's classpath asPath. This method should only be used, if a real file is needed. To get a stream, code should prefergetDataInputStream(String).- Throws:
IOException
-
getDataInputStream
Gets a resource from the test's classpath asInputStream.- Throws:
IOException
-
assertReaderEquals
public void assertReaderEquals(String info, IndexReader leftReader, IndexReader rightReader) throws IOException - Throws:
IOException
-
assertReaderStatisticsEquals
public void assertReaderStatisticsEquals(String info, IndexReader leftReader, IndexReader rightReader) throws IOException checks that reader-level statistics are the same- Throws:
IOException
-
assertTermsEquals
public void assertTermsEquals(String info, IndexReader leftReader, IndexReader rightReader, boolean deep) throws IOException Fields api equivalency- Throws:
IOException
-
assertTermsEquals
public void assertTermsEquals(String info, IndexReader leftReader, Terms leftTerms, Terms rightTerms, boolean deep) throws IOException Terms api equivalency- Throws:
IOException
-
assertTermsStatisticsEquals
public void assertTermsStatisticsEquals(String info, Terms leftTerms, Terms rightTerms) throws IOException checks collection-level statistics on Terms- Throws:
IOException
-
assertTermsEnumEquals
public void assertTermsEnumEquals(String info, IndexReader leftReader, TermsEnum leftTermsEnum, TermsEnum rightTermsEnum, boolean deep) throws IOException checks the terms enum sequentially if deep is false, it does a 'shallow' test that doesnt go down to the docsenums- Throws:
IOException
-
assertDocsAndPositionsEnumEquals
public void assertDocsAndPositionsEnumEquals(String info, PostingsEnum leftDocs, PostingsEnum rightDocs) throws IOException checks docs + freqs + positions + payloads, sequentially- Throws:
IOException
-
assertDocsEnumEquals
public void assertDocsEnumEquals(String info, PostingsEnum leftDocs, PostingsEnum rightDocs, boolean hasFreqs) throws IOException checks docs + freqs, sequentially- Throws:
IOException
-
assertDocsSkippingEquals
public void assertDocsSkippingEquals(String info, IndexReader leftReader, int docFreq, PostingsEnum leftDocs, PostingsEnum rightDocs, boolean hasFreqs) throws IOException checks advancing docs- Throws:
IOException
-
assertPositionsSkippingEquals
public void assertPositionsSkippingEquals(String info, IndexReader leftReader, int docFreq, PostingsEnum leftDocs, PostingsEnum rightDocs) throws IOException checks advancing docs + positions- Throws:
IOException
-
assertTermStatsEquals
public void assertTermStatsEquals(String info, TermsEnum leftTermsEnum, TermsEnum rightTermsEnum) throws IOException checks term-level statistics- Throws:
IOException
-
assertNormsEquals
public void assertNormsEquals(String info, IndexReader leftReader, IndexReader rightReader) throws IOException checks that norms are the same across all fields- Throws:
IOException
-
assertStoredFieldsEquals
public void assertStoredFieldsEquals(String info, IndexReader leftReader, IndexReader rightReader) throws IOException checks that stored fields of all documents are the same- Throws:
IOException
-
assertStoredFieldEquals
public void assertStoredFieldEquals(String info, IndexableField leftField, IndexableField rightField) checks that two stored fields are equivalent -
assertTermVectorsEquals
public void assertTermVectorsEquals(String info, IndexReader leftReader, IndexReader rightReader) throws IOException checks that term vectors across all fields are equivalent- Throws:
IOException
-
assertDocValuesEquals
public void assertDocValuesEquals(String info, IndexReader leftReader, IndexReader rightReader) throws IOException checks that docvalues across all fields are equivalent- Throws:
IOException
-
assertDocValuesEquals
public void assertDocValuesEquals(String info, int num, NumericDocValues leftDocValues, NumericDocValues rightDocValues) throws IOException - Throws:
IOException
-
assertDeletedDocsEquals
public void assertDeletedDocsEquals(String info, IndexReader leftReader, IndexReader rightReader) throws IOException - Throws:
IOException
-
assertFieldInfosEquals
public void assertFieldInfosEquals(String info, IndexReader leftReader, IndexReader rightReader) throws IOException - Throws:
IOException
-
assertPointsEquals
public void assertPointsEquals(String info, IndexReader leftReader, IndexReader rightReader) throws IOException - Throws:
IOException
-
callStackContains
Inspects stack trace to figure out if a method of a specific class called us. -
callStackContainsAnyOf
Inspects stack trace to figure out if one of the given method names (no class restriction) called us. -
callStackContains
Inspects stack trace if the given class called us. -
expectThrows
public static <T extends Throwable> T expectThrows(Class<T> expectedType, LuceneTestCase.ThrowingRunnable runnable) Checks a specific exception class is thrown by the given runnable, and returns it. -
expectThrows
public static <T extends Throwable> T expectThrows(Class<T> expectedType, String noExceptionMessage, LuceneTestCase.ThrowingRunnable runnable) Checks a specific exception class is thrown by the given runnable, and returns it. -
expectThrowsAnyOf
public static <T extends Throwable> T expectThrowsAnyOf(List<Class<? extends T>> expectedTypes, LuceneTestCase.ThrowingRunnable runnable) Checks a specific exception class is thrown by the given runnable, and returns it. -
expectThrows
public static <TO extends Throwable,TW extends Throwable> TW expectThrows(Class<TO> expectedOuterType, Class<TW> expectedWrappedType, LuceneTestCase.ThrowingRunnable runnable) Checks that specific wrapped and outer exception classes are thrown by the given runnable, and returns the wrapped exception. -
expectThrowsAnyOf
public static <TO extends Throwable,TW extends Throwable> TO expectThrowsAnyOf(LinkedHashMap<Class<? extends TO>, List<Class<? extends TW>>> expectedOuterToWrappedTypes, LuceneTestCase.ThrowingRunnable runnable) Checks that one of the specified wrapped and outer exception classes are thrown by the given runnable, and returns the outer exception.This method accepts outer exceptions with no wrapped exception; an empty list of expected wrapped exception types indicates no wrapped exception.
-
slowFileExists
Returns true if the file exists (can be opened), false if it cannot be opened, and (unlike Java's File.exists) throws IOException if there's some unexpected error.- Throws:
IOException
-
createTempDir
Creates an empty, temporary folder (when the name of the folder is of no importance).- See Also:
-
createTempDir
Creates an empty, temporary folder with the given name prefix.The folder will be automatically removed after the test class completes successfully. The test should close any file handles that would prevent the folder from being removed.
-
createTempFile
Creates an empty file with the given prefix and suffix.The file will be automatically removed after the test class completes successfully. The test should close any file handles that would prevent the folder from being removed.
- Throws:
IOException
-
createTempFile
Creates an empty temporary file.- Throws:
IOException- See Also:
-
getJvmForkArguments
Returns a set of JVM arguments to fork a JVM with the same class or module path (including any associated JVM options). The returned value may be empty. This method may throw an assertion error if fork options cannot be reliably acquired (at the moment they are collected and passed as an external file in gradle scripts).JVM forking is strongly discouraged as it makes test slower and more resource-hungry. Consider all alternatives first.
- Throws:
IOException
-
runWithRestrictedPermissions
public static <T> T runWithRestrictedPermissions(PrivilegedExceptionAction<T> action, Permission... permissions) throws Exception Runs a code part with restricted permissions (be sure to add all required permissions, because it would start with empty permissions). You cannot grant more permissions than our policy file allows, but you may restrict writing to several dirs...Note: This assumes a
SecurityManagerenabled, otherwise it stops test execution. If enabled, it needs the followingSecurityPermission:"createAccessControlContext"- Throws:
Exception
-
collate
Compares two strings with a collator, also looking to see if the strings are impacted by jdk bugs. may not avoid all jdk bugs in tests. see https://bugs.openjdk.java.net/browse/JDK-8071862 -
ensureSaneIWCOnNightly
Ensures that the MergePolicy has sane values for tests that test with lots of documents. -
newBytesRef
Creates aBytesRefholding UTF-8 bytes for the incoming String, that sometimes uses a non-zerooffset, and non-zero end-padding, to tickle latent bugs that fail to look atBytesRef.offset. -
newBytesRef
Creates a copy of the incomingBytesRefthat sometimes uses a non-zerooffset, and non-zero end-padding, to tickle latent bugs that fail to look atBytesRef.offset. -
newBytesRef
Creates a random BytesRef from the incoming bytes that sometimes uses a non-zerooffset, and non-zero end-padding, to tickle latent bugs that fail to look atBytesRef.offset. -
newBytesRef
Creates a random empty BytesRef that sometimes uses a non-zerooffset, and non-zero end-padding, to tickle latent bugs that fail to look atBytesRef.offset. -
newBytesRef
Creates a random empty BytesRef, with at least the requested length of bytes free, that sometimes uses a non-zerooffset, and non-zero end-padding, to tickle latent bugs that fail to look atBytesRef.offset. -
newBytesRef
Creates a copy of the incoming bytes slice that sometimes uses a non-zerooffset, and non-zero end-padding, to tickle latent bugs that fail to look atBytesRef.offset. -
randomVectorFormat
-