|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.junit.Assert org.apache.lucene.util.LuceneTestCase
public abstract class LuceneTestCase
Base class for all Lucene unit tests, Junit3 or Junit4 variant.
If you
override either setUp()
or
tearDown()
in your unit test, make sure you
call super.setUp()
and
super.tearDown()
@After
- replaces setup
@Before
- replaces teardown
@Test
- any public method with this annotation is a test case, regardless
of its name
See Junit4 documentation for a complete list of features.
Import from org.junit rather than junit.framework.
You should be able to use this class anywhere you used LuceneTestCase if you annotate your derived class correctly with the annotations above
assertSaneFieldCaches(String)
Nested Class Summary | |
---|---|
static interface |
LuceneTestCase.Nightly
Annotation for tests that should only be run during nightly builds. |
Field Summary | |
---|---|
static org.junit.rules.TestRule |
classRules
This controls how suite-level rules are nested. |
protected static SmartRandom |
random
|
static int |
RANDOM_MULTIPLIER
A random multiplier which you should use when writing random tests: multiply it by the number of iterations |
org.junit.rules.TestRule |
ruleChain
This controls how individual test rules are nested. |
protected static Map<MockDirectoryWrapper,StackTraceElement[]> |
stores
|
static File |
TEMP_DIR
Create indexes in this directory, optimally use a subdir, named after the test |
static String |
TEST_CLEAN_THREADS
whether or not to clean threads between test invocations: "false", "perMethod", "perClass" |
static String |
TEST_DIRECTORY
Gets the directory to run tests with |
static int |
TEST_ITER
Get the number of times to run tests |
static int |
TEST_ITER_MIN
Get the minimum number of times to run tests until a failure happens |
static String |
TEST_LINE_DOCS_FILE
the line file used by LineFileDocs |
static String |
TEST_LOCALE
Gets the locale to run tests with |
static boolean |
TEST_NIGHTLY
whether or not nightly tests should run |
static String |
TEST_SEED
Get the random seed for tests |
static String |
TEST_TIMEZONE
Gets the timezone to run tests with |
static Version |
TEST_VERSION_CURRENT
Use this constant when creating Analyzers and any other version-dependent stuff. |
protected static boolean |
testsFailed
|
static boolean |
VERBOSE
true iff tests are run in verbose mode. |
Constructor Summary | |
---|---|
LuceneTestCase()
|
Method Summary | ||
---|---|---|
static void |
afterClassLuceneTestCaseJ4()
|
|
void |
alwaysIgnoredTestMethod()
|
|
static void |
assertEquals(double expected,
double actual)
Deprecated. |
|
static void |
assertEquals(float expected,
float actual)
Deprecated. |
|
static void |
assertEquals(String message,
double expected,
double actual)
Deprecated. |
|
static void |
assertEquals(String message,
float expected,
float actual)
Deprecated. |
|
protected void |
assertSaneFieldCaches(String msg)
Asserts that FieldCacheSanityChecker does not detect any problems with FieldCache.DEFAULT. |
|
static
|
asSet(T... args)
|
|
static void |
assumeFalse(String msg,
boolean b)
|
|
static void |
assumeNoException(String msg,
Exception e)
|
|
static void |
assumeTrue(String msg,
boolean b)
|
|
static int |
atLeast(int i)
|
|
static int |
atLeast(Random random,
int i)
Returns a number of at least i |
|
static void |
beforeClassLuceneTestCaseJ4()
|
|
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. |
|
protected File |
getDataFile(String name)
Gets a resource from the classpath as File . |
|
String |
getName()
|
|
static Class<?> |
getTestClass()
Return the current class being tested. |
|
protected String |
getTestLabel()
|
|
protected boolean |
isTestThread()
Returns true if and only if the calling thread is the primary thread executing the test case. |
|
static Locale |
localeForName(String localeName)
return a Locale object equivalent to its programmatic name |
|
static MockDirectoryWrapper |
newDirectory()
Returns a new Directory instance. |
|
static MockDirectoryWrapper |
newDirectory(Directory d)
Returns a new Directory instance, with contents copied from the provided directory. |
|
static MockDirectoryWrapper |
newDirectory(Random r)
Returns a new Directory instance, using the specified random. |
|
static MockDirectoryWrapper |
newDirectory(Random r,
Directory d)
Returns a new Directory instance, using the specified random with contents copied from the provided directory. |
|
static Field |
newField(Random random,
String name,
String value,
Field.Index index)
Returns a new field instance, using the specified random. |
|
static Field |
newField(Random random,
String name,
String value,
Field.Store store,
Field.Index index)
Returns a new field instance, using the specified random. |
|
static Field |
newField(Random random,
String name,
String value,
Field.Store store,
Field.Index index,
Field.TermVector tv)
Returns a new field instance, using the specified random. |
|
static Field |
newField(String name,
String value,
Field.Index index)
Returns a new field instance. |
|
static Field |
newField(String name,
String value,
Field.Store store,
Field.Index index)
Returns a new field instance. |
|
static Field |
newField(String name,
String value,
Field.Store store,
Field.Index index,
Field.TermVector tv)
Returns a new Field instance. |
|
static MockDirectoryWrapper |
newFSDirectory(File f)
Returns a new FSDirectory instance over the given file, which must be a folder. |
|
static MockDirectoryWrapper |
newFSDirectory(File f,
LockFactory lf)
Returns a new FSDirectory instance over the given file, which must be a folder. |
|
static IndexWriterConfig |
newIndexWriterConfig(Random r,
Version v,
Analyzer a)
create a new index writer config with random defaults using the specified random |
|
static IndexWriterConfig |
newIndexWriterConfig(Version v,
Analyzer a)
create a new index writer config with random defaults |
|
static LogMergePolicy |
newLogMergePolicy()
|
|
static LogMergePolicy |
newLogMergePolicy(boolean useCFS)
|
|
static LogMergePolicy |
newLogMergePolicy(boolean useCFS,
int mergeFactor)
|
|
static LogMergePolicy |
newLogMergePolicy(int mergeFactor)
|
|
static LogMergePolicy |
newLogMergePolicy(Random r)
|
|
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 TieredMergePolicy |
newTieredMergePolicy()
|
|
static TieredMergePolicy |
newTieredMergePolicy(Random r)
|
|
protected void |
purgeFieldCache(FieldCache fc)
Forcible purges all cache entries from the FieldCache. |
|
static String |
randomDirectory(Random random)
|
|
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, |
|
void |
reportAdditionalFailureInfo()
|
|
static void |
reportPartialFailureInfo()
|
|
static void |
setMergeFactor(MergePolicy mp,
int mergeFactor)
|
|
void |
setUp()
For subclassing only. |
|
static void |
setUseCompoundFile(MergePolicy mp,
boolean useCompound)
|
|
void |
tearDown()
For subclassing only. |
|
static boolean |
usually()
|
|
static boolean |
usually(Random random)
|
Methods inherited from class org.junit.Assert |
---|
assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertThat, assertThat, assertTrue, assertTrue, fail, fail |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final boolean VERBOSE
public static final Version TEST_VERSION_CURRENT
NOTE: Change this when development starts for new Lucene version:
public static final File TEMP_DIR
public static final String TEST_LOCALE
public static final String TEST_TIMEZONE
public static final String TEST_DIRECTORY
public static final int TEST_ITER
public static final int TEST_ITER_MIN
public static final String TEST_SEED
public static final boolean TEST_NIGHTLY
public static final String TEST_LINE_DOCS_FILE
public static final String TEST_CLEAN_THREADS
public static final int RANDOM_MULTIPLIER
protected static Map<MockDirectoryWrapper,StackTraceElement[]> stores
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.
protected static boolean testsFailed
protected static final SmartRandom random
Constructor Detail |
---|
public LuceneTestCase()
Method Detail |
---|
public static void beforeClassLuceneTestCaseJ4()
public static void afterClassLuceneTestCaseJ4()
protected void purgeFieldCache(FieldCache fc)
This method will be called by tearDown to clean up FieldCache.DEFAULT. If a (poorly written) test has some expectation that the FieldCache will persist across test methods (ie: a static IndexReader) this method can be overridden to do nothing.
FieldCache.purgeAllCaches()
protected String getTestLabel()
public static void setUseCompoundFile(MergePolicy mp, boolean useCompound)
public static void setMergeFactor(MergePolicy mp, int mergeFactor)
protected boolean isTestThread()
public void setUp() throws Exception
super.setUp()
.
Exception
public void tearDown() throws Exception
super.tearDown()
.
Exception
protected void assertSaneFieldCaches(String msg)
If any problems are found, they are logged to System.err (allong with the msg) when the Assertion is thrown.
This method is called by tearDown after every test method, however IndexReaders scoped inside test methods may be garbage collected prior to this method being called, causing errors to be overlooked. Tests are encouraged to keep their IndexReaders scoped at the class level, or to explicitly call this method directly in the same scope as the IndexReader.
FieldCacheSanityChecker
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()
@Deprecated public static void assertEquals(double expected, double actual)
@Deprecated public static void assertEquals(String message, double expected, double actual)
@Deprecated public static void assertEquals(float expected, float actual)
@Deprecated public static void assertEquals(String message, float expected, float actual)
public static void assumeTrue(String msg, boolean b)
public static void assumeFalse(String msg, boolean b)
public static void assumeNoException(String msg, Exception e)
public static <T> Set<T> asSet(T... args)
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)
dumpIterator(String,Iterator,PrintStream)
public static IndexWriterConfig newIndexWriterConfig(Version v, Analyzer a)
public static IndexWriterConfig newIndexWriterConfig(Random r, Version v, Analyzer a)
public static LogMergePolicy newLogMergePolicy()
public static TieredMergePolicy newTieredMergePolicy()
public static LogMergePolicy newLogMergePolicy(Random r)
public static TieredMergePolicy newTieredMergePolicy(Random r)
public static LogMergePolicy newLogMergePolicy(boolean useCFS)
public static LogMergePolicy newLogMergePolicy(boolean useCFS, int mergeFactor)
public static LogMergePolicy newLogMergePolicy(int mergeFactor)
public static MockDirectoryWrapper newDirectory() throws IOException
The Directory is wrapped with MockDirectoryWrapper
.
By default this means 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.
IOException
public static MockDirectoryWrapper newDirectory(Random r) throws IOException
newDirectory()
for more information.
IOException
public static MockDirectoryWrapper newDirectory(Directory d) throws IOException
newDirectory()
for more
information.
IOException
public static MockDirectoryWrapper newFSDirectory(File f) throws IOException
IOException
public static MockDirectoryWrapper newFSDirectory(File f, LockFactory lf) throws IOException
IOException
public static MockDirectoryWrapper newDirectory(Random r, Directory d) throws IOException
newDirectory()
for more information.
IOException
public static Field newField(String name, String value, Field.Index index)
newField(String, String, Field.Store, Field.Index, Field.TermVector)
for more information
public static Field newField(String name, String value, Field.Store store, Field.Index index)
newField(String, String, Field.Store, Field.Index, Field.TermVector)
for more information
public static Field newField(String name, String value, Field.Store store, Field.Index index, Field.TermVector tv)
public static Field newField(Random random, String name, String value, Field.Index index)
newField(String, String, Field.Store, Field.Index, Field.TermVector)
for more information
public static Field newField(Random random, String name, String value, Field.Store store, Field.Index index)
newField(String, String, Field.Store, Field.Index, Field.TermVector)
for more information
public static Field newField(Random random, String name, String value, Field.Store store, Field.Index index, Field.TermVector tv)
newField(String, String, Field.Store, Field.Index, Field.TermVector)
for more information
public static Locale randomLocale(Random random)
public static TimeZone randomTimeZone(Random random)
public static Locale localeForName(String localeName)
public static String randomDirectory(Random random)
public static IndexSearcher newSearcher(IndexReader r) throws IOException
IOException
public static IndexSearcher newSearcher(IndexReader r, boolean maybeWrap) throws IOException
maybeWrap
is true, this searcher might wrap the reader
with one that returns null for getSequentialSubReaders.
IOException
public String getName()
protected File getDataFile(String name) throws IOException
File
. This method should only be used,
if a real file is needed. To get a stream, code should prefer
Class.getResourceAsStream(java.lang.String)
using this.getClass()
.
IOException
public static void reportPartialFailureInfo()
public void reportAdditionalFailureInfo()
public static Class<?> getTestClass()
public final void alwaysIgnoredTestMethod()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |