Class ESTestCase

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  ESTestCase.GeohashGenerator  
      static class  ESTestCase.TestAnalysis
      This cute helper class just holds all analysis building blocks that are used to build IndexAnalyzers.
      • Nested classes/interfaces inherited from class org.apache.lucene.util.LuceneTestCase

        org.apache.lucene.util.LuceneTestCase.AwaitsFix, org.apache.lucene.util.LuceneTestCase.BadApple, org.apache.lucene.util.LuceneTestCase.Monster, org.apache.lucene.util.LuceneTestCase.Nightly, org.apache.lucene.util.LuceneTestCase.Slow, org.apache.lucene.util.LuceneTestCase.SuppressCodecs, org.apache.lucene.util.LuceneTestCase.SuppressFileSystems, org.apache.lucene.util.LuceneTestCase.SuppressFsync, org.apache.lucene.util.LuceneTestCase.SuppressReproduceLine, org.apache.lucene.util.LuceneTestCase.SuppressSysoutChecks, org.apache.lucene.util.LuceneTestCase.SuppressTempFileChecks, org.apache.lucene.util.LuceneTestCase.ThrowingRunnable, org.apache.lucene.util.LuceneTestCase.Weekly
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static boolean checkIndexFailed
      MockFSDirectoryService sets this:
      protected DeprecationLogger deprecationLogger  
      org.junit.rules.RuleChain failureAndSuccessEvents  
      protected static java.util.List<java.lang.String> JAVA_TIMEZONE_IDS  
      protected static java.util.List<java.lang.String> JAVA_ZONE_IDS  
      protected static java.util.List<java.lang.String> JODA_TIMEZONE_IDS  
      protected org.apache.logging.log4j.Logger logger  
      • Fields inherited from class org.apache.lucene.util.LuceneTestCase

        assertsAreEnabled, classRules, DEFAULT_LINE_DOCS_FILE, INFOSTREAM, JENKINS_LARGE_LINE_DOCS_FILE, LEAVE_TEMPORARY, MAYBE_CACHE_POLICY, RANDOM_MULTIPLIER, ruleChain, suiteFailureMarker, SYSPROP_AWAITSFIX, SYSPROP_BADAPPLES, SYSPROP_FAILFAST, SYSPROP_MAXFAILURES, SYSPROP_MONSTER, SYSPROP_NIGHTLY, SYSPROP_SLOW, SYSPROP_WEEKLY, TEST_ASSERTS_ENABLED, TEST_AWAITSFIX, TEST_BADAPPLES, TEST_CODEC, TEST_DIRECTORY, TEST_DOCVALUESFORMAT, TEST_LINE_DOCS_FILE, TEST_MONSTER, TEST_NIGHTLY, TEST_POSTINGSFORMAT, TEST_SLOW, TEST_THROTTLING, TEST_WEEKLY, VERBOSE
    • Constructor Summary

      Constructors 
      Constructor Description
      ESTestCase()  
    • Field Detail

      • JODA_TIMEZONE_IDS

        protected static final java.util.List<java.lang.String> JODA_TIMEZONE_IDS
      • JAVA_TIMEZONE_IDS

        protected static final java.util.List<java.lang.String> JAVA_TIMEZONE_IDS
      • JAVA_ZONE_IDS

        protected static final java.util.List<java.lang.String> JAVA_ZONE_IDS
      • logger

        protected final org.apache.logging.log4j.Logger logger
      • failureAndSuccessEvents

        public org.junit.rules.RuleChain failureAndSuccessEvents
      • checkIndexFailed

        public static boolean checkIndexFailed
        MockFSDirectoryService sets this:
    • Constructor Detail

      • ESTestCase

        public ESTestCase()
    • Method Detail

      • resetPortCounter

        public static void resetPortCounter()
      • buildNewFakeTransportAddress

        public static TransportAddress buildNewFakeTransportAddress()
        Generates a new transport address using TransportAddress.META_ADDRESS with an incrementing port number. The port number starts at 0 and is reset after each test suite run.
      • afterIfFailed

        protected void afterIfFailed​(java.util.List<java.lang.Throwable> errors)
        Called when a test fails, supplying the errors it generated. Not called when the test fails because assumptions are violated.
      • afterIfSuccessful

        protected void afterIfSuccessful()
                                  throws java.lang.Exception
        called after a test is finished, but only if successful
        Throws:
        java.lang.Exception
      • setFileSystem

        public static void setFileSystem()
                                  throws java.lang.Exception
        Throws:
        java.lang.Exception
      • restoreFileSystem

        public static void restoreFileSystem()
                                      throws java.lang.Exception
        Throws:
        java.lang.Exception
      • setContentType

        public static void setContentType()
                                   throws java.lang.Exception
        Throws:
        java.lang.Exception
      • restoreContentType

        public static void restoreContentType()
      • ensureSupportedLocale

        public static void ensureSupportedLocale()
      • before

        public final void before()
      • enableWarningsCheck

        protected boolean enableWarningsCheck()
        Whether or not we check after each test whether it has left warnings behind. That happens if any deprecated feature or syntax was used by the test and the test didn't assert on it using assertWarnings(String...).
      • enableJodaDeprecationWarningsCheck

        protected boolean enableJodaDeprecationWarningsCheck()
      • after

        public final void after()
                         throws java.lang.Exception
        Throws:
        java.lang.Exception
      • assertSettingDeprecationsAndWarnings

        protected final void assertSettingDeprecationsAndWarnings​(Setting<?>[] settings,
                                                                  java.lang.String... warnings)
        Convenience method to assert warnings for settings deprecations and general deprecation warnings.
        Parameters:
        settings - the settings that are expected to be deprecated
        warnings - other expected general deprecation warnings
      • assertSettingDeprecationsAndWarnings

        protected final void assertSettingDeprecationsAndWarnings​(java.lang.String[] settings,
                                                                  java.lang.String... warnings)
      • assertWarnings

        protected final void assertWarnings​(java.lang.String... expectedWarnings)
      • checkStaticState

        protected static void checkStaticState​(boolean afterClass)
                                        throws java.lang.Exception
        Throws:
        java.lang.Exception
      • ensureAllSearchContextsReleased

        public final void ensureAllSearchContextsReleased()
                                                   throws java.lang.Exception
        Throws:
        java.lang.Exception
      • resetCheckIndexStatus

        public final void resetCheckIndexStatus()
                                         throws java.lang.Exception
        Throws:
        java.lang.Exception
      • ensureCheckIndexPassed

        public final void ensureCheckIndexPassed()
                                          throws java.lang.Exception
        Throws:
        java.lang.Exception
      • scaledRandomIntBetween

        public static int scaledRandomIntBetween​(int min,
                                                 int max)
        Returns a "scaled" random number between min and max (inclusive).
        See Also:
        RandomizedTest.scaledRandomIntBetween(int, int)
      • randomIntBetween

        public static int randomIntBetween​(int min,
                                           int max)
        A random integer from min to max (inclusive).
        See Also:
        scaledRandomIntBetween(int, int)
      • randomLongBetween

        public static long randomLongBetween​(long min,
                                             long max)
        A random long number between min (inclusive) and max (inclusive).
      • iterations

        public static int iterations​(int min,
                                     int max)
        Returns a "scaled" number of iterations for loops which can have a variable iteration count. This method is effectively an alias to scaledRandomIntBetween(int, int).
      • frequently

        public static boolean frequently()
        The exact opposite of LuceneTestCase.rarely().
      • randomBoolean

        public static boolean randomBoolean()
      • randomByte

        public static byte randomByte()
      • randomByteArrayOfLength

        public static byte[] randomByteArrayOfLength​(int size)
        Helper method to create a byte array of a given length populated with random byte values
        See Also:
        randomByte()
      • randomShort

        public static short randomShort()
      • randomInt

        public static int randomInt()
      • randomNonNegativeLong

        public static long randomNonNegativeLong()
        Returns:
        a long between 0 and Long.MAX_VALUE (inclusive) chosen uniformly at random.
      • randomFloat

        public static float randomFloat()
      • randomDouble

        public static double randomDouble()
      • randomDoubleBetween

        public static double randomDoubleBetween​(double start,
                                                 double end,
                                                 boolean lowerInclusive)
        Returns a double value in the interval [start, end) if lowerInclusive is set to true, (start, end) otherwise.
        Parameters:
        start - lower bound of interval to draw uniformly distributed random numbers from
        end - upper bound
        lowerInclusive - whether or not to include lower end of the interval
      • randomLong

        public static long randomLong()
      • randomInt

        public static int randomInt​(int max)
        A random integer from 0..max (inclusive).
      • randomFrom

        public static <T> T randomFrom​(T... array)
        Pick a random object from the given array. The array must not be empty.
      • randomFrom

        public static <T> T randomFrom​(java.util.Random random,
                                       T... array)
        Pick a random object from the given array. The array must not be empty.
      • randomFrom

        public static <T> T randomFrom​(java.util.List<T> list)
        Pick a random object from the given list.
      • randomFrom

        public static <T> T randomFrom​(java.util.Collection<T> collection)
        Pick a random object from the given collection.
      • randomFrom

        public static <T> T randomFrom​(java.util.Random random,
                                       java.util.Collection<T> collection)
        Pick a random object from the given collection.
      • randomAlphaOfLengthBetween

        public static java.lang.String randomAlphaOfLengthBetween​(int minCodeUnits,
                                                                  int maxCodeUnits)
      • randomAlphaOfLength

        public static java.lang.String randomAlphaOfLength​(int codeUnits)
      • randomUnicodeOfLengthBetween

        public static java.lang.String randomUnicodeOfLengthBetween​(int minCodeUnits,
                                                                    int maxCodeUnits)
      • randomUnicodeOfLength

        public static java.lang.String randomUnicodeOfLength​(int codeUnits)
      • randomUnicodeOfCodepointLengthBetween

        public static java.lang.String randomUnicodeOfCodepointLengthBetween​(int minCodePoints,
                                                                             int maxCodePoints)
      • randomUnicodeOfCodepointLength

        public static java.lang.String randomUnicodeOfCodepointLength​(int codePoints)
      • randomRealisticUnicodeOfLengthBetween

        public static java.lang.String randomRealisticUnicodeOfLengthBetween​(int minCodeUnits,
                                                                             int maxCodeUnits)
      • randomRealisticUnicodeOfLength

        public static java.lang.String randomRealisticUnicodeOfLength​(int codeUnits)
      • randomRealisticUnicodeOfCodepointLengthBetween

        public static java.lang.String randomRealisticUnicodeOfCodepointLengthBetween​(int minCodePoints,
                                                                                      int maxCodePoints)
      • randomRealisticUnicodeOfCodepointLength

        public static java.lang.String randomRealisticUnicodeOfCodepointLength​(int codePoints)
      • generateRandomStringArray

        public static java.lang.String[] generateRandomStringArray​(int maxArraySize,
                                                                   int stringSize,
                                                                   boolean allowNull,
                                                                   boolean allowEmpty)
      • generateRandomStringArray

        public static java.lang.String[] generateRandomStringArray​(int maxArraySize,
                                                                   int stringSize,
                                                                   boolean allowNull)
      • randomArray

        public static <T> T[] randomArray​(int maxArraySize,
                                          java.util.function.IntFunction<T[]> arrayConstructor,
                                          java.util.function.Supplier<T> valueConstructor)
      • randomArray

        public static <T> T[] randomArray​(int minArraySize,
                                          int maxArraySize,
                                          java.util.function.IntFunction<T[]> arrayConstructor,
                                          java.util.function.Supplier<T> valueConstructor)
      • randomTimeValue

        public static java.lang.String randomTimeValue​(int lower,
                                                       int upper,
                                                       java.lang.String... suffixes)
      • randomTimeValue

        public static java.lang.String randomTimeValue​(int lower,
                                                       int upper)
      • randomTimeValue

        public static java.lang.String randomTimeValue()
      • randomPositiveTimeValue

        public static java.lang.String randomPositiveTimeValue()
      • randomDateTimeZone

        public static org.joda.time.DateTimeZone randomDateTimeZone()
        generate a random DateTimeZone from the ones available in joda library
      • randomTimeZone

        public static java.util.TimeZone randomTimeZone()
        generate a random TimeZone from the ones available in java.util
      • randomZone

        public static java.time.ZoneId randomZone()
        generate a random TimeZone from the ones available in java.time
      • maybeSet

        public static <T> void maybeSet​(java.util.function.Consumer<T> consumer,
                                        T value)
        helper to randomly perform on consumer with value
      • randomValueOtherThan

        public static <T> T randomValueOtherThan​(T input,
                                                 java.util.function.Supplier<T> randomSupplier)
        helper to get a random value in a certain range that's different from the input
      • randomValueOtherThanMany

        public static <T> T randomValueOtherThanMany​(java.util.function.Predicate<T> input,
                                                     java.util.function.Supplier<T> randomSupplier)
        helper to get a random value in a certain range that's different from the input
      • assertBusy

        public static void assertBusy​(CheckedRunnable<java.lang.Exception> codeBlock)
                               throws java.lang.Exception
        Runs the code block for 10 seconds waiting for no assertion to trip.
        Throws:
        java.lang.Exception
      • assertBusy

        public static void assertBusy​(CheckedRunnable<java.lang.Exception> codeBlock,
                                      long maxWaitTime,
                                      java.util.concurrent.TimeUnit unit)
                               throws java.lang.Exception
        Runs the code block for the provided interval, waiting for no assertions to trip.
        Throws:
        java.lang.Exception
      • awaitBusy

        public static boolean awaitBusy​(java.util.function.BooleanSupplier breakSupplier)
                                 throws java.lang.InterruptedException
        Throws:
        java.lang.InterruptedException
      • awaitBusy

        public static boolean awaitBusy​(java.util.function.BooleanSupplier breakSupplier,
                                        long maxWaitTime,
                                        java.util.concurrent.TimeUnit unit)
                                 throws java.lang.InterruptedException
        Throws:
        java.lang.InterruptedException
      • terminate

        public static boolean terminate​(java.util.concurrent.ExecutorService... services)
                                 throws java.lang.InterruptedException
        Throws:
        java.lang.InterruptedException
      • terminate

        public static boolean terminate​(ThreadPool threadPool)
      • getDataPath

        public java.nio.file.Path getDataPath​(java.lang.String relativePath)
        Returns a Path pointing to the class path relative resource given as the first argument. In contrast to getClass().getResource(...).getFile() this method will not return URL encoded paths if the parent path contains spaces or other non-standard characters.
        Overrides:
        getDataPath in class org.apache.lucene.util.LuceneTestCase
      • getBwcIndicesPath

        public java.nio.file.Path getBwcIndicesPath()
      • tmpPaths

        public java.lang.String[] tmpPaths()
        Returns a random number of temporary paths.
      • newNodeEnvironment

        public NodeEnvironment newNodeEnvironment()
                                           throws java.io.IOException
        Throws:
        java.io.IOException
      • newNodeEnvironment

        public NodeEnvironment newNodeEnvironment​(Settings settings)
                                           throws java.io.IOException
        Throws:
        java.io.IOException
      • settings

        public static Settings.Builder settings​(Version version)
        Return consistent index settings for the provided index version.
      • randomSubsetOf

        public static <T> java.util.List<T> randomSubsetOf​(int size,
                                                           T... values)
        Returns size random values
      • randomSubsetOf

        public static <T> java.util.List<T> randomSubsetOf​(java.util.Collection<T> collection)
        Returns a random subset of values (including a potential empty list)
      • randomSubsetOf

        public static <T> java.util.List<T> randomSubsetOf​(int size,
                                                           java.util.Collection<T> collection)
        Returns size random values
      • randomUnique

        public static <T> java.util.Set<T> randomUnique​(java.util.function.Supplier<T> supplier,
                                                        int targetCount)
        Builds a set of unique items. Usually you'll get the requested count but you might get less than that number if the supplier returns lots of repeats. Make sure that the items properly implement equals and hashcode.
      • randomGeohash

        public static java.lang.String randomGeohash​(int minPrecision,
                                                     int maxPrecision)
      • getTestTransportType

        public static java.lang.String getTestTransportType()
      • getTestTransportPlugin

        public static java.lang.Class<? extends Plugin> getTestTransportPlugin()
      • toShuffledXContent

        protected final BytesReference toShuffledXContent​(ToXContent toXContent,
                                                          XContentType xContentType,
                                                          ToXContent.Params params,
                                                          boolean humanReadable,
                                                          java.lang.String... exceptFieldNames)
                                                   throws java.io.IOException
        Returns the bytes that represent the XContent output of the provided ToXContent object, using the provided XContentType. Wraps the output into a new anonymous object according to the value returned by the ToXContent.isFragment() method returns. Shuffles the keys to make sure that parsing never relies on keys ordering.
        Throws:
        java.io.IOException
      • shuffleXContent

        protected final XContentBuilder shuffleXContent​(XContentBuilder builder,
                                                        java.lang.String... exceptFieldNames)
                                                 throws java.io.IOException
        Randomly shuffles the fields inside objects in the XContentBuilder passed in. Recursively goes through inner objects and also shuffles them. Exceptions for this recursive shuffling behavior can be made by passing in the names of fields which internally should stay untouched.
        Throws:
        java.io.IOException
      • shuffleXContent

        public static XContentBuilder shuffleXContent​(XContentParser parser,
                                                      boolean prettyPrint,
                                                      java.lang.String... exceptFieldNames)
                                               throws java.io.IOException
        Randomly shuffles the fields inside objects parsed using the XContentParser passed in. Recursively goes through inner objects and also shuffles them. Exceptions for this recursive shuffling behavior can be made by passing in the names of fields which internally should stay untouched.
        Throws:
        java.io.IOException
      • shuffleMap

        public static java.util.LinkedHashMap<java.lang.String,​java.lang.Object> shuffleMap​(java.util.LinkedHashMap<java.lang.String,​java.lang.Object> map,
                                                                                                  java.util.Set<java.lang.String> exceptFields)
      • assertAllIndicesRemovedAndDeletionCompleted

        public void assertAllIndicesRemovedAndDeletionCompleted​(java.lang.Iterable<IndicesService> indicesServices)
                                                         throws java.lang.Exception
        Throws:
        java.lang.Exception
      • assertPathHasBeenCleared

        public void assertPathHasBeenCleared​(java.nio.file.Path path)
        Asserts that there are no files in the specified path
      • createParser

        protected final XContentParser createParser​(XContent xContent,
                                                    java.lang.String data)
                                             throws java.io.IOException
        Create a new XContentParser.
        Throws:
        java.io.IOException
      • createParser

        protected final XContentParser createParser​(XContent xContent,
                                                    java.io.InputStream data)
                                             throws java.io.IOException
        Create a new XContentParser.
        Throws:
        java.io.IOException
      • createParser

        protected final XContentParser createParser​(XContent xContent,
                                                    byte[] data)
                                             throws java.io.IOException
        Create a new XContentParser.
        Throws:
        java.io.IOException
      • mockScript

        public static final Script mockScript​(java.lang.String id)
        Create a "mock" script for use either with MockScriptEngine or anywhere where you need a script but don't really care about its contents.
      • getSuiteFailureMarker

        public static org.apache.lucene.util.TestRuleMarkFailure getSuiteFailureMarker()
        Returns the suite failure marker: internal use only!
      • assertArrayEquals

        public static void assertArrayEquals​(java.lang.StackTraceElement[] expected,
                                             java.lang.StackTraceElement[] actual)
        Compares two stack traces, ignoring module (which is not yet serialized)
      • assertEquals

        public static void assertEquals​(java.lang.StackTraceElement expected,
                                        java.lang.StackTraceElement actual)
        Compares two stack trace elements, ignoring module (which is not yet serialized)
      • spinForAtLeastOneMillisecond

        protected static long spinForAtLeastOneMillisecond()
      • spinForAtLeastNMilliseconds

        protected static long spinForAtLeastNMilliseconds​(long ms)
      • createTestAnalysis

        public static ESTestCase.TestAnalysis createTestAnalysis​(Index index,
                                                                 Settings settings,
                                                                 AnalysisPlugin... analysisPlugins)
                                                          throws java.io.IOException
        Creates an TestAnalysis with all the default analyzers configured.
        Throws:
        java.io.IOException
      • createTestAnalysis

        public static ESTestCase.TestAnalysis createTestAnalysis​(Index index,
                                                                 Settings nodeSettings,
                                                                 Settings settings,
                                                                 AnalysisPlugin... analysisPlugins)
                                                          throws java.io.IOException
        Creates an TestAnalysis with all the default analyzers configured.
        Throws:
        java.io.IOException
      • createTestAnalysis

        public static ESTestCase.TestAnalysis createTestAnalysis​(IndexSettings indexSettings,
                                                                 Settings nodeSettings,
                                                                 AnalysisPlugin... analysisPlugins)
                                                          throws java.io.IOException
        Creates an TestAnalysis with all the default analyzers configured.
        Throws:
        java.io.IOException
      • newTestScriptModule

        public static ScriptModule newTestScriptModule()
      • newTestIndicesModule

        public static IndicesModule newTestIndicesModule​(java.util.Map<java.lang.String,​Mapper.TypeParser> extraMappers,
                                                         java.util.Map<java.lang.String,​MetadataFieldMapper.TypeParser> extraMetadataMappers)
        Creates an IndicesModule for testing with the given mappers and metadata mappers.
      • inFipsJvm

        public static boolean inFipsJvm()