Class MixWithIncrement

java.lang.Object
org.elasticsearch.test.MixWithIncrement
All Implemented Interfaces:
com.carrotsearch.randomizedtesting.SeedDecorator

public class MixWithIncrement extends Object implements com.carrotsearch.randomizedtesting.SeedDecorator
The Randomness class creates random generators with the same seed in every thread.

This means that repeatedly calling:

   
     new Thread(() -> System.out.println(Randomness.get().nextInt())).start();
   
 
will print the same number in every thread.

For some use cases, this is not desirable, e.g. when testing that the random behavior obeys certain statistical properties.

To fix this, annotate a test class with:

   
     @SeedDecorators(MixWithIncrement.class)
   
 
In this way, an additional seed is mixed into the seed of the random generators. This additional seed can be updated be calling:
   
     MixWithIncrement.next()
   
 
to make sure that new threads will get a different seed.
  • Constructor Details

    • MixWithIncrement

      public MixWithIncrement()
  • Method Details

    • initialize

      public void initialize(Class<?> aClass)
      Specified by:
      initialize in interface com.carrotsearch.randomizedtesting.SeedDecorator
    • decorate

      public long decorate(long seed)
      Specified by:
      decorate in interface com.carrotsearch.randomizedtesting.SeedDecorator
    • next

      public static void next()