|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.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 class |
LuceneTestCase.LuceneTestCaseRunner
optionally filters the tests to be run by TEST_METHOD |
static interface |
LuceneTestCase.Nightly
Annotation for tests that should only be run during nightly builds. |
Field Summary | |
---|---|
org.junit.rules.TestWatchman |
intercept
|
protected static Random |
random
|
static int |
RANDOM_MULTIPLIER
A random multiplier which you should use when writing random tests: multiply it by the number of iterations |
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 org.apache.lucene.util.Version |
TEST_VERSION_CURRENT
Use this constant when creating Analyzers and any other version-dependent stuff. |
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 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()
|
protected String |
getTestLabel()
|
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(org.apache.lucene.store.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,
org.apache.lucene.store.Directory d)
Returns a new Directory instance, using the specified random with contents copied from the provided directory. |
static org.apache.lucene.document.Field |
newField(Random random,
String name,
String value,
org.apache.lucene.document.Field.Index index)
Returns a new field instance, using the specified random. |
static org.apache.lucene.document.Field |
newField(Random random,
String name,
String value,
org.apache.lucene.document.Field.Store store,
org.apache.lucene.document.Field.Index index)
Returns a new field instance, using the specified random. |
static org.apache.lucene.document.Field |
newField(Random random,
String name,
String value,
org.apache.lucene.document.Field.Store store,
org.apache.lucene.document.Field.Index index,
org.apache.lucene.document.Field.TermVector tv)
Returns a new field instance, using the specified random. |
static org.apache.lucene.document.Field |
newField(String name,
String value,
org.apache.lucene.document.Field.Index index)
Returns a new field instance. |
static org.apache.lucene.document.Field |
newField(String name,
String value,
org.apache.lucene.document.Field.Store store,
org.apache.lucene.document.Field.Index index)
Returns a new field instance. |
static org.apache.lucene.document.Field |
newField(String name,
String value,
org.apache.lucene.document.Field.Store store,
org.apache.lucene.document.Field.Index index,
org.apache.lucene.document.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,
org.apache.lucene.store.LockFactory lf)
Returns a new FSDirectory instance over the given file, which must be a folder. |
static org.apache.lucene.index.IndexWriterConfig |
newIndexWriterConfig(Random r,
org.apache.lucene.util.Version v,
org.apache.lucene.analysis.Analyzer a)
create a new index writer config with random defaults using the specified random |
static org.apache.lucene.index.IndexWriterConfig |
newIndexWriterConfig(org.apache.lucene.util.Version v,
org.apache.lucene.analysis.Analyzer a)
create a new index writer config with random defaults |
static org.apache.lucene.index.LogMergePolicy |
newLogMergePolicy()
|
static org.apache.lucene.index.LogMergePolicy |
newLogMergePolicy(boolean useCFS)
|
static org.apache.lucene.index.LogMergePolicy |
newLogMergePolicy(boolean useCFS,
int mergeFactor)
|
static org.apache.lucene.index.LogMergePolicy |
newLogMergePolicy(int mergeFactor)
|
static org.apache.lucene.index.LogMergePolicy |
newLogMergePolicy(Random r)
|
static org.apache.lucene.search.IndexSearcher |
newSearcher(org.apache.lucene.index.IndexReader r)
create a new searcher over the reader. |
static org.apache.lucene.search.IndexSearcher |
newSearcher(org.apache.lucene.index.IndexReader r,
boolean maybeWrap)
create a new searcher over the reader. |
static org.apache.lucene.index.TieredMergePolicy |
newTieredMergePolicy()
|
static org.apache.lucene.index.TieredMergePolicy |
newTieredMergePolicy(Random r)
|
protected void |
purgeFieldCache(org.apache.lucene.search.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, |
static void |
registerTempFile(File tmpFile)
Registers a temp file that will be deleted when tests are done. |
void |
reportAdditionalFailureInfo()
|
static void |
setMergeFactor(org.apache.lucene.index.MergePolicy mp,
int mergeFactor)
|
void |
setUp()
|
static void |
setUseCompoundFile(org.apache.lucene.index.MergePolicy mp,
boolean useCompound)
|
void |
tearDown()
|
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 org.apache.lucene.util.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 final org.junit.rules.TestWatchman intercept
protected static final Random random
Constructor Detail |
---|
public LuceneTestCase()
Method Detail |
---|
public static void beforeClassLuceneTestCaseJ4()
public static void afterClassLuceneTestCaseJ4()
public void setUp() throws Exception
Exception
protected void purgeFieldCache(org.apache.lucene.search.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(org.apache.lucene.index.MergePolicy mp, boolean useCompound)
public static void setMergeFactor(org.apache.lucene.index.MergePolicy mp, int mergeFactor)
public void tearDown() throws Exception
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 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 org.apache.lucene.index.IndexWriterConfig newIndexWriterConfig(org.apache.lucene.util.Version v, org.apache.lucene.analysis.Analyzer a)
public static org.apache.lucene.index.IndexWriterConfig newIndexWriterConfig(Random r, org.apache.lucene.util.Version v, org.apache.lucene.analysis.Analyzer a)
public static org.apache.lucene.index.LogMergePolicy newLogMergePolicy()
public static org.apache.lucene.index.TieredMergePolicy newTieredMergePolicy()
public static org.apache.lucene.index.LogMergePolicy newLogMergePolicy(Random r)
public static org.apache.lucene.index.TieredMergePolicy newTieredMergePolicy(Random r)
public static org.apache.lucene.index.LogMergePolicy newLogMergePolicy(boolean useCFS)
public static org.apache.lucene.index.LogMergePolicy newLogMergePolicy(boolean useCFS, int mergeFactor)
public static org.apache.lucene.index.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(org.apache.lucene.store.Directory d) throws IOException
newDirectory()
for more
information.
IOException
public static MockDirectoryWrapper newFSDirectory(File f) throws IOException
IOException
public static MockDirectoryWrapper newFSDirectory(File f, org.apache.lucene.store.LockFactory lf) throws IOException
IOException
public static MockDirectoryWrapper newDirectory(Random r, org.apache.lucene.store.Directory d) throws IOException
newDirectory()
for more information.
IOException
public static org.apache.lucene.document.Field newField(String name, String value, org.apache.lucene.document.Field.Index index)
newField(String, String, Field.Store, Field.Index, Field.TermVector)
for more information
public static org.apache.lucene.document.Field newField(String name, String value, org.apache.lucene.document.Field.Store store, org.apache.lucene.document.Field.Index index)
newField(String, String, Field.Store, Field.Index, Field.TermVector)
for more information
public static org.apache.lucene.document.Field newField(String name, String value, org.apache.lucene.document.Field.Store store, org.apache.lucene.document.Field.Index index, org.apache.lucene.document.Field.TermVector tv)
public static org.apache.lucene.document.Field newField(Random random, String name, String value, org.apache.lucene.document.Field.Index index)
newField(String, String, Field.Store, Field.Index, Field.TermVector)
for more information
public static org.apache.lucene.document.Field newField(Random random, String name, String value, org.apache.lucene.document.Field.Store store, org.apache.lucene.document.Field.Index index)
newField(String, String, Field.Store, Field.Index, Field.TermVector)
for more information
public static org.apache.lucene.document.Field newField(Random random, String name, String value, org.apache.lucene.document.Field.Store store, org.apache.lucene.document.Field.Index index, org.apache.lucene.document.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 void registerTempFile(File tmpFile)
public static org.apache.lucene.search.IndexSearcher newSearcher(org.apache.lucene.index.IndexReader r) throws IOException
IOException
public static org.apache.lucene.search.IndexSearcher newSearcher(org.apache.lucene.index.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 void reportAdditionalFailureInfo()
public final void alwaysIgnoredTestMethod()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |