public static String clusterName(String prefix, long clusterSeed) { StringBuilder builder = new StringBuilder(prefix); final int childVM = RandomizedTest.systemPropertyAsInt(SysGlobals.CHILDVM_SYSPROP_JVM_ID, 0); builder.append("-CHILD_VM=[").append(childVM).append(']'); builder.append("-CLUSTER_SEED=[").append(clusterSeed).append(']'); // if multiple maven task run on a single host we better have an identifier that doesn't rely on input params builder.append("-HASH=[").append(SeedUtils.formatSeed(System.nanoTime())).append(']'); return builder.toString(); }
/** * Parse a seed chain formatted with {@link SeedUtils#formatSeedChain(Randomness...)}. */ public static long [] parseSeedChain(String chain) { chain = chain.replaceAll("[\\[\\]]", ""); if (!chain.matches("[0-9A-Fa-f\\:]+")) { throw new IllegalArgumentException("Not a valid seed chain: " + chain); } String [] splits = chain.split("[\\:]"); long [] longs = new long [splits.length]; for (int i = 0; i < splits.length; i++) longs[i] = parseSeed(splits[i]); return longs; }
/** * Get an annotated element's {@link Seed} annotation and determine if it's fixed * or not. If it is fixed, return the seeds. Otherwise return <code>randomSeed</code>. */ private long [] seedFromAnnot(AnnotatedElement element, long randomSeed) { Seed seed = element.getAnnotation(Seed.class); String seedChain = seed.value(); if (seedChain.equals("random")) { return new long [] { randomSeed }; } return SeedUtils.parseSeedChain(seedChain); }
@Override public String toString() { return "[Randomness, seed=" + SeedUtils.formatSeedChain(this) + "]"; }
@Override public String toString() { return "[Randomness, seed=" + SeedUtils.formatSeedChain(this) + "]"; }
/** * Formats randomness seed or seeds into something the user can type in to get predictably repeatable * execution. */ public static String formatSeedChain(Randomness... randomnesses) { StringBuilder b = new StringBuilder(); b.append("["); for (int i = 0; i < randomnesses.length; i++) { if (i > 0) b.append(":"); b.append(formatSeed(randomnesses[i].getSeed())); } b.append("]"); return b.toString(); } }
/** * Return the master seed of {@link #getSeed()}. */ private long masterSeed() { long[] seeds = SeedUtils.parseSeedChain(getSeed()); if (seeds.length < 1) { throw new BuildException("Random seed is required."); } return seeds[0]; }
/** * Parse a seed chain formatted with {@link SeedUtils#formatSeedChain(Randomness...)}. */ public static long [] parseSeedChain(String chain) { chain = chain.replaceAll("[\\[\\]]", ""); if (!chain.matches("[0-9A-Fa-f\\:]+")) { throw new IllegalArgumentException("Not a valid seed chain: " + chain); } String [] splits = chain.split("[\\:]"); long [] longs = new long [splits.length]; for (int i = 0; i < splits.length; i++) longs[i] = parseSeed(splits[i]); return longs; }
/** * Augment stack trace of the given exception with seed infos. */ static <T extends Throwable> T augmentStackTrace(T e, Randomness... seeds) { if (seeds.length == 0) { seeds = RandomizedContext.current().getRandomnesses(); } final String seedChain = SeedUtils.formatSeedChain(seeds); final String existingSeed = seedFromThrowable(e); if (existingSeed != null && existingSeed.equals(seedChain)) { return e; } List<StackTraceElement> stack = new ArrayList<StackTraceElement>( Arrays.asList(e.getStackTrace())); stack.add(0, new StackTraceElement(AUGMENTED_SEED_PACKAGE + ".SeedInfo", "seed", seedChain, 0)); e.setStackTrace(stack.toArray(new StackTraceElement [stack.size()])); return e; }
/** * Formats randomness seed or seeds into something the user can type in to get predictably repeatable * execution. */ public static String formatSeedChain(Randomness... randomnesses) { StringBuilder b = new StringBuilder(); b.append("["); for (int i = 0; i < randomnesses.length; i++) { if (i > 0) b.append(":"); b.append(formatSeed(randomnesses[i].getSeed())); } b.append("]"); return b.toString(); } }
/** * Get an annotated element's {@link Seed} annotation and determine if it's fixed * or not. If it is fixed, return the seeds. Otherwise return <code>randomSeed</code>. */ private long [] seedFromAnnot(AnnotatedElement element, long randomSeed) { Seed seed = element.getAnnotation(Seed.class); String seedChain = seed.value(); if (seedChain.equals("random")) { return new long [] { randomSeed }; } return SeedUtils.parseSeedChain(seedChain); }
private MockBigArrays(PageCacheRecycler recycler, CircuitBreakerService breakerService, boolean checkBreaker) { super(recycler, breakerService, checkBreaker); this.recycler = recycler; this.breakerService = breakerService; long seed; try { seed = SeedUtils.parseSeed(RandomizedContext.current().getRunnerSeedAsString()); } catch (IllegalStateException e) { // rest tests don't run randomized and have no context seed = 0; } random = new Random(seed); }
/** * Augment stack trace of the given exception with seed infos. */ static <T extends Throwable> T augmentStackTrace(T e, Randomness... seeds) { if (seeds.length == 0) { seeds = RandomizedContext.current().getRandomnesses(); } final String seedChain = SeedUtils.formatSeedChain(seeds); final String existingSeed = seedFromThrowable(e); if (existingSeed != null && existingSeed.equals(seedChain)) { return e; } List<StackTraceElement> stack = new ArrayList<StackTraceElement>( Arrays.asList(e.getStackTrace())); stack.add(0, new StackTraceElement(AUGMENTED_SEED_PACKAGE + ".SeedInfo", "seed", seedChain, 0)); e.setStackTrace(stack.toArray(new StackTraceElement [stack.size()])); return e; }
/** * Returns the runner's master seed, formatted. */ public String getRunnerSeedAsString() { checkDisposed(); return SeedUtils.formatSeed(getRunnerSeed()); }
/** * Validate arguments and state. */ private void validate() { if (Strings.emptyToNull(random) == null) { random = Strings.emptyToNull(getProject().getProperty(SYSPROP_RANDOM_SEED())); } if (random == null) { throw new BuildException("Required attribute 'seed' must not be empty. Look at <junit4:pickseed>."); } long[] seeds = SeedUtils.parseSeedChain(random); if (seeds.length < 1) { throw new BuildException("Random seed is required."); } if (values.isEmpty() && !allowUndefined) { throw new BuildException("No values to pick from and allowUndefined=false."); } } }
args[args.length - 1] = SeedUtils.formatSeedChain(runnerRandomness, new Randomness(thisSeed, randomSupplier)); String formattedArguments = String.format(Locale.ROOT, argFormattingTemplate, args);
/** * Returns the runner's master seed, formatted. */ public String getRunnerSeedAsString() { checkDisposed(); return SeedUtils.formatSeed(getRunnerSeed()); }
/** * Execute the task. */ @Override public void execute() throws BuildException { validate(); if (allowUndefined) { values.add(null); } long permutedSeed = SeedUtils.parseSeedChain(random)[0]; permutedSeed ^= new Random(executionId.incrementAndGet()).nextLong(); StringValue pick = RandomPicks.randomFrom(new Random(permutedSeed), values); if (pick != null) { getProject().setProperty(propertyName, pick.toString()); } }
args[args.length - 1] = SeedUtils.formatSeedChain(runnerRandomness, new Randomness(thisSeed, randomSupplier)); String formattedArguments = String.format(Locale.ROOT, argFormattingTemplate, args);
/** * Execute the task. */ @Override public void execute() throws BuildException { validate(); String seedValue = Strings.emptyToNull(getProject().getProperty(propertyName)); if (seedValue == null) { seedValue = SeedUtils.formatSeed(new Random().nextLong()); log("Picking master seed for property '" + propertyName + "': " + seedValue, Project.MSG_VERBOSE); getProject().setProperty(propertyName, seedValue); } else { log("Seed property '" + propertyName + "' already defined: " + seedValue, Project.MSG_INFO); } }