Class AssertingRandom

java.lang.Object
java.util.Random
com.carrotsearch.randomizedtesting.AssertingRandom
All Implemented Interfaces:
Serializable

public final class AssertingRandom extends Random
A random with a delegate, preventing Random.setSeed(long) and locked to be used by a single thread.
See Also:
  • Field Details

    • delegate

      private final Random delegate
    • ownerRef

      private final WeakReference<Thread> ownerRef
    • ownerName

      private final String ownerName
    • allocationStack

      private final StackTraceElement[] allocationStack
    • valid

      private volatile boolean valid
      Track out-of-context use of this Random instance. 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.
  • Constructor Details

    • AssertingRandom

      public AssertingRandom(Thread owner, Random delegate)
      Creates an instance to be used by owner thread and delegating to delegate until destroy()ed.
  • Method Details

    • next

      protected int next(int bits)
      Overrides:
      next in class Random
    • nextBoolean

      public boolean nextBoolean()
      Overrides:
      nextBoolean in class Random
    • nextBytes

      public void nextBytes(byte[] bytes)
      Overrides:
      nextBytes in class Random
    • nextDouble

      public double nextDouble()
      Overrides:
      nextDouble in class Random
    • nextFloat

      public float nextFloat()
      Overrides:
      nextFloat in class Random
    • nextGaussian

      public double nextGaussian()
      Overrides:
      nextGaussian in class Random
    • nextInt

      public int nextInt()
      Overrides:
      nextInt in class Random
    • nextInt

      public int nextInt(int n)
      Overrides:
      nextInt in class Random
    • nextLong

      public long nextLong()
      Overrides:
      nextLong in class Random
    • setSeed

      public void setSeed(long seed)
      Overrides:
      setSeed in class Random
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • destroy

      public void destroy()
      This object will no longer be usable after this method is called.
    • checkValid

      private final void checkValid()
    • clone

      protected Object clone() throws CloneNotSupportedException
      Overrides:
      clone in class Object
      Throws:
      CloneNotSupportedException
    • isVerifying

      public static boolean isVerifying()
      Returns:
      Return true if this class is verifying sharing and lifecycle assertions.
      See Also:
      • "https://github.com/randomizedtesting/randomizedtesting/issues/234"
    • noSetSeed

      static RuntimeException noSetSeed()