public final class TestUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.util.Comparator<java.lang.CharSequence> |
STRING_CODEPOINT_COMPARATOR
A comparator that compares UTF-16 strings / char sequences according to Unicode
code point order.
|
Modifier and Type | Method and Description |
---|---|
static void |
addIndexesSlowly(IndexWriter writer,
DirectoryReader... readers) |
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,
java.util.Map<java.lang.String,T> reflectedValues)
Checks some basic behaviour of an AttributeImpl
|
static void |
assertEquals(TopDocs expected,
TopDocs actual) |
static java.lang.String |
bytesRefToString(BytesRef br)
For debugging: tries to include br.utf8ToString(), but if that
fails (because it's not valid utf8, which is fine!), just
use ordinary toString.
|
static java.lang.CharSequence |
bytesToCharSequence(BytesRef ref,
java.util.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 CheckIndex.Status |
checkIndex(Directory dir,
boolean crossCheckTermVectors,
boolean failFast,
java.io.ByteArrayOutputStream output)
If failFast is true, then throw the first exception when index corruption is hit, instead of moving on to other fields/segments to
look for any other corruption.
|
static <T> void |
checkIterator(java.util.Iterator<T> iterator)
Checks that the provided iterator is well-formed.
|
static <T> void |
checkIterator(java.util.Iterator<T> iterator,
long expectedSize,
boolean allowNull)
Checks that the provided iterator is well-formed.
|
static void |
checkReader(IndexReader reader)
This runs the CheckIndex tool on the Reader.
|
static void |
checkReader(LeafReader reader,
boolean crossCheckTermVectors) |
static <T> void |
checkReadOnly(java.util.Collection<T> coll)
Checks that the provided collection is read-only.
|
static Document |
cloneDocument(Document doc1) |
static boolean |
disableVirusChecker(Directory in)
Returns true if VirusCheckingFS is in use and was in fact already enabled
|
static PostingsEnum |
docs(java.util.Random random,
IndexReader r,
java.lang.String field,
BytesRef term,
PostingsEnum reuse,
int flags) |
static PostingsEnum |
docs(java.util.Random random,
TermsEnum termsEnum,
PostingsEnum reuse,
int flags) |
static void |
enableVirusChecker(Directory in) |
static boolean |
fieldSupportsHugeBinaryDocValues(java.lang.String field) |
static Codec |
getDefaultCodec()
Returns the actual default codec (e.g.
|
static DocValuesFormat |
getDefaultDocValuesFormat()
Returns the actual default docvalues format (e.g.
|
static PostingsFormat |
getDefaultPostingsFormat()
Returns the actual default postings format (e.g.
|
static PostingsFormat |
getDefaultPostingsFormat(int minItemsPerBlock,
int maxItemsPerBlock)
Returns the actual default postings format (e.g.
|
static java.lang.String |
getDocValuesFormat(Codec codec,
java.lang.String field) |
static java.lang.String |
getDocValuesFormat(java.lang.String field) |
static java.lang.String |
getPostingsFormat(Codec codec,
java.lang.String field) |
static java.lang.String |
getPostingsFormat(java.lang.String field) |
static PostingsFormat |
getPostingsFormatWithOrds(java.util.Random r)
Returns a random postings format that supports term ordinals
|
static boolean |
hasVirusChecker(Directory dir) |
static boolean |
hasVirusChecker(java.nio.file.Path path) |
static boolean |
hasWindowsFS(Directory dir) |
static boolean |
hasWindowsFS(java.nio.file.Path path) |
static java.math.BigInteger |
nextBigInteger(java.util.Random random,
int maxBytes)
Returns a randomish big integer with {@code 1 ..
|
static int |
nextInt(java.util.Random r,
int start,
int end)
start and end are BOTH inclusive
|
static long |
nextLong(java.util.Random r,
long start,
long end)
start and end are BOTH inclusive
|
static RAMDirectory |
ramCopyOf(Directory dir)
Returns a copy of directory, entirely in RAM
|
static java.lang.String |
randomAnalysisString(java.util.Random random,
int maxLength,
boolean simple) |
static BytesRef |
randomBinaryTerm(java.util.Random r)
Returns a random binary term.
|
static java.lang.String |
randomFixedByteLengthUnicodeString(java.util.Random r,
int length)
Returns random string, with a given UTF-8 byte length
|
static void |
randomFixedLengthUnicodeString(java.util.Random random,
char[] chars,
int offset,
int length)
Fills provided char[] with valid random unicode code
unit sequence.
|
static java.lang.String |
randomHtmlishString(java.util.Random random,
int numElements) |
static java.lang.String |
randomlyRecaseCodePoints(java.util.Random random,
java.lang.String str)
Randomly upcases, downcases, or leaves intact each code point in the given string
|
static java.util.regex.Pattern |
randomPattern(java.util.Random random)
Returns a valid (compiling) Pattern instance with random stuff inside.
|
static java.lang.String |
randomRealisticUnicodeString(java.util.Random r)
Returns random string of length between 0-20 codepoints, all codepoints within the same unicode block.
|
static java.lang.String |
randomRealisticUnicodeString(java.util.Random r,
int maxLength)
Returns random string of length up to maxLength codepoints , all codepoints within the same unicode block.
|
static java.lang.String |
randomRealisticUnicodeString(java.util.Random r,
int minLength,
int maxLength)
Returns random string of length between min and max codepoints, all codepoints within the same unicode block.
|
static java.lang.String |
randomRegexpishString(java.util.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 java.lang.String |
randomRegexpishString(java.util.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 java.lang.String |
randomSimpleString(java.util.Random r) |
static java.lang.String |
randomSimpleString(java.util.Random r,
int maxLength) |
static java.lang.String |
randomSimpleString(java.util.Random r,
int minLength,
int maxLength) |
static java.lang.String |
randomSimpleStringRange(java.util.Random r,
char minChar,
char maxChar,
int maxLength) |
static java.lang.String |
randomSubString(java.util.Random random,
int wordLength,
boolean simple) |
static java.lang.String |
randomUnicodeString(java.util.Random r)
Returns random string, including full unicode range.
|
static java.lang.String |
randomUnicodeString(java.util.Random r,
int maxLength)
Returns a random string up to a certain length.
|
static void |
reduceOpenFiles(IndexWriter w)
just tries to configure things to keep the open file
count lowish
|
static void |
shutdownExecutorService(java.util.concurrent.ExecutorService ex)
Shutdown
ExecutorService and wait for its. |
static java.lang.CharSequence |
stringToCharSequence(java.lang.String string,
java.util.Random random) |
static void |
syncConcurrentMerges(IndexWriter writer) |
static void |
syncConcurrentMerges(MergeScheduler ms) |
static void |
unzip(java.io.InputStream in,
java.nio.file.Path destDir)
Convenience method unzipping zipName into destDir.
|
public static final java.util.Comparator<java.lang.CharSequence> STRING_CODEPOINT_COMPARATOR
BytesRef
order.
Warning: This comparator is rather inefficient, because
it converts the strings to a int[]
array on each invocation.
public static void unzip(java.io.InputStream in, java.nio.file.Path destDir) throws java.io.IOException
java.io.IOException
public static <T> void checkIterator(java.util.Iterator<T> iterator, long expectedSize, boolean allowNull)
remove
expectedSize
number of elements
allowNull
is true.
next
is called
after hasNext
returns false.
public static <T> void checkIterator(java.util.Iterator<T> iterator)
remove
next
is called
after hasNext
returns false.
public static <T> void checkReadOnly(java.util.Collection<T> coll)
checkIterator(Iterator)
public static void syncConcurrentMerges(IndexWriter writer)
public static void syncConcurrentMerges(MergeScheduler ms)
public static CheckIndex.Status checkIndex(Directory dir) throws java.io.IOException
java.io.IOException
public static CheckIndex.Status checkIndex(Directory dir, boolean crossCheckTermVectors) throws java.io.IOException
java.io.IOException
public static CheckIndex.Status checkIndex(Directory dir, boolean crossCheckTermVectors, boolean failFast, java.io.ByteArrayOutputStream output) throws java.io.IOException
java.io.IOException
public static void checkReader(IndexReader reader) throws java.io.IOException
java.io.IOException
public static void checkReader(LeafReader reader, boolean crossCheckTermVectors) throws java.io.IOException
java.io.IOException
public static int nextInt(java.util.Random r, int start, int end)
public static long nextLong(java.util.Random r, long start, long end)
public static java.math.BigInteger nextBigInteger(java.util.Random random, int maxBytes)
1 .. maxBytes
storage.public static java.lang.String randomSimpleString(java.util.Random r, int maxLength)
public static java.lang.String randomSimpleString(java.util.Random r, int minLength, int maxLength)
public static java.lang.String randomSimpleStringRange(java.util.Random r, char minChar, char maxChar, int maxLength)
public static java.lang.String randomSimpleString(java.util.Random r)
public static java.lang.String randomUnicodeString(java.util.Random r)
public static java.lang.String randomUnicodeString(java.util.Random r, int maxLength)
public static void randomFixedLengthUnicodeString(java.util.Random random, char[] chars, int offset, int length)
public static java.lang.String randomRegexpishString(java.util.Random r)
public static java.lang.String randomRegexpishString(java.util.Random r, int maxLength)
Note: to avoid practically endless backtracking patterns we replace asterisk and plus operators with bounded repetitions. See LUCENE-4111 for more info.
maxLength
- A hint about maximum length of the regexpish string. It may be exceeded by a few characters.public static java.lang.String randomHtmlishString(java.util.Random random, int numElements)
public static java.lang.String randomlyRecaseCodePoints(java.util.Random random, java.lang.String str)
public static java.lang.String randomRealisticUnicodeString(java.util.Random r)
public static java.lang.String randomRealisticUnicodeString(java.util.Random r, int maxLength)
public static java.lang.String randomRealisticUnicodeString(java.util.Random r, int minLength, int maxLength)
public static java.lang.String randomFixedByteLengthUnicodeString(java.util.Random r, int length)
public static BytesRef randomBinaryTerm(java.util.Random r)
public static Codec alwaysPostingsFormat(PostingsFormat format)
public static Codec alwaysDocValuesFormat(DocValuesFormat format)
public static Codec getDefaultCodec()
Codec.getDefault()
because that is randomized.public static PostingsFormat getDefaultPostingsFormat()
public static PostingsFormat getDefaultPostingsFormat(int minItemsPerBlock, int maxItemsPerBlock)
public static PostingsFormat getPostingsFormatWithOrds(java.util.Random r)
public static DocValuesFormat getDefaultDocValuesFormat()
public static java.lang.String getPostingsFormat(java.lang.String field)
public static java.lang.String getPostingsFormat(Codec codec, java.lang.String field)
public static java.lang.String getDocValuesFormat(java.lang.String field)
public static java.lang.String getDocValuesFormat(Codec codec, java.lang.String field)
public static boolean fieldSupportsHugeBinaryDocValues(java.lang.String field)
public static boolean anyFilesExceptWriteLock(Directory dir) throws java.io.IOException
java.io.IOException
public static void addIndexesSlowly(IndexWriter writer, DirectoryReader... readers) throws java.io.IOException
java.io.IOException
public static void reduceOpenFiles(IndexWriter w)
public static <T> void assertAttributeReflection(AttributeImpl att, java.util.Map<java.lang.String,T> reflectedValues)
reflectedValues
- contains a map with "AttributeClass#key" as valuespublic static PostingsEnum docs(java.util.Random random, IndexReader r, java.lang.String field, BytesRef term, PostingsEnum reuse, int flags) throws java.io.IOException
java.io.IOException
public static PostingsEnum docs(java.util.Random random, TermsEnum termsEnum, PostingsEnum reuse, int flags) throws java.io.IOException
java.io.IOException
public static java.lang.CharSequence stringToCharSequence(java.lang.String string, java.util.Random random)
public static java.lang.CharSequence bytesToCharSequence(BytesRef ref, java.util.Random random)
public static void shutdownExecutorService(java.util.concurrent.ExecutorService ex)
ExecutorService
and wait for its.public static java.util.regex.Pattern randomPattern(java.util.Random random)
public static java.lang.String randomAnalysisString(java.util.Random random, int maxLength, boolean simple)
public static java.lang.String randomSubString(java.util.Random random, int wordLength, boolean simple)
public static java.lang.String bytesRefToString(BytesRef br)
public static RAMDirectory ramCopyOf(Directory dir) throws java.io.IOException
java.io.IOException
public static boolean hasWindowsFS(Directory dir)
public static boolean hasWindowsFS(java.nio.file.Path path)
public static boolean hasVirusChecker(Directory dir)
public static boolean hasVirusChecker(java.nio.file.Path path)
public static boolean disableVirusChecker(Directory in)
public static void enableVirusChecker(Directory in)
Copyright © 2000–2019 The Apache Software Foundation. All rights reserved.