Package org.elasticsearch.test
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongdecorate(long seed) voidinitialize(Class<?> aClass) static voidnext()
-
Constructor Details
-
MixWithIncrement
public MixWithIncrement()
-
-
Method Details
-
initialize
- Specified by:
initializein interfacecom.carrotsearch.randomizedtesting.SeedDecorator
-
decorate
public long decorate(long seed) - Specified by:
decoratein interfacecom.carrotsearch.randomizedtesting.SeedDecorator
-
next
public static void next()
-