## org.apache.lucene.util
Class _TestUtil

    java.lang.Object
      org.apache.lucene.util._TestUtil

    public class _TestUtil

extends Object

General utility methods for Lucene unit tests.

Field Summary
`static char[]` `WHITESPACE_CHARACTERS` List of characters that match `Character.isWhitespace(char)`

Constructor Summary
`_TestUtil()`

Method Summary
`static Codec` `alwaysDocValuesFormat(DocValuesFormat format)` Return a Codec that can read any of the default codecs and formats, but always writes in the specified format.
`static Codec` `alwaysPostingsFormat(PostingsFormat format)` Return a Codec that can read any of the default codecs and formats, but always writes in the specified format.
`static boolean` `anyFilesExceptWriteLock(Directory dir)`

`static

`<T> void`

`

`assertAttributeReflection(AttributeImpl att, Map<String,T> reflectedValues)`
Checks some basic behaviour of an AttributeImpl

`static void` `assertEquals(TopDocs expected, TopDocs actual)`
`static CharSequence` `bytesToCharSequence(BytesRef ref, Random random)`
`static CheckIndex.Status` `checkIndex(Directory dir)` This runs the CheckIndex tool on the index in.
`static CheckIndex.Status` `checkIndex(Directory dir, boolean crossCheckTermVectors)`
`static void` `checkReader(AtomicReader reader, boolean crossCheckTermVectors)`
`static void` `checkReader(IndexReader reader)` This runs the CheckIndex tool on the Reader.
`static Document` `cloneDocument(Document doc1)`
`static File` `createTempFile(String prefix, String suffix, File directory)` insecure, fast version of File.createTempFile uses Random instead of SecureRandom.
`static DocsEnum` `docs(Random random, IndexReader r, String field, BytesRef term, Bits liveDocs, DocsEnum reuse, int flags)`
`static DocsEnum` `docs(Random random, TermsEnum termsEnum, Bits liveDocs, DocsEnum reuse, int flags)`
`static FieldInfos` `getFieldInfos(SegmentInfo info)`
`static String` `getPostingsFormat(Codec codec, String field)`
`static String` `getPostingsFormat(String field)`
`static File` `getTempDir(String desc)` Returns a temp directory, based on the given description.
`static void` `keepFullyDeletedSegments(IndexWriter w)`
`static int` `nextInt(Random r, int start, int end)` start and end are BOTH inclusive
`static long` `nextLong(Random r, long start, long end)` start and end are BOTH inclusive
`static FilteredQuery.FilterStrategy` `randomFilterStrategy(Random random)`
`static String` `randomFixedByteLengthUnicodeString(Random r, int length)` Returns random string, with a given UTF-8 byte length
`static void` `randomFixedLengthUnicodeString(Random random, char[] chars, int offset, int length)` Fills provided char[] with valid random unicode code unit sequence.
`static String` `randomHtmlishString(Random random, int numElements)`
`static String` `randomlyRecaseCodePoints(Random random, String str)` Randomly upcases, downcases, or leaves intact each code point in the given string
`static Pattern` `randomPattern(Random random)` Returns a valid (compiling) Pattern instance with random stuff inside.
`static String` `randomRealisticUnicodeString(Random r)` Returns random string of length between 0-20 codepoints, all codepoints within the same unicode block.
`static String` `randomRealisticUnicodeString(Random r, int maxLength)` Returns random string of length up to maxLength codepoints , all codepoints within the same unicode block.
`static String` `randomRealisticUnicodeString(Random r, int minLength, int maxLength)` Returns random string of length between min and max codepoints, all codepoints within the same unicode block.
`static String` `randomRegexpishString(Random r)` Returns a String thats "regexpish" (contains lots of operators typically found in regular expressions) If you call this enough times, you might get a valid regex!
`static String` `randomRegexpishString(Random r, int maxLength)` Returns a String thats "regexpish" (contains lots of operators typically found in regular expressions) If you call this enough times, you might get a valid regex!
`static String` `randomSimpleString(Random r)`
`static String` `randomSimpleString(Random r, int maxLength)`
`static String` `randomSimpleStringRange(Random r, char minChar, char maxChar, int maxLength)`
`static String` `randomUnicodeString(Random r)` Returns random string, including full unicode range.
`static String` `randomUnicodeString(Random r, int maxLength)` Returns a random string up to a certain length.
`static String` `randomWhitespace(Random r, int minLength, int maxLength)` Returns a random string in the specified length range consisting entirely of whitespace characters
`static void` `reduceOpenFiles(IndexWriter w)` just tries to configure things to keep the open file count lowish
`static void` `rmDir(File dir)` Deletes a directory and everything underneath it.
`static void` `shutdownExecutorService(ExecutorService ex)` Shutdown `ExecutorService` and wait for its.
`static CharSequence` `stringToCharSequence(String string, Random random)`
`static void` `syncConcurrentMerges(IndexWriter writer)`
`static void` `syncConcurrentMerges(MergeScheduler ms)`
`static void` `unzip(File zipName, File destDir)` Convenience method: Unzip zipName + ".zip" under destDir, removing destDir first

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### WHITESPACE_CHARACTERS

    public static final char[] WHITESPACE_CHARACTERS

  List of characters that match `Character.isWhitespace(char)`

