@TestMethodProviders(value={LuceneJUnit3MethodProvider.class,com.carrotsearch.randomizedtesting.JUnit4MethodProvider.class}) @Listeners(value={RunListenerPrintReproduceInfo.class,FailureMarker.class}) @SeedDecorators(value=com.carrotsearch.randomizedtesting.MixWithSuiteName.class) @TestRuleLimitSysouts.Limit(bytes=8192) public abstract class LuceneTestCase extends Assert
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.
Any test method with a testXXX
prefix is considered a test case.
Any test method annotated with Test
is considered a test case.
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:
RandomizedContext.current()
) and then calling
RandomizedContext.getRunnerSeedAsString()
.Modifier and Type | Class and Description |
---|---|
static interface |
LuceneTestCase.AwaitsFix
Annotation for tests which exhibit a known issue and are temporarily disabled.
|
static interface |
LuceneTestCase.BadApple
Annotation for tests that fail frequently and should
be moved to a "vault" plan in Jenkins.
|
static interface |
LuceneTestCase.Monster
Annotation for monster tests that require special setup (e.g.
|
static interface |
LuceneTestCase.Nightly
Annotation for tests that should only be run during nightly builds.
|
static interface |
LuceneTestCase.Slow
Annotation for tests that are slow.
|
static interface |
LuceneTestCase.SuppressCodecs
Annotation for test classes that should avoid certain codec types
(because they are expensive, for example).
|
static interface |
LuceneTestCase.SuppressFileSystems
Annotation for test classes that should avoid mock filesystem types
(because they test a bug that only happens on linux, for example).
|
static interface |
LuceneTestCase.SuppressFsync
Annotation for test classes that should avoid always omit
actual fsync calls from reaching the filesystem.
|
static interface |
LuceneTestCase.SuppressReproduceLine
Suppress the default
reproduce with: ant test...
Your own listener can be added as needed for your build. |
static interface |
LuceneTestCase.SuppressSysoutChecks
Ignore
TestRuleLimitSysouts for any suite which is known to print
over the default limit of bytes to System.out or System.err . |
static interface |
LuceneTestCase.SuppressTempFileChecks
Marks any suites which are known not to close all the temporary
files.
|
static interface |
LuceneTestCase.ThrowingRunnable
A runnable that can throw any checked exception.
|
static interface |
LuceneTestCase.Weekly
Annotation for tests that should only be run during weekly builds
|
Modifier and Type | Field and Description |
---|---|
static boolean |
assertsAreEnabled
True if assertions (-ea) are enabled (at least for this class).
|
static org.junit.rules.TestRule |
classRules
This controls how suite-level rules are nested.
|
static String |
DEFAULT_LINE_DOCS_FILE
TODO: javadoc?
|
static boolean |
INFOSTREAM
Enables or disables dumping of
InfoStream messages. |
static String |
JENKINS_LARGE_LINE_DOCS_FILE
TODO: javadoc?
|
static boolean |
LEAVE_TEMPORARY
Leave temporary files on disk, even on successful runs.
|
static QueryCachingPolicy |
MAYBE_CACHE_POLICY
A
QueryCachingPolicy that randomly caches. |
static int |
RANDOM_MULTIPLIER
A random multiplier which you should use when writing random tests:
multiply it by the number of iterations to scale your tests (for nightly builds).
|
org.junit.rules.TestRule |
ruleChain
This controls how individual test rules are nested.
|
protected static TestRuleMarkFailure |
suiteFailureMarker
Suite failure marker (any error in the test or suite scope).
|
static String |
SYSPROP_AWAITSFIX |
static String |
SYSPROP_BADAPPLES |
static String |
SYSPROP_FAILFAST |
static String |
SYSPROP_MAXFAILURES |
static String |
SYSPROP_MONSTER |
static String |
SYSPROP_NIGHTLY |
static String |
SYSPROP_SLOW |
static String |
SYSPROP_WEEKLY |
static boolean |
TEST_ASSERTS_ENABLED |
static boolean |
TEST_AWAITSFIX
Whether or not
LuceneTestCase.AwaitsFix tests should run. |
static String |
TEST_CODEC
Gets the codec to run tests with.
|
static String |
TEST_DIRECTORY
Gets the directory to run tests with
|
static String |
TEST_DOCVALUESFORMAT
Gets the docValuesFormat to run tests with
|
static String |
TEST_LINE_DOCS_FILE
the line file used by LineFileDocs
|
static boolean |
TEST_NIGHTLY
Whether or not
LuceneTestCase.Nightly tests should run. |
static String |
TEST_POSTINGSFORMAT
Gets the postingsFormat to run tests with.
|
static boolean |
TEST_SLOW
Whether or not
LuceneTestCase.Slow tests should run. |
static MockDirectoryWrapper.Throttling |
TEST_THROTTLING
Throttling, see
MockDirectoryWrapper.setThrottling(Throttling) . |
static boolean |
TEST_WEEKLY
Whether or not
LuceneTestCase.Weekly tests should run. |
static boolean |
VERBOSE
True if and only if tests are run in verbose mode.
|
Constructor and Description |
---|
LuceneTestCase() |
Modifier and Type | Method and Description |
---|---|
static Path |
addVirusChecker(Path path) |
void |
assertDeletedDocsEquals(String info,
IndexReader leftReader,
IndexReader rightReader) |
void |
assertDocsAndPositionsEnumEquals(String info,
PostingsEnum leftDocs,
PostingsEnum rightDocs)
checks docs + freqs + positions + payloads, sequentially
|
void |
assertDocsEnumEquals(String info,
PostingsEnum leftDocs,
PostingsEnum rightDocs,
boolean hasFreqs)
checks docs + freqs, sequentially
|
void |
assertDocsSkippingEquals(String info,
IndexReader leftReader,
int docFreq,
PostingsEnum leftDocs,
PostingsEnum rightDocs,
boolean hasFreqs)
checks advancing docs
|
void |
assertDocValuesEquals(String info,
IndexReader leftReader,
IndexReader rightReader)
checks that docvalues across all fields are equivalent
|
void |
assertDocValuesEquals(String info,
int num,
NumericDocValues leftDocValues,
NumericDocValues rightDocValues) |
void |
assertFieldInfosEquals(String info,
IndexReader leftReader,
IndexReader rightReader) |
void |
assertFieldsEquals(String info,
IndexReader leftReader,
Fields leftFields,
Fields rightFields,
boolean deep)
Fields api equivalency
|
void |
assertFieldStatisticsEquals(String info,
Fields leftFields,
Fields rightFields)
checks that top-level statistics on Fields are the same
|
void |
assertNormsEquals(String info,
IndexReader leftReader,
IndexReader rightReader)
checks that norms are the same across all fields
|
void |
assertPointsEquals(String info,
IndexReader leftReader,
IndexReader rightReader) |
void |
assertPositionsSkippingEquals(String info,
IndexReader leftReader,
int docFreq,
PostingsEnum leftDocs,
PostingsEnum rightDocs)
checks advancing docs + positions
|
void |
assertReaderEquals(String info,
IndexReader leftReader,
IndexReader rightReader) |
void |
assertReaderStatisticsEquals(String info,
IndexReader leftReader,
IndexReader rightReader)
checks that reader-level statistics are the same
|
void |
assertStoredFieldEquals(String info,
IndexableField leftField,
IndexableField rightField)
checks that two stored fields are equivalent
|
void |
assertStoredFieldsEquals(String info,
IndexReader leftReader,
IndexReader rightReader)
checks that stored fields of all documents are the same
|
void |
assertTermsEnumEquals(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 docsenums
|
void |
assertTermsEquals(String info,
IndexReader leftReader,
Terms leftTerms,
Terms rightTerms,
boolean deep)
Terms api equivalency
|
void |
assertTermsStatisticsEquals(String info,
Terms leftTerms,
Terms rightTerms)
checks collection-level statistics on Terms
|
void |
assertTermStatsEquals(String info,
TermsEnum leftTermsEnum,
TermsEnum rightTermsEnum)
checks term-level statistics
|
void |
assertTermVectorsEquals(String info,
IndexReader leftReader,
IndexReader rightReader)
checks that term vectors across all fields are equivalent
|
static <T> Set<T> |
asSet(T... args)
Return
args as a Set instance. |
static void |
assumeFalse(String msg,
boolean condition) |
static void |
assumeNoException(String msg,
Exception e) |
static void |
assumeTrue(String msg,
boolean condition) |
static int |
atLeast(int i) |
static int |
atLeast(Random random,
int i)
Returns a number of at least
i |
static <T extends Closeable> |
closeAfterSuite(T resource)
Registers a
Closeable resource that should be closed after the suite
completes. |
<T extends Closeable> |
closeAfterTest(T resource)
Registers a
Closeable resource that should be closed after the test
completes. |
static int |
collate(Collator collator,
String s1,
String s2)
Compares two strings with a collator, also looking to see if the the strings
are impacted by jdk bugs.
|
static Path |
createTempDir()
Creates an empty, temporary folder (when the name of the folder is of no importance).
|
static Path |
createTempDir(String prefix)
Creates an empty, temporary folder with the given name prefix under the
test class's
getBaseTempDirForTestClass() . |
static Path |
createTempFile()
Creates an empty temporary file.
|
static Path |
createTempFile(String prefix,
String suffix)
Creates an empty file with the given prefix and suffix under the
test class's
getBaseTempDirForTestClass() . |
static void |
dumpArray(String label,
Object[] objs,
PrintStream stream)
Convenience method for logging an array.
|
static void |
dumpIterator(String label,
Iterator<?> iter,
PrintStream stream)
Convenience method for logging an iterator.
|
static <T extends Throwable> |
expectThrows(Class<T> expectedType,
LuceneTestCase.ThrowingRunnable runnable)
Checks a specific exception class is thrown by the given runnable, and returns it.
|
static Path |
getBaseTempDirForTestClass()
Deprecated.
|
protected InputStream |
getDataInputStream(String name)
Gets a resource from the test's classpath as
InputStream . |
protected Path |
getDataPath(String name)
Gets a resource from the test's classpath as
Path . |
static LeafReader |
getOnlyLeafReader(IndexReader reader)
Some tests expect the directory to contain a single segment, and want to
do tests on that segment's reader.
|
static Class<?> |
getTestClass()
Return the current class being tested.
|
String |
getTestName()
Return the name of the currently executing test case.
|
protected boolean |
isTestThread()
Returns true if and only if the calling thread is the primary thread
executing the test case.
|
static Locale |
localeForLanguageTag(String languageTag)
return a Locale object equivalent to its programmatic name
|
static void |
maybeChangeLiveIndexWriterConfig(Random r,
LiveIndexWriterConfig c) |
static IndexReader |
maybeWrapReader(IndexReader r)
Sometimes wrap the IndexReader as slow, parallel or filter reader (or
combinations of that)
|
static AlcoholicMergePolicy |
newAlcoholicMergePolicy() |
static AlcoholicMergePolicy |
newAlcoholicMergePolicy(Random r,
TimeZone tz) |
static BaseDirectoryWrapper |
newDirectory()
Returns a new Directory instance.
|
static BaseDirectoryWrapper |
newDirectory(Directory d)
Returns a new Directory instance, with contents copied from the
provided directory.
|
static BaseDirectoryWrapper |
newDirectory(Random r)
Returns a new Directory instance, using the specified random.
|
static BaseDirectoryWrapper |
newDirectory(Random r,
Directory d)
Returns a new Directory instance, using the specified random
with contents copied from the provided directory.
|
static BaseDirectoryWrapper |
newDirectory(Random r,
LockFactory lf)
Returns a new Directory instance, using the specified random.
|
static Field |
newField(Random random,
String name,
Object value,
FieldType type) |
static Field |
newField(String name,
String value,
FieldType type) |
static BaseDirectoryWrapper |
newFSDirectory(Path f)
Returns a new FSDirectory instance over the given file, which must be a folder.
|
static BaseDirectoryWrapper |
newFSDirectory(Path f,
LockFactory lf)
Returns a new FSDirectory instance over the given file, which must be a folder.
|
static IndexWriterConfig |
newIndexWriterConfig()
create a new index writer config with random defaults
|
static IndexWriterConfig |
newIndexWriterConfig(Analyzer a)
create a new index writer config with random defaults
|
static IndexWriterConfig |
newIndexWriterConfig(Random r,
Analyzer a)
create a new index writer config with random defaults using the specified random
|
static IOContext |
newIOContext(Random random)
TODO: javadoc
|
static IOContext |
newIOContext(Random random,
IOContext oldContext)
TODO: javadoc
|
static LogMergePolicy |
newLogMergePolicy() |
static MergePolicy |
newLogMergePolicy(boolean useCFS) |
static MergePolicy |
newLogMergePolicy(boolean useCFS,
int mergeFactor) |
static MergePolicy |
newLogMergePolicy(int mergeFactor) |
static LogMergePolicy |
newLogMergePolicy(Random r) |
static BaseDirectoryWrapper |
newMaybeVirusCheckingDirectory()
Like
newDirectory() except randomly the VirusCheckingFS may be installed |
static BaseDirectoryWrapper |
newMaybeVirusCheckingFSDirectory(Path f)
Like
newFSDirectory(Path) , but randomly insert VirusCheckingFS |
static MergePolicy |
newMergePolicy() |
static MergePolicy |
newMergePolicy(Random r) |
static MockDirectoryWrapper |
newMockDirectory() |
static MockDirectoryWrapper |
newMockDirectory(Random r) |
static MockDirectoryWrapper |
newMockDirectory(Random r,
LockFactory lf) |
static MockDirectoryWrapper |
newMockFSDirectory(Path f) |
static MockDirectoryWrapper |
newMockFSDirectory(Path f,
LockFactory lf) |
static IndexSearcher |
newSearcher(IndexReader r)
Create a new searcher over the reader.
|
static IndexSearcher |
newSearcher(IndexReader r,
boolean maybeWrap)
Create a new searcher over the reader.
|
static IndexSearcher |
newSearcher(IndexReader r,
boolean maybeWrap,
boolean wrapWithAssertions)
Create a new searcher over the reader.
|
static Field |
newStringField(Random random,
String name,
BytesRef value,
Field.Store stored) |
static Field |
newStringField(Random random,
String name,
String value,
Field.Store stored) |
static Field |
newStringField(String name,
BytesRef value,
Field.Store stored) |
static Field |
newStringField(String name,
String value,
Field.Store stored) |
static Field |
newTextField(Random random,
String name,
String value,
Field.Store stored) |
static Field |
newTextField(String name,
String value,
Field.Store stored) |
static TieredMergePolicy |
newTieredMergePolicy() |
static TieredMergePolicy |
newTieredMergePolicy(Random r) |
static void |
overrideDefaultQueryCache() |
void |
overrideTestDefaultQueryCache() |
static Random |
random()
Access to the current
RandomizedContext 's Random instance. |
static Locale |
randomLocale(Random random)
Return a random Locale from the available locales on the system.
|
static TimeZone |
randomTimeZone(Random random)
Return a random TimeZone from the available timezones on the system
|
static boolean |
rarely() |
static boolean |
rarely(Random random)
Returns true if something should happen rarely,
|
static TestRuleIgnoreAfterMaxFailures |
replaceMaxFailureRule(TestRuleIgnoreAfterMaxFailures newValue)
Temporarily substitute the global
TestRuleIgnoreAfterMaxFailures . |
static void |
resetDefaultQueryCache() |
static void |
restoreCPUCoreCount() |
void |
restoreIndexWriterMaxDocs()
Returns to the default
IndexWriter.MAX_DOCS limit. |
static void |
restoreSpins() |
static <T> T |
runWithRestrictedPermissions(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).
|
void |
setIndexWriterMaxDocs(int limit)
Tells
IndexWriter to enforce the specified limit as the maximum number of documents in one index; call
restoreIndexWriterMaxDocs() once your test is done. |
void |
setUp()
For subclasses to override.
|
static void |
setupCPUCoreCount() |
static void |
setupSpins() |
static boolean |
slowFileExists(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.
|
void |
tearDown()
For subclasses to override.
|
static boolean |
usually() |
static boolean |
usually(Random random) |
static IndexReader |
wrapReader(IndexReader r) |
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, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertThat, assertThat, assertTrue, assertTrue, fail, fail
public static final String SYSPROP_NIGHTLY
public static final String SYSPROP_WEEKLY
public static final String SYSPROP_MONSTER
public static final String SYSPROP_AWAITSFIX
public static final String SYSPROP_SLOW
public static final String SYSPROP_BADAPPLES
public static final String SYSPROP_MAXFAILURES
ignoreAfterMaxFailures
,
Constant Field Valuespublic static final String SYSPROP_FAILFAST
ignoreAfterMaxFailures
,
Constant Field Valuespublic static final boolean VERBOSE
TestRuleLimitSysouts
.public static final boolean INFOSTREAM
InfoStream
messages.public static final int RANDOM_MULTIPLIER
public static final boolean TEST_ASSERTS_ENABLED
public static final String DEFAULT_LINE_DOCS_FILE
public static final String JENKINS_LARGE_LINE_DOCS_FILE
public static final String TEST_CODEC
public static final String TEST_POSTINGSFORMAT
public static final String TEST_DOCVALUESFORMAT
public static final String TEST_DIRECTORY
public static final String TEST_LINE_DOCS_FILE
public static final boolean TEST_NIGHTLY
LuceneTestCase.Nightly
tests should run.public static final boolean TEST_WEEKLY
LuceneTestCase.Weekly
tests should run.public static final boolean TEST_AWAITSFIX
LuceneTestCase.AwaitsFix
tests should run.public static final boolean TEST_SLOW
LuceneTestCase.Slow
tests should run.public static final MockDirectoryWrapper.Throttling TEST_THROTTLING
MockDirectoryWrapper.setThrottling(Throttling)
.public static final boolean LEAVE_TEMPORARY
public static final QueryCachingPolicy MAYBE_CACHE_POLICY
QueryCachingPolicy
that randomly caches.protected static TestRuleMarkFailure suiteFailureMarker
public static org.junit.rules.TestRule classRules
LuceneTestCase
are executed in proper order if they depend on each
other.public final org.junit.rules.TestRule ruleChain
LuceneTestCase
are executed in proper order
if they depend on each other.public static final boolean assertsAreEnabled
public static TestRuleIgnoreAfterMaxFailures replaceMaxFailureRule(TestRuleIgnoreAfterMaxFailures newValue)
TestRuleIgnoreAfterMaxFailures
. See
ignoreAfterMaxFailuresDelegate
for some explanation why this method
is needed.public void setUp() throws Exception
super.setUp()
.Exception
public void tearDown() throws Exception
super.tearDown()
.Exception
public void setIndexWriterMaxDocs(int limit)
IndexWriter
to enforce the specified limit as the maximum number of documents in one index; call
restoreIndexWriterMaxDocs()
once your test is done.public void restoreIndexWriterMaxDocs()
IndexWriter.MAX_DOCS
limit.public static Random random()
RandomizedContext
'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 returned Random
instance will be
different when this method is called inside a BeforeClass
hook (static
suite scope) and within Before
/ After
hooks or test methods.
The returned instance must not be shared with other threads or cross a single scope's
boundary. For example, a Random
acquired within a test method shouldn't be reused
for another test case.
There is an overhead connected with getting the Random
for a particular context
and thread. It is better to cache the Random
locally if tight loops with multiple
invocations are present or create a derivative local Random
for millions of calls
like this:
Random random = new Random(random().nextLong()); // tight loop with many invocations.
public <T extends Closeable> T closeAfterTest(T resource)
Closeable
resource that should be closed after the test
completes.resource
(for call chaining).public static <T extends Closeable> T closeAfterSuite(T resource)
Closeable
resource that should be closed after the suite
completes.resource
(for call chaining).public static Class<?> getTestClass()
public String getTestName()
public static LeafReader getOnlyLeafReader(IndexReader reader)
protected boolean isTestThread()
public static int atLeast(Random random, int i)
i
The actual number returned will be influenced by whether TEST_NIGHTLY
is active and RANDOM_MULTIPLIER
, but also with some random fudge.
public static int atLeast(int i)
public static boolean rarely(Random random)
The actual number returned will be influenced by whether TEST_NIGHTLY
is active and RANDOM_MULTIPLIER
.
public static boolean rarely()
public static boolean usually(Random random)
public static boolean usually()
public static void assumeTrue(String msg, boolean condition)
public static void assumeFalse(String msg, boolean condition)
@SafeVarargs public static <T> Set<T> asSet(T... args)
args
as a Set
instance. The order of elements is not
preserved in iterators.public static void dumpIterator(String label, Iterator<?> iter, PrintStream stream)
label
- String logged before/after the items in the iteratoriter
- Each next() is toString()ed and logged on it's own line. If iter is null this is logged differnetly then an empty iterator.stream
- Stream to log messages to.public static void dumpArray(String label, Object[] objs, PrintStream stream)
public static IndexWriterConfig newIndexWriterConfig()
public static IndexWriterConfig newIndexWriterConfig(Analyzer a)
public static IndexWriterConfig newIndexWriterConfig(Random r, Analyzer a)
public static MergePolicy newMergePolicy(Random r)
public static MergePolicy newMergePolicy()
public static LogMergePolicy newLogMergePolicy()
public static TieredMergePolicy newTieredMergePolicy()
public static AlcoholicMergePolicy newAlcoholicMergePolicy()
public static AlcoholicMergePolicy newAlcoholicMergePolicy(Random r, TimeZone tz)
public static LogMergePolicy newLogMergePolicy(Random r)
public static TieredMergePolicy newTieredMergePolicy(Random r)
public static MergePolicy newLogMergePolicy(boolean useCFS)
public static MergePolicy newLogMergePolicy(boolean useCFS, int mergeFactor)
public static MergePolicy newLogMergePolicy(int mergeFactor)
public static void maybeChangeLiveIndexWriterConfig(Random r, LiveIndexWriterConfig c)
public static BaseDirectoryWrapper newDirectory()
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.
public static BaseDirectoryWrapper newMaybeVirusCheckingDirectory()
newDirectory()
except randomly the VirusCheckingFS
may be installedpublic static BaseDirectoryWrapper newDirectory(Random r)
newDirectory()
for more information.public static BaseDirectoryWrapper newDirectory(Random r, LockFactory lf)
newDirectory()
for more information.public static MockDirectoryWrapper newMockDirectory()
public static MockDirectoryWrapper newMockDirectory(Random r)
public static MockDirectoryWrapper newMockDirectory(Random r, LockFactory lf)
public static MockDirectoryWrapper newMockFSDirectory(Path f)
public static MockDirectoryWrapper newMockFSDirectory(Path f, LockFactory lf)
public static BaseDirectoryWrapper newDirectory(Directory d) throws IOException
newDirectory()
for more
information.IOException
public static BaseDirectoryWrapper newFSDirectory(Path f)
public static BaseDirectoryWrapper newMaybeVirusCheckingFSDirectory(Path f)
newFSDirectory(Path)
, but randomly insert VirusCheckingFS
public static BaseDirectoryWrapper newFSDirectory(Path f, LockFactory lf)
public static BaseDirectoryWrapper newDirectory(Random r, Directory d) throws IOException
newDirectory()
for more information.IOException
public static Field newStringField(String name, String value, Field.Store stored)
public static Field newStringField(String name, BytesRef value, Field.Store stored)
public static Field newTextField(String name, String value, Field.Store stored)
public static Field newStringField(Random random, String name, String value, Field.Store stored)
public static Field newStringField(Random random, String name, BytesRef value, Field.Store stored)
public static Field newTextField(Random random, String name, String value, Field.Store stored)
public static Locale randomLocale(Random random)
public static TimeZone randomTimeZone(Random random)
public static Locale localeForLanguageTag(String languageTag)
public static IndexReader wrapReader(IndexReader r) throws IOException
IOException
public static IndexReader maybeWrapReader(IndexReader r) throws IOException
IOException
public static IOContext newIOContext(Random random, IOContext oldContext)
public void overrideTestDefaultQueryCache()
public static void overrideDefaultQueryCache()
public static void resetDefaultQueryCache()
public static void setupCPUCoreCount()
public static void restoreCPUCoreCount()
public static void setupSpins()
public static void restoreSpins()
public static IndexSearcher newSearcher(IndexReader r)
public static IndexSearcher newSearcher(IndexReader r, boolean maybeWrap)
public static IndexSearcher newSearcher(IndexReader r, boolean maybeWrap, boolean wrapWithAssertions)
maybeWrap
is true, this searcher might wrap the
reader with one that returns null for getSequentialSubReaders. If
wrapWithAssertions
is true, this searcher might be an
AssertingIndexSearcher
instance.protected Path getDataPath(String name) throws IOException
Path
. This method should only
be used, if a real file is needed. To get a stream, code should prefer
getDataInputStream(String)
.IOException
protected InputStream getDataInputStream(String name) throws IOException
InputStream
.IOException
public void assertReaderEquals(String info, IndexReader leftReader, IndexReader rightReader) throws IOException
IOException
public void assertReaderStatisticsEquals(String info, IndexReader leftReader, IndexReader rightReader) throws IOException
IOException
public void assertFieldsEquals(String info, IndexReader leftReader, Fields leftFields, Fields rightFields, boolean deep) throws IOException
IOException
public void assertFieldStatisticsEquals(String info, Fields leftFields, Fields rightFields) throws IOException
IOException
public void assertTermsEquals(String info, IndexReader leftReader, Terms leftTerms, Terms rightTerms, boolean deep) throws IOException
IOException
public void assertTermsStatisticsEquals(String info, Terms leftTerms, Terms rightTerms) throws IOException
IOException
public void assertTermsEnumEquals(String info, IndexReader leftReader, TermsEnum leftTermsEnum, TermsEnum rightTermsEnum, boolean deep) throws IOException
IOException
public void assertDocsAndPositionsEnumEquals(String info, PostingsEnum leftDocs, PostingsEnum rightDocs) throws IOException
IOException
public void assertDocsEnumEquals(String info, PostingsEnum leftDocs, PostingsEnum rightDocs, boolean hasFreqs) throws IOException
IOException
public void assertDocsSkippingEquals(String info, IndexReader leftReader, int docFreq, PostingsEnum leftDocs, PostingsEnum rightDocs, boolean hasFreqs) throws IOException
IOException
public void assertPositionsSkippingEquals(String info, IndexReader leftReader, int docFreq, PostingsEnum leftDocs, PostingsEnum rightDocs) throws IOException
IOException
public void assertTermStatsEquals(String info, TermsEnum leftTermsEnum, TermsEnum rightTermsEnum) throws IOException
IOException
public void assertNormsEquals(String info, IndexReader leftReader, IndexReader rightReader) throws IOException
IOException
public void assertStoredFieldsEquals(String info, IndexReader leftReader, IndexReader rightReader) throws IOException
IOException
public void assertStoredFieldEquals(String info, IndexableField leftField, IndexableField rightField)
public void assertTermVectorsEquals(String info, IndexReader leftReader, IndexReader rightReader) throws IOException
IOException
public void assertDocValuesEquals(String info, IndexReader leftReader, IndexReader rightReader) throws IOException
IOException
public void assertDocValuesEquals(String info, int num, NumericDocValues leftDocValues, NumericDocValues rightDocValues) throws IOException
IOException
public void assertDeletedDocsEquals(String info, IndexReader leftReader, IndexReader rightReader) throws IOException
IOException
public void assertFieldInfosEquals(String info, IndexReader leftReader, IndexReader rightReader) throws IOException
IOException
public void assertPointsEquals(String info, IndexReader leftReader, IndexReader rightReader) throws IOException
IOException
public static <T extends Throwable> T expectThrows(Class<T> expectedType, LuceneTestCase.ThrowingRunnable runnable)
public static boolean slowFileExists(Directory dir, String fileName) throws IOException
IOException
@Deprecated public static Path getBaseTempDirForTestClass()
createTempDir()
or createTempDir(String)
or createTempFile(String, String)
.public static Path createTempDir()
createTempDir(String)
public static Path createTempDir(String prefix)
getBaseTempDirForTestClass()
.
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.
public static Path createTempFile(String prefix, String suffix) throws IOException
getBaseTempDirForTestClass()
.
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.
IOException
public static Path createTempFile() throws IOException
IOException
createTempFile(String, String)
public static <T> T runWithRestrictedPermissions(PrivilegedExceptionAction<T> action, Permission... permissions) throws Exception
Note: This assumes a SecurityManager
enabled, otherwise it
stops test execution. If enabled, it needs the following SecurityPermission
:
"createAccessControlContext"
Exception
Copyright © 2000-2016 Apache Software Foundation. All Rights Reserved.