Class AssertingRandom
- java.lang.Object
-
- java.util.Random
-
- com.carrotsearch.randomizedtesting.AssertingRandom
-
- All Implemented Interfaces:
java.io.Serializable
public final class AssertingRandom extends java.util.RandomA random with a delegate, preventingRandom.setSeed(long)and locked to be used by a single thread.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StackTraceElement[]allocationStackprivate static booleanassertionsEnabledEnable paranoid mode when assertions are enabled.private java.util.Randomdelegateprivate java.lang.StringownerNameprivate java.lang.ref.WeakReference<java.lang.Thread>ownerRefprivate booleanvalidTrack out-of-context use of thisRandominstance.
-
Constructor Summary
Constructors Constructor Description AssertingRandom(java.lang.Thread owner, java.util.Random delegate)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidcheckValid()protected java.lang.Objectclone()voiddestroy()This object will no longer be usable after this method is called.booleanequals(java.lang.Object obj)inthashCode()static booleanisVerifying()protected intnext(int bits)booleannextBoolean()voidnextBytes(byte[] bytes)doublenextDouble()floatnextFloat()doublenextGaussian()intnextInt()intnextInt(int n)longnextLong()(package private) static java.lang.RuntimeExceptionnoSetSeed()voidsetSeed(long seed)java.lang.StringtoString()
-
-
-
Field Detail
-
delegate
private final java.util.Random delegate
-
ownerRef
private final java.lang.ref.WeakReference<java.lang.Thread> ownerRef
-
ownerName
private final java.lang.String ownerName
-
allocationStack
private final java.lang.StackTraceElement[] allocationStack
-
valid
private volatile boolean valid
Track out-of-context use of thisRandominstance. This introduces memory barriers and scheduling side-effects but there's no other way to do it in any other way and sharing randoms across threads or test cases is very bad and worth tracking.
-
assertionsEnabled
private static final boolean assertionsEnabled
Enable paranoid mode when assertions are enabled.
-
-
Method Detail
-
next
protected int next(int bits)
- Overrides:
nextin classjava.util.Random
-
nextBoolean
public boolean nextBoolean()
- Overrides:
nextBooleanin classjava.util.Random
-
nextBytes
public void nextBytes(byte[] bytes)
- Overrides:
nextBytesin classjava.util.Random
-
nextDouble
public double nextDouble()
- Overrides:
nextDoublein classjava.util.Random
-
nextFloat
public float nextFloat()
- Overrides:
nextFloatin classjava.util.Random
-
nextGaussian
public double nextGaussian()
- Overrides:
nextGaussianin classjava.util.Random
-
nextInt
public int nextInt()
- Overrides:
nextIntin classjava.util.Random
-
nextInt
public int nextInt(int n)
- Overrides:
nextIntin classjava.util.Random
-
nextLong
public long nextLong()
- Overrides:
nextLongin classjava.util.Random
-
setSeed
public void setSeed(long seed)
- Overrides:
setSeedin classjava.util.Random
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
destroy
public void destroy()
This object will no longer be usable after this method is called.
-
checkValid
private final void checkValid()
-
clone
protected java.lang.Object clone() throws java.lang.CloneNotSupportedException- Overrides:
clonein classjava.lang.Object- Throws:
java.lang.CloneNotSupportedException
-
isVerifying
public static boolean isVerifying()
- Returns:
- Return
trueif this class is verifying sharing and lifecycle assertions. - See Also:
- "https://github.com/randomizedtesting/randomizedtesting/issues/234"
-
noSetSeed
static java.lang.RuntimeException noSetSeed()
-
-