public final class RandomizedContext extends Object
RandomizedRunner
.Modifier and Type | Method and Description |
---|---|
<T extends Closeable> |
closeAtEnd(T resource,
LifecycleScope scope)
Dispose the given resource at the end of a given lifecycle scope.
|
static RandomizedContext |
current() |
com.carrotsearch.randomizedtesting.GroupEvaluator |
getGroupEvaluator()
Provide access to
GroupEvaluator . |
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.
|
String |
getRunnerSeedAsString()
Returns the runner's master seed, formatted.
|
Class<?> |
getTargetClass()
The class (suite) being tested.
|
Method |
getTargetMethod() |
boolean |
isNightly()
Deprecated.
[GH-218] will be removed. Use
getGroupEvaluator() . |
<T> T |
runWithPrivateRandomness(Randomness randomness,
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 Class<?> getTargetClass()
public String getRunnerSeedAsString()
public Randomness getRandomness()
public Random getRandom()
getRandomness()
and then Randomness.getRandom()
.public boolean isNightly()
getGroupEvaluator()
.true
if tests are running in nightly mode.public static RandomizedContext current()
IllegalStateException
if the thread is out of scope.IllegalStateException
- If context is not available.public RandomizedRunner getRunner()
public <T extends 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 com.carrotsearch.randomizedtesting.GroupEvaluator getGroupEvaluator()
GroupEvaluator
.public <T> T runWithPrivateRandomness(Randomness randomness, Callable<T> callable) throws 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()
Exception
- if Callable.call()
throws an exceptionpublic Method getTargetMethod()
null
if called from the static context (no test case is being executed at
the moment).Copyright © 2011–2016 Carrot Search s.c.. All rights reserved.