Constructor Detail

### _TestUtil

    public _TestUtil()

Method Detail

### getTempDir

    public static File getTempDir(String desc)

  Returns a temp directory, based on the given description. Creates the directory.

### rmDir

    public static void rmDir(File dir)
                      throws IOException

  Deletes a directory and everything underneath it.

  Throws:
    `IOException`

### unzip

    public static void unzip(File zipName,
                             File destDir)
                      throws IOException

  Convenience method: Unzip zipName + ".zip" under destDir, removing destDir first

  Throws:
    `IOException`

### syncConcurrentMerges

    public static void syncConcurrentMerges(IndexWriter writer)

### syncConcurrentMerges

    public static void syncConcurrentMerges(MergeScheduler ms)

### checkIndex

    public static CheckIndex.Status checkIndex(Directory dir)
                                        throws IOException

  This runs the CheckIndex tool on the index in. If any issues are hit, a RuntimeException is thrown; else, true is returned.

  Throws:
    `IOException`

### checkIndex

    public static CheckIndex.Status checkIndex(Directory dir,
                                               boolean crossCheckTermVectors)
                                        throws IOException

  Throws:
    `IOException`

### checkReader

    public static void checkReader(IndexReader reader)
                            throws IOException

  This runs the CheckIndex tool on the Reader. If any issues are hit, a RuntimeException is thrown

  Throws:
    `IOException`

### checkReader

    public static void checkReader(AtomicReader reader,
                                   boolean crossCheckTermVectors)
                            throws IOException

  Throws:
    `IOException`

### nextInt

    public static int nextInt(Random r,
                              int start,
                              int end)

  start and end are BOTH inclusive

### nextLong

    public static long nextLong(Random r,
                                long start,
                                long end)

  start and end are BOTH inclusive

### randomSimpleString

    public static String randomSimpleString(Random r,
                                            int maxLength)

### randomSimpleStringRange

    public static String randomSimpleStringRange(Random r,
                                                 char minChar,
                                                 char maxChar,
                                                 int maxLength)

### randomSimpleString

    public static String randomSimpleString(Random r)

### randomUnicodeString

    public static String randomUnicodeString(Random r)

  Returns random string, including full unicode range.

### randomUnicodeString

    public static String randomUnicodeString(Random r,
                                             int maxLength)

  Returns a random string up to a certain length.

### randomFixedLengthUnicodeString

    public static void randomFixedLengthUnicodeString(Random random,
                                                      char[] chars,
                                                      int offset,
                                                      int length)

  Fills provided char[] with valid random unicode code unit sequence.

### randomRegexpishString

    public static String randomRegexpishString(Random r)

  Returns a String thats "regexpish" (contains lots of operators typically found in regular expressions) If you call this enough times, you might get a valid regex!

### randomRegexpishString

    public static String randomRegexpishString(Random r,
                                               int maxLength)

  Returns a String thats "regexpish" (contains lots of operators typically found in regular expressions) If you call this enough times, you might get a valid regex!

  Note: to avoid practically endless backtracking patterns we replace asterisk and plus operators with bounded repetitions. See LUCENE-4111 for more info.

  Parameters:
    `maxLength` - A hint about maximum length of the regexpish string. It may be exceeded by a few characters.

### randomHtmlishString

    public static String randomHtmlishString(Random random,
                                             int numElements)

