Fork me on GitHub
  • API

    Show / Hide Table of Contents

    Class TestUtil

    General utility methods for Lucene unit tests.

    Inheritance
    object
    TestUtil
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Lucene.Net.Util
    Assembly: Lucene.Net.TestFramework.dll
    Syntax
    public static class TestUtil

    Fields

    WHITESPACE_CHARACTERS

    List of characters that match IsWhiteSpace(char).

    Declaration
    public static readonly char[] WHITESPACE_CHARACTERS
    Field Value
    Type Description
    char[]

    Methods

    AlwaysDocValuesFormat(DocValuesFormat)

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

    Declaration
    public static Codec AlwaysDocValuesFormat(DocValuesFormat format)
    Parameters
    Type Name Description
    DocValuesFormat format
    Returns
    Type Description
    Codec

    AlwaysPostingsFormat(PostingsFormat)

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

    Declaration
    public static Codec AlwaysPostingsFormat(PostingsFormat format)
    Parameters
    Type Name Description
    PostingsFormat format
    Returns
    Type Description
    Codec

    AnyFilesExceptWriteLock(Directory)

    General utility methods for Lucene unit tests.

    Declaration
    public static bool AnyFilesExceptWriteLock(Directory dir)
    Parameters
    Type Name Description
    Directory dir
    Returns
    Type Description
    bool

    AssertAttributeReflection(Attribute, IDictionary<string, object>)

    Checks some basic behaviour of an Lucene.Net.Util.Attribute.

    Declaration
    public static void AssertAttributeReflection(Attribute att, IDictionary<string, object> reflectedValues)
    Parameters
    Type Name Description
    Attribute att

    Lucene.Net.Util.Attribute to reflect

    IDictionary<string, object> reflectedValues

    Contains a IDictionary<TKey, TValue> with "AttributeSubclassType/key" as values.

    AssertEquals(TopDocs, TopDocs)

    General utility methods for Lucene unit tests.

    Declaration
    public static void AssertEquals(TopDocs expected, TopDocs actual)
    Parameters
    Type Name Description
    TopDocs expected
    TopDocs actual

    BytesToCharSequence(BytesRef, Random)

    General utility methods for Lucene unit tests.

    Declaration
    public static ICharSequence BytesToCharSequence(BytesRef @ref, Random random)
    Parameters
    Type Name Description
    BytesRef ref
    Random random
    Returns
    Type Description
    ICharSequence

    CheckIndex(Directory)

    This runs the Lucene.Net.Index.CheckIndex tool on the index in. If any issues are hit, an Exception is thrown; else, true is returned.

    Declaration
    public static CheckIndex.Status CheckIndex(Directory dir)
    Parameters
    Type Name Description
    Directory dir
    Returns
    Type Description
    CheckIndex.Status

    CheckIndex(Directory, bool)

    General utility methods for Lucene unit tests.

    Declaration
    public static CheckIndex.Status CheckIndex(Directory dir, bool crossCheckTermVectors)
    Parameters
    Type Name Description
    Directory dir
    bool crossCheckTermVectors
    Returns
    Type Description
    CheckIndex.Status

    CheckReader(AtomicReader, bool)

    General utility methods for Lucene unit tests.

    Declaration
    public static void CheckReader(AtomicReader reader, bool crossCheckTermVectors)
    Parameters
    Type Name Description
    AtomicReader reader
    bool crossCheckTermVectors

    CheckReader(IndexReader)

    This runs the Lucene.Net.Index.CheckIndex tool on the Lucene.Net.Index.IndexReader. If any issues are hit, an Exception is thrown.

    Declaration
    public static void CheckReader(IndexReader reader)
    Parameters
    Type Name Description
    IndexReader reader

    CloneDocument(Document)

    General utility methods for Lucene unit tests.

    Declaration
    public static Document CloneDocument(Document doc1)
    Parameters
    Type Name Description
    Document doc1
    Returns
    Type Description
    Document

    Docs(Random, IndexReader, string, BytesRef, IBits, DocsEnum, DocsFlags)

    Returns a Lucene.Net.Index.DocsEnum, but randomly sometimes uses a Lucene.Net.Index.MultiDocsEnum, Lucene.Net.Index.DocsAndPositionsEnum. Returns null if field/term doesn't exist.

    Declaration
    public static DocsEnum Docs(Random random, IndexReader r, string field, BytesRef term, IBits liveDocs, DocsEnum reuse, DocsFlags flags)
    Parameters
    Type Name Description
    Random random
    IndexReader r
    string field
    BytesRef term
    IBits liveDocs
    DocsEnum reuse
    DocsFlags flags
    Returns
    Type Description
    DocsEnum

    Docs(Random, TermsEnum, IBits, DocsEnum, DocsFlags)

    Returns a Lucene.Net.Index.DocsEnum from a positioned Lucene.Net.Index.TermsEnum, but randomly sometimes uses a Lucene.Net.Index.MultiDocsEnum, Lucene.Net.Index.DocsAndPositionsEnum.

    Declaration
    public static DocsEnum Docs(Random random, TermsEnum termsEnum, IBits liveDocs, DocsEnum reuse, DocsFlags flags)
    Parameters
    Type Name Description
    Random random
    TermsEnum termsEnum
    IBits liveDocs
    DocsEnum reuse
    DocsFlags flags
    Returns
    Type Description
    DocsEnum

    FieldSupportsHugeBinaryDocValues(string)

    General utility methods for Lucene unit tests.

    Declaration
    public static bool FieldSupportsHugeBinaryDocValues(string field)
    Parameters
    Type Name Description
    string field
    Returns
    Type Description
    bool

    GetDocValuesFormat(Codec, string)

    General utility methods for Lucene unit tests.

    Declaration
    public static string GetDocValuesFormat(Codec codec, string field)
    Parameters
    Type Name Description
    Codec codec
    string field
    Returns
    Type Description
    string

    GetDocValuesFormat(string)

    General utility methods for Lucene unit tests.

    Declaration
    public static string GetDocValuesFormat(string field)
    Parameters
    Type Name Description
    string field
    Returns
    Type Description
    string

    GetPostingsFormat(Codec, string)

    General utility methods for Lucene unit tests.

    Declaration
    public static string GetPostingsFormat(Codec codec, string field)
    Parameters
    Type Name Description
    Codec codec
    string field
    Returns
    Type Description
    string

    GetPostingsFormat(string)

    General utility methods for Lucene unit tests.

    Declaration
    public static string GetPostingsFormat(string field)
    Parameters
    Type Name Description
    string field
    Returns
    Type Description
    string

    NextInt32(Random, int, int)

    Returns a random int from minValue (inclusive) to maxValue (inclusive).

    Declaration
    public static int NextInt32(Random random, int minValue, int maxValue)
    Parameters
    Type Name Description
    Random random

    A Random instance.

    int minValue

    The inclusive start of the range.

    int maxValue

    The inclusive end of the range.

    Returns
    Type Description
    int

    A random int from minValue (inclusive) to maxValue (inclusive).

    Exceptions
    Type Condition
    ArgumentException

    minValue is greater than maxValue.

    ArgumentNullException

    random is null.

    NextInt64(Random, long, long)

    Returns a random long from minValue to maxValue (inclusive).

    Declaration
    public static long NextInt64(Random random, long minValue, long maxValue)
    Parameters
    Type Name Description
    Random random

    A Random instance.

    long minValue

    The inclusive start of the range.

    long maxValue

    The inclusive end of the range.

    Returns
    Type Description
    long

    A random long from minValue to maxValue (inclusive).

    Exceptions
    Type Condition
    ArgumentException

    minValue is greater than maxValue.

    ArgumentNullException

    random is null.

    RandomAnalysisString(Random, int, bool)

    General utility methods for Lucene unit tests.

    Declaration
    public static string RandomAnalysisString(Random random, int maxLength, bool simple)
    Parameters
    Type Name Description
    Random random
    int maxLength
    bool simple
    Returns
    Type Description
    string

    RandomFilterStrategy(Random)

    General utility methods for Lucene unit tests.

    Declaration
    public static FilteredQuery.FilterStrategy RandomFilterStrategy(Random random)
    Parameters
    Type Name Description
    Random random
    Returns
    Type Description
    FilteredQuery.FilterStrategy

    RandomFixedByteLengthUnicodeString(Random, int)

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

    Declaration
    public static string RandomFixedByteLengthUnicodeString(Random random, int length)
    Parameters
    Type Name Description
    Random random
    int length
    Returns
    Type Description
    string
    Exceptions
    Type Condition
    ArgumentOutOfRangeException

    length is less than 0.

    ArgumentNullException

    random is null.

    RandomFixedLengthUnicodeString(Random, char[], int, int)

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

    Declaration
    public static void RandomFixedLengthUnicodeString(Random random, char[] chars, int startIndex, int length)
    Parameters
    Type Name Description
    Random random

    This Random.

    char[] chars

    A char[] with preallocated space to put the characters.

    int startIndex

    The index of chars to begin populating with characters.

    int length

    The number of characters to populate.

    Exceptions
    Type Condition
    ArgumentOutOfRangeException

    startIndex or length is less than 0.

    -or-

    startIndex + length refers to a position outside of the range of chars.
    ArgumentNullException

    random or chars is null.

    RandomHtmlishString(Random, int)

    Returns a random HTML-like string.

    Declaration
    public static string RandomHtmlishString(Random random, int numElements)
    Parameters
    Type Name Description
    Random random

    This Random.

    int numElements

    The maximum number of HTML elements to include in the string.

    Returns
    Type Description
    string
    Exceptions
    Type Condition
    ArgumentOutOfRangeException

    numElements is less than 0.

    ArgumentNullException

    random is null.

    RandomRealisticUnicodeString(Random)

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

    Declaration
    public static string RandomRealisticUnicodeString(Random random)
    Parameters
    Type Name Description
    Random random

    This Random.

    Returns
    Type Description
    string
    Exceptions
    Type Condition
    ArgumentNullException

    random is null.

    RandomRealisticUnicodeString(Random, int)

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

    Declaration
    public static string RandomRealisticUnicodeString(Random random, int maxLength)
    Parameters
    Type Name Description
    Random random

    This Random.

    int maxLength

    The maximum length of the string to return (inclusive).

    Returns
    Type Description
    string
    Exceptions
    Type Condition
    ArgumentOutOfRangeException

    maxLength is less than 0.

    ArgumentNullException

    random is null.

    RandomRealisticUnicodeString(Random, int, int)

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

    Declaration
    public static string RandomRealisticUnicodeString(Random random, int minLength, int maxLength)
    Parameters
    Type Name Description
    Random random

    This Random.

    int minLength

    The minimum length of the string to return (inclusive).

    int maxLength

    The maximum length of the string to return (inclusive).

    Returns
    Type Description
    string
    Exceptions
    Type Condition
    ArgumentException

    minLength is greater than maxLength.

    ArgumentOutOfRangeException

    minLength or maxLength is less than 0.

    ArgumentNullException

    random is null.

    RandomRegex(Random)

    Returns a valid (compiling) Regex 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).

    Declaration
    public static Regex RandomRegex(Random random)
    Parameters
    Type Name Description
    Random random
    Returns
    Type Description
    Regex

    RandomRegexishString(Random)

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

    Declaration
    public static string RandomRegexishString(Random random)
    Parameters
    Type Name Description
    Random random

    This Random.

    Returns
    Type Description
    string
    Exceptions
    Type Condition
    ArgumentNullException

    random is null.

    RandomRegexpishString(Random, int)

    Returns a string thats "regexish" (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.
    Declaration
    public static string RandomRegexpishString(Random random, int maxLength)
    Parameters
    Type Name Description
    Random random

    This Random.

    int maxLength

    A hint about maximum length of the regexpish string. It may be exceeded by a few characters.

    Returns
    Type Description
    string
    Exceptions
    Type Condition
    ArgumentOutOfRangeException

    maxLength is less than 0.

    ArgumentNullException

    random is null.

    RandomSimpleString(Random)

    Returns a random string consisting only of lowercase characters 'a' through 'z', between 0 and 10 characters in length.

    Declaration
    public static string RandomSimpleString(Random random)
    Parameters
    Type Name Description
    Random random

    This Random.

    Returns
    Type Description
    string
    Exceptions
    Type Condition
    ArgumentNullException

    random is null.

    RandomSimpleString(Random, int)

    Returns a random string consisting only of lowercase characters 'a' through 'z'. May be an empty string.

    Declaration
    public static string RandomSimpleString(Random random, int maxLength)
    Parameters
    Type Name Description
    Random random

    This Random.

    int maxLength

    The maximum length of the string to return (inclusive).

    Returns
    Type Description
    string
    Exceptions
    Type Condition
    ArgumentOutOfRangeException

    maxLength is less than 0.

    ArgumentNullException

    random is null.

    RandomSimpleString(Random, int, int)

    Returns a random string consisting only of lowercase characters 'a' through 'z'. May be an empty string.

    Declaration
    public static string RandomSimpleString(Random random, int minLength, int maxLength)
    Parameters
    Type Name Description
    Random random

    This Random.

    int minLength

    The minimum length of the string to return (inclusive).

    int maxLength

    The maximum length of the string to return (inclusive).

    Returns
    Type Description
    string
    Exceptions
    Type Condition
    ArgumentException

    minLength is greater than maxLength.

    ArgumentOutOfRangeException

    minLength or maxLength is less than 0.

    ArgumentNullException

    random is null.

    RandomSimpleStringRange(Random, char, char, int)

    Returns a random string consisting only of characters between minChar (inclusive) and maxChar (inclusive).

    Declaration
    public static string RandomSimpleStringRange(Random random, char minChar, char maxChar, int maxLength)
    Parameters
    Type Name Description
    Random random

    This Random.

    char minChar

    The minimum char value of the range (inclusive).

    char maxChar

    The maximum char value of the range (inclusive).

    int maxLength

    The maximum length of the string to generate.

    Returns
    Type Description
    string

    a random string consisting only of characters between minChar (inclusive) and maxChar (inclusive).

    Exceptions
    Type Condition
    ArgumentException

    minChar is greater than maxChar.

    ArgumentOutOfRangeException

    minChar or maxChar is not in the range between MinValue and MaxValue.

    -or-

    maxLength is less than 0.
    ArgumentNullException

    random is null.

    RandomSubString(Random, int, bool)

    General utility methods for Lucene unit tests.

    Declaration
    public static string RandomSubString(Random random, int wordLength, bool simple)
    Parameters
    Type Name Description
    Random random
    int wordLength
    bool simple
    Returns
    Type Description
    string

    RandomUnicodeString(Random)

    Returns random string with up to 20 characters, including full unicode range.

    Declaration
    public static string RandomUnicodeString(Random random)
    Parameters
    Type Name Description
    Random random

    This Random.

    Returns
    Type Description
    string
    Exceptions
    Type Condition
    ArgumentNullException

    random is null.

    RandomUnicodeString(Random, int)

    Returns a random string up to a certain length.

    Declaration
    public static string RandomUnicodeString(Random random, int maxLength)
    Parameters
    Type Name Description
    Random random

    This Random.

    int maxLength

    The maximum length of the string to return.

    Returns
    Type Description
    string
    Exceptions
    Type Condition
    ArgumentOutOfRangeException

    maxLength is less than 0.

    ArgumentNullException

    random is null.

    RandomWhitespace(Random, int, int)

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

    Declaration
    public static string RandomWhitespace(Random random, int minLength, int maxLength)
    Parameters
    Type Name Description
    Random random
    int minLength
    int maxLength
    Returns
    Type Description
    string
    See Also
    WHITESPACE_CHARACTERS

    RandomlyRecaseString(Random, string)

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

    Declaration
    public static string RandomlyRecaseString(Random random, string value)
    Parameters
    Type Name Description
    Random random

    This Random.

    string value

    The string to recase randomly.

    Returns
    Type Description
    string
    Exceptions
    Type Condition
    ArgumentNullException

    random or value is null.

    RandomlyRecaseString(Random, string, CultureInfo)

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

    Declaration
    public static string RandomlyRecaseString(Random random, string value, CultureInfo culture)
    Parameters
    Type Name Description
    Random random

    This Random.

    string value

    The string to recase randomly.

    CultureInfo culture

    The culture to use when recasing the string.

    Returns
    Type Description
    string
    Exceptions
    Type Condition
    ArgumentNullException

    random, value or culture is null.

    ReduceOpenFiles(IndexWriter)

    Just tries to configure things to keep the open file count lowish.

    Declaration
    public static void ReduceOpenFiles(IndexWriter w)
    Parameters
    Type Name Description
    IndexWriter w

    Rm(params FileSystemInfo[])

    Deletes one or more files or directories (and everything underneath it).

    Declaration
    public static void Rm(params FileSystemInfo[] locations)
    Parameters
    Type Name Description
    FileSystemInfo[] locations
    Exceptions
    Type Condition
    IOException

    If any of the given files (or their subhierarchy files in case of directories) cannot be removed.

    StringToCharSequence(string, Random)

    General utility methods for Lucene unit tests.

    Declaration
    public static ICharSequence StringToCharSequence(string @string, Random random)
    Parameters
    Type Name Description
    string string
    Random random
    Returns
    Type Description
    ICharSequence

    SyncConcurrentMerges(IMergeScheduler)

    General utility methods for Lucene unit tests.

    Declaration
    public static void SyncConcurrentMerges(IMergeScheduler ms)
    Parameters
    Type Name Description
    IMergeScheduler ms

    SyncConcurrentMerges(IndexWriter)

    General utility methods for Lucene unit tests.

    Declaration
    public static void SyncConcurrentMerges(IndexWriter writer)
    Parameters
    Type Name Description
    IndexWriter writer

    Unzip(Stream, DirectoryInfo)

    Convenience method unzipping zipFileStream into destDir, cleaning up destDir first.

    Declaration
    public static void Unzip(Stream zipFileStream, DirectoryInfo destDir)
    Parameters
    Type Name Description
    Stream zipFileStream
    DirectoryInfo destDir
    Back to top Copyright © 2024 The Apache Software Foundation, Licensed under the Apache License, Version 2.0
    Apache Lucene.Net, Lucene.Net, Apache, the Apache feather logo, and the Apache Lucene.Net project logo are trademarks of The Apache Software Foundation.
    All other marks mentioned may be trademarks or registered trademarks of their respective owners.