Class LuceneTestCase

    • Field Detail

      • VERBOSE

        public static final boolean VERBOSE
        true iff tests are run in verbose mode. Note: if it is false, tests are not expected to print any messages.
      • TEST_VERSION_CURRENT

        public static final org.apache.lucene.util.Version TEST_VERSION_CURRENT
        Use this constant when creating Analyzers and any other version-dependent stuff.

        NOTE: Change this when development starts for new Lucene version:

      • TEMP_DIR

        public static final File TEMP_DIR
        Create indexes in this directory, optimally use a subdir, named after the test
      • TEST_LOCALE

        public static final String TEST_LOCALE
        Gets the locale to run tests with
      • TEST_TIMEZONE

        public static final String TEST_TIMEZONE
        Gets the timezone to run tests with
      • TEST_DIRECTORY

        public static final String TEST_DIRECTORY
        Gets the directory to run tests with
      • TEST_ITER

        public static final int TEST_ITER
        Get the number of times to run tests
      • TEST_ITER_MIN

        public static final int TEST_ITER_MIN
        Get the minimum number of times to run tests until a failure happens
      • TEST_SEED

        public static final String TEST_SEED
        Get the random seed for tests
      • TEST_NIGHTLY

        public static final boolean TEST_NIGHTLY
        whether or not nightly tests should run
      • TEST_LINE_DOCS_FILE

        public static final String TEST_LINE_DOCS_FILE
        the line file used by LineFileDocs
      • TEST_CLEAN_THREADS

        public static final String TEST_CLEAN_THREADS
        whether or not to clean threads between test invocations: "false", "perMethod", "perClass"
      • RANDOM_MULTIPLIER

        public static final int RANDOM_MULTIPLIER
        A random multiplier which you should use when writing random tests: multiply it by the number of iterations
      • classRules

        public static org.junit.rules.TestRule classRules
        This controls how suite-level rules are nested. It is important that _all_ rules declared in LuceneTestCase are executed in proper order if they depend on each other.
      • ruleChain

        public final org.junit.rules.TestRule ruleChain
        This controls how individual test rules are nested. It is important that _all_ rules declared in LuceneTestCase are executed in proper order if they depend on each other.
      • testsFailed

        protected static boolean testsFailed
    • Constructor Detail

      • LuceneTestCase

        public LuceneTestCase()
    • Method Detail

      • beforeClassLuceneTestCaseJ4

        public static void beforeClassLuceneTestCaseJ4()
      • afterClassLuceneTestCaseJ4

        public static void afterClassLuceneTestCaseJ4()
      • purgeFieldCache

        protected void purgeFieldCache​(org.apache.lucene.search.FieldCache fc)
        Forcible purges all cache entries from the FieldCache.

        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.

        See Also:
        FieldCache.purgeAllCaches()
      • getTestLabel

        protected String getTestLabel()
      • setUseCompoundFile

        public static void setUseCompoundFile​(org.apache.lucene.index.MergePolicy mp,
                                              boolean useCompound)
      • setMergeFactor

        public static void setMergeFactor​(org.apache.lucene.index.MergePolicy mp,
                                          int mergeFactor)
      • isTestThread

        protected boolean isTestThread()
        Returns true if and only if the calling thread is the primary thread executing the test case.
      • setUp

        public void setUp()
                   throws Exception
        For subclassing only. Overrides must call super.setUp().
        Throws:
        Exception
      • tearDown

        public void tearDown()
                      throws Exception
        For subclassing only. Overrides must call super.tearDown().
        Throws:
        Exception
      • assertSaneFieldCaches

        protected void assertSaneFieldCaches​(String msg)
        Asserts that FieldCacheSanityChecker does not detect any problems with FieldCache.DEFAULT.

        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.

        See Also:
        FieldCacheSanityChecker
      • atLeast

        public static int atLeast​(Random random,
                                  int i)
        Returns a number of at least i

        The actual number returned will be influenced by whether TEST_NIGHTLY is active and RANDOM_MULTIPLIER, but also with some random fudge.

      • atLeast

        public static int atLeast​(int i)
      • rarely

        public static boolean rarely​(Random random)
        Returns true if something should happen rarely,

        The actual number returned will be influenced by whether TEST_NIGHTLY is active and RANDOM_MULTIPLIER.

      • rarely

        public static boolean rarely()
      • usually

        public static boolean usually​(Random random)
      • usually

        public static boolean usually()
      • assertEquals

        @Deprecated
        public static void assertEquals​(double expected,
                                        double actual)
        Deprecated.
      • assertEquals

        @Deprecated
        public static void assertEquals​(String message,
                                        double expected,
                                        double actual)
        Deprecated.
      • assertEquals

        @Deprecated
        public static void assertEquals​(float expected,
                                        float actual)
        Deprecated.
      • assertEquals

        @Deprecated
        public static void assertEquals​(String message,
                                        float expected,
                                        float actual)
        Deprecated.
      • assumeTrue

        public static void assumeTrue​(String msg,
                                      boolean b)
      • assumeFalse

        public static void assumeFalse​(String msg,
                                       boolean b)
      • assumeNoException

        public static void assumeNoException​(String msg,
                                             Exception e)
      • asSet

        public static <T> Set<T> asSet​(T... args)
      • dumpIterator

        public static void dumpIterator​(String label,
                                        Iterator<?> iter,
                                        PrintStream stream)
        Convenience method for logging an iterator.
        Parameters:
        label - String logged before/after the items in the iterator
        iter - 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.
      • newIndexWriterConfig

        public 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
      • newIndexWriterConfig

        public 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
      • newLogMergePolicy

        public static org.apache.lucene.index.LogMergePolicy newLogMergePolicy()
      • newTieredMergePolicy

        public static org.apache.lucene.index.TieredMergePolicy newTieredMergePolicy()
      • newLogMergePolicy

        public static org.apache.lucene.index.LogMergePolicy newLogMergePolicy​(Random r)
      • newTieredMergePolicy

        public static org.apache.lucene.index.TieredMergePolicy newTieredMergePolicy​(Random r)
      • newLogMergePolicy

        public static org.apache.lucene.index.LogMergePolicy newLogMergePolicy​(boolean useCFS)
      • newLogMergePolicy

        public static org.apache.lucene.index.LogMergePolicy newLogMergePolicy​(boolean useCFS,
                                                                               int mergeFactor)
      • newLogMergePolicy

        public static org.apache.lucene.index.LogMergePolicy newLogMergePolicy​(int mergeFactor)
      • newDirectory

        public static MockDirectoryWrapper newDirectory()
                                                 throws IOException
        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 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.

        Throws:
        IOException
      • newFSDirectory

        public static MockDirectoryWrapper newFSDirectory​(File f,
                                                          org.apache.lucene.store.LockFactory lf)
                                                   throws IOException
        Returns a new FSDirectory instance over the given file, which must be a folder.
        Throws:
        IOException
      • newField

        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)
        Returns a new Field instance. Use this when the test does not care about some specific field settings (most tests)
        • If the store value is set to Store.NO, sometimes the field will be randomly stored.
        • More term vector data than you ask for might be indexed, for example if you choose YES it might index term vectors with offsets too.
      • randomLocale

        public static Locale randomLocale​(Random random)
        return a random Locale from the available locales on the system
      • randomTimeZone

        public static TimeZone randomTimeZone​(Random random)
        return a random TimeZone from the available timezones on the system
      • localeForName

        public static Locale localeForName​(String localeName)
        return a Locale object equivalent to its programmatic name
      • randomDirectory

        public static String randomDirectory​(Random random)
      • newSearcher

        public static org.apache.lucene.search.IndexSearcher newSearcher​(org.apache.lucene.index.IndexReader r)
                                                                  throws IOException
        create a new searcher over the reader. This searcher might randomly use threads.
        Throws:
        IOException
      • newSearcher

        public static org.apache.lucene.search.IndexSearcher newSearcher​(org.apache.lucene.index.IndexReader r,
                                                                         boolean maybeWrap)
                                                                  throws IOException
        create a new searcher over the reader. This searcher might randomly use threads. if maybeWrap is true, this searcher might wrap the reader with one that returns null for getSequentialSubReaders.
        Throws:
        IOException
      • getName

        public String getName()
      • reportPartialFailureInfo

        public static void reportPartialFailureInfo()
      • reportAdditionalFailureInfo

        public void reportAdditionalFailureInfo()
      • getTestClass

        public static Class<?> getTestClass()
        Return the current class being tested.
      • alwaysIgnoredTestMethod

        public final void alwaysIgnoredTestMethod()