public static int between(int min, int max) { return RandomNumbers.randomIntBetween(RandomizedContext.current().getRandom(), min, max); }
/** * Append a single VM option. */ @Override public ReproduceErrorMessageBuilder appendOpt(String sysPropName, String value) { if (sysPropName.equals(SYSPROP_ITERATIONS())) { // we don't want the iters to be in there! return this; } if (sysPropName.equals(SYSPROP_TESTMETHOD())) { //don't print out the test method, we print it ourselves in appendAllOpts //without filtering out the parameters (needed for REST tests) return this; } if (sysPropName.equals(SYSPROP_PREFIX())) { // we always use the default prefix return this; } if (!Strings.isBlank(value)) { if (value.indexOf(' ') >= 0) { return super.appendOpt(sysPropName, '"' + value + '"'); } return super.appendOpt(sysPropName, value); } return this; }
@Override public ReproduceErrorMessageBuilder appendAllOpts(Description description) { super.appendAllOpts(description); if (description.getMethodName() != null) { //prints out the raw method description instead of methodName(description) which filters out the parameters super.appendOpt(SYSPROP_TESTMETHOD(), "\"" + description.getMethodName() + "\""); } List<String> properties = new ArrayList<>(); scanProperties(description.getTestClass(), properties); appendProperties(properties.toArray(new String[properties.size()])); return appendESProperties(); }
/** * Returns the runner's master seed, formatted. */ public String getRunnerSeedAsString() { checkDisposed(); return SeedUtils.formatSeed(getRunnerSeed()); }
/** * Shortcut for {@link RandomizedContext#getRandom()}. Even though this method * is static, it returns per-thread {@link Random} instance, so no race conditions * can occur. * * <p>It is recommended that specific methods are used to pick random values. */ public static Random getRandom() { return getContext().getRandom(); }
public Randomness(Thread owner, RandomSupplier supplier, long seed, SeedDecorator... decorators) { this.seed = seed; this.decorators = decorators; this.supplier = supplier; Random delegate = supplier.get(decorate(seed, decorators)); if (AssertingRandom.isVerifying()) { this.random = new AssertingRandom(owner, delegate); } else { this.random = delegate; } }
/** * Return <code>true</code> if {@link Nightly} test group is explicitly enabled. * * @see RandomizedContext#getGroupEvaluator() * @see GroupEvaluator#isGroupEnabled(Class) */ public boolean isNightly() { checkDisposed(); return getGroupEvaluator().isGroupEnabled(Nightly.class); }
/** * Registers a {@link Closeable} resource that should be closed after the suite * completes. * * @return <code>resource</code> (for call chaining). */ public static <T extends Closeable> T closeAfterSuite(T resource) { return getContext().closeAtEnd(resource, LifecycleScope.SUITE); }
@Test public void test_subdirs_very_deep_tree() throws Exception { long subdirs = randomLongBetween(30, 100); newDir = newDir.resolve(i + "_" + randomAsciiLettersOfLengthBetween(2, 5)); Files.createDirectory(newDir);
/** * A shorthand for calling {@link #getRandomness()} and then {@link Randomness#getRandom()}. */ public Random getRandom() { return getRandomness().getRandom(); }
public ReproduceErrorMessageBuilder appendTestGroupOptions(RandomizedContext ctx) { if (ctx != null) { ctx.getGroupEvaluator().appendGroupFilteringOptions(this); } return this; }
@Test public void test_enable_raw() throws Exception { Fs.Builder builder = startCrawlerDefinition(); if (rarely()) { // Sometimes we explicitly set it but this is also the default value builder.setRawMetadata(true); } startCrawler(getCrawlerName(), builder.build(), endCrawlerDefinition(getCrawlerName()), null); ESSearchResponse searchResponse = countTestHelper(new ESSearchRequest().withIndex(getCrawlerName()), 1L, null); for (ESSearchHit hit : searchResponse.getHits()) { assertThat(extractFromPath(hit.getSourceAsMap(), Doc.FIELD_NAMES.META).get("raw"), notNullValue()); } } }
/** * Returns true if {@link Nightly} test group is enabled. * * @see Nightly */ public static boolean isNightly() { return getContext().isNightly(); }
long nbDocs = randomLongBetween(10, 100); long nbFolders = randomLongBetween(1, 10);
@BeforeClass public static void setTimeZone() { String testTimeZone = System.getProperty("tests.timezone", RANDOM); TimeZone timeZone = testTimeZone.equals(RANDOM) ? randomTimeZone() : TimeZone.getTimeZone(testTimeZone); staticLogger.debug("Running test suite with TimeZone [{}]/[{}]", timeZone.getID(), timeZone.getDisplayName()); TimeZone.setDefault(timeZone); }
@BeforeClass public static void setLocale() { String testLocale = System.getProperty("tests.locale", RANDOM); Locale locale = testLocale.equals(RANDOM) ? randomLocale() : new Locale.Builder().setLanguageTag(testLocale).build(); staticLogger.debug("Running test suite with Locale [{}]", locale); Locale.setDefault(locale); }
/** * Returns the runner's master seed, formatted. */ public String getRunnerSeedAsString() { checkDisposed(); return SeedUtils.formatSeed(getRunnerSeed()); }
public Randomness(Thread owner, RandomSupplier supplier, long seed, SeedDecorator... decorators) { this.seed = seed; this.decorators = decorators; this.supplier = supplier; Random delegate = supplier.get(decorate(seed, decorators)); if (AssertingRandom.isVerifying()) { this.random = new AssertingRandom(owner, delegate); } else { this.random = delegate; } }
/** * Registers a {@link Closeable} resource that should be closed after the test * completes. * * @return <code>resource</code> (for call chaining). */ public <T extends Closeable> T closeAfterTest(T resource) { return getContext().closeAtEnd(resource, LifecycleScope.TEST); }