### randomlyRecaseCodePoints

    public static String randomlyRecaseCodePoints(Random random,
                                                  String str)

  Randomly upcases, downcases, or leaves intact each code point in the given string

### randomRealisticUnicodeString

    public static String randomRealisticUnicodeString(Random r)

  Returns random string of length between 0-20 codepoints, all codepoints within the same unicode block.

### randomRealisticUnicodeString

    public static String randomRealisticUnicodeString(Random r,
                                                      int maxLength)

  Returns random string of length up to maxLength codepoints , all codepoints within the same unicode block.

### randomRealisticUnicodeString

    public static String randomRealisticUnicodeString(Random r,
                                                      int minLength,
                                                      int maxLength)

  Returns random string of length between min and max codepoints, all codepoints within the same unicode block.

### randomFixedByteLengthUnicodeString

    public static String randomFixedByteLengthUnicodeString(Random r,
                                                            int length)

  Returns random string, with a given UTF-8 byte length

### alwaysPostingsFormat

    public static Codec alwaysPostingsFormat(PostingsFormat format)

  Return a Codec that can read any of the default codecs and formats, but always writes in the specified format.

### alwaysDocValuesFormat

    public static Codec alwaysDocValuesFormat(DocValuesFormat format)

  Return a Codec that can read any of the default codecs and formats, but always writes in the specified format.

### getPostingsFormat

    public static String getPostingsFormat(String field)

### getPostingsFormat

    public static String getPostingsFormat(Codec codec,
                                           String field)

### anyFilesExceptWriteLock

    public static boolean anyFilesExceptWriteLock(Directory dir)
                                           throws IOException

  Throws:
    `IOException`

### reduceOpenFiles

    public static void reduceOpenFiles(IndexWriter w)

  just tries to configure things to keep the open file count lowish

### assertAttributeReflection

    public static <T> void assertAttributeReflection(AttributeImpl att,
                                                     Map<String,T> reflectedValues)

  Checks some basic behaviour of an AttributeImpl

  Parameters:
    `reflectedValues` - contains a map with "AttributeClass#key" as values

### keepFullyDeletedSegments

    public static void keepFullyDeletedSegments(IndexWriter w)

### createTempFile

    public static File createTempFile(String prefix,
                                      String suffix,
                                      File directory)
                               throws IOException

  insecure, fast version of File.createTempFile uses Random instead of SecureRandom.

  Throws:
    `IOException`

### assertEquals

    public static void assertEquals(TopDocs expected,
                                    TopDocs actual)

### cloneDocument

    public static Document cloneDocument(Document doc1)

### docs

    public static DocsEnum docs(Random random,
                                IndexReader r,
                                String field,
                                BytesRef term,
                                Bits liveDocs,
                                DocsEnum reuse,
                                int flags)
                         throws IOException

  Throws:
    `IOException`

### docs

    public static DocsEnum docs(Random random,
                                TermsEnum termsEnum,
                                Bits liveDocs,
                                DocsEnum reuse,
                                int flags)
                         throws IOException

  Throws:
    `IOException`

### stringToCharSequence

    public static CharSequence stringToCharSequence(String string,
                                                    Random random)

### bytesToCharSequence

    public static CharSequence bytesToCharSequence(BytesRef ref,
                                                   Random random)

### shutdownExecutorService

    public static void shutdownExecutorService(ExecutorService ex)

  Shutdown `ExecutorService` and wait for its.

### getFieldInfos

    public static FieldInfos getFieldInfos(SegmentInfo info)
                                    throws IOException

  Throws:
    `IOException`

### randomPattern

    public static Pattern randomPattern(Random random)

  Returns a valid (compiling) Pattern instance with random stuff inside. Be careful when applying random patterns to longer strings as certain types of patterns may explode into exponential times in backtracking implementations (such as Java's).

### randomFilterStrategy

    public static final FilteredQuery.FilterStrategy randomFilterStrategy(Random random)

### randomWhitespace

    public static String randomWhitespace(Random r,
                                          int minLength,
                                          int maxLength)

  Returns a random string in the specified length range consisting entirely of whitespace characters

  See Also:
    `WHITESPACE_CHARACTERS`

Copyright © 2000-2013 Apache Software Foundation. All Rights Reserved.