/** * A shorthand for calling {@link #getRandomness()} and then {@link Randomness#getRandom()}. */ public Random getRandom() { return getRandomness().getRandom(); }
/** * A shorthand for calling {@link #getRandomness()} and then {@link Randomness#getRandom()}. */ public Random getRandom() { return getRandomness().getRandom(); }
@Test public void simpleArgumentsConsumer() { System.out.println(value + " " + string + " " + getContext().getRandomness()); }
@Test public void printContext() { System.out.println("# Test context (@Test)"); System.out.println(getContext().getRunnerSeedAsString()); System.out.println(RandomizedContext.current().getRandomness()); }
@BeforeClass public static void printMasterContext() { System.out.println("# Static context (@BeforeClass)"); System.out.println(getContext().getRunnerSeedAsString()); System.out.println(RandomizedContext.current().getRandomness()); }
@Seeds({@Seed("deadbeef"), @Seed("cafebabe")}) @Test @Repeat(iterations = 2, useConstantSeed = true) public void paramsWithRepeatAndSeeds() { System.out.println(value + " " + string + " " + getContext().getRandomness()); }
/** * Pushes the given randomness to the top of the stack, runs the {@link Callable} and disposes * the randomness before the this method returns. * <p> * This utility method can be used to initialize resources in a reproducible way since all calls to utility methods * like {@link com.carrotsearch.randomizedtesting.RandomizedTest#randomInt()} et.al. are forwarded to the current * RandomContext which uses the provided randomness from the top of the stack. * </p> * * @param seed The initial seed for the new, private randomness * @param callable the callable to execute * @param <T> the return type of the callable * @return the result of the call to {@link java.util.concurrent.Callable#call()} * @throws Exception if {@link java.util.concurrent.Callable#call()} throws an exception */ public <T> T runWithPrivateRandomness(long seed, Callable<T> callable) throws Exception { Randomness randomness = getRandomness(); Randomness prv = new Randomness(seed, randomness.getRandomSupplier(), randomness.getDecorators()); return runWithPrivateRandomness(prv, callable); }
/** * Pushes the given randomness to the top of the stack, runs the {@link Callable} and disposes * the randomness before the this method returns. * <p> * This utility method can be used to initialize resources in a reproducible way since all calls to utility methods * like {@link com.carrotsearch.randomizedtesting.RandomizedTest#randomInt()} et.al. are forwarded to the current * RandomContext which uses the provided randomness from the top of the stack. * </p> * * @param seed The initial seed for the new, private randomness * @param callable the callable to execute * @param <T> the return type of the callable * @return the result of the call to {@link java.util.concurrent.Callable#call()} * @throws Exception if {@link java.util.concurrent.Callable#call()} throws an exception */ public <T> T runWithPrivateRandomness(long seed, Callable<T> callable) throws Exception { Randomness randomness = getRandomness(); Randomness prv = new Randomness(seed, randomness.getRandomSupplier(), randomness.getDecorators()); return runWithPrivateRandomness(prv, callable); }