public final class RandomizedContext
extends java.lang.Object
RandomizedRunner
.Modifier and Type | Method and Description |
---|---|
<T extends java.io.Closeable> |
closeAtEnd(T resource,
LifecycleScope scope)
Dispose the given resource at the end of a given lifecycle scope.
|
static RandomizedContext |
current() |
GroupEvaluator |
getGroupEvaluator()
Provide access to
GroupEvaluator . |
java.util.Random |
getRandom()
A shorthand for calling
getRandomness() and then Randomness.getRandom() . |
Randomness |
getRandomness()
Source of randomness for the context's thread.
|
RandomizedRunner |
getRunner()
Access to the runner governing this context.
|
java.lang.String |
getRunnerSeedAsString()
Returns the runner's master seed, formatted.
|
java.lang.Class<?> |
getTargetClass()
The class (suite) being tested.
|
java.lang.reflect.Method |
getTargetMethod() |
boolean |
isNightly()
Return
true if Nightly test group is explicitly enabled. |
<T> T |
runWithPrivateRandomness(long seed,
java.util.concurrent.Callable<T> callable)
Pushes the given randomness to the top of the stack, runs the
Callable and disposes
the randomness before the this method returns. |
<T> T |
runWithPrivateRandomness(Randomness randomness,
java.util.concurrent.Callable<T> callable)
Pushes the given randomness to the top of the stack, runs the
Callable and disposes
the randomness before the this method returns. |
public java.lang.Class<?> getTargetClass()
public java.lang.String getRunnerSeedAsString()
public Randomness getRandomness()
public java.util.Random getRandom()
getRandomness()
and then Randomness.getRandom()
.public boolean isNightly()
true
if Nightly
test group is explicitly enabled.public static RandomizedContext current()
IllegalStateException
if the thread is out of scope.java.lang.IllegalStateException
- If context is not available.public RandomizedRunner getRunner()
public <T extends java.io.Closeable> T closeAtEnd(T resource, LifecycleScope scope)
Closeable
throws an exception, the test case or suite will end in a failure.resource
(for call chaining).public GroupEvaluator getGroupEvaluator()
GroupEvaluator
.public <T> T runWithPrivateRandomness(Randomness randomness, java.util.concurrent.Callable<T> callable) throws java.lang.Exception
Callable
and disposes
the randomness before the this method returns.
This utility method can be used to initialize resources in a reproducible way since all calls to utility methods
like RandomizedTest.randomInt()
et.al. are forwarded to the current
RandomContext which uses the provided randomness from the top of the stack.
T
- the return type of the callablerandomness
- the randomness to push to the top of the stackcallable
- the callable to executeCallable.call()
java.lang.Exception
- if Callable.call()
throws an exceptionpublic <T> T runWithPrivateRandomness(long seed, java.util.concurrent.Callable<T> callable) throws java.lang.Exception
Callable
and disposes
the randomness before the this method returns.
This utility method can be used to initialize resources in a reproducible way since all calls to utility methods
like RandomizedTest.randomInt()
et.al. are forwarded to the current
RandomContext which uses the provided randomness from the top of the stack.
T
- the return type of the callableseed
- The initial seed for the new, private randomnesscallable
- the callable to executeCallable.call()
java.lang.Exception
- if Callable.call()
throws an exceptionpublic java.lang.reflect.Method getTargetMethod()
null
if called from the static context (no test case is being executed at
the moment).Copyright © 2011–2017 Carrot Search s.c.. All rights reserved.