public static short randomShort() { return (short) getRandom().nextInt(); } public static int randomInt() { return getRandom().nextInt(); }
/** * Rarely returns <code>true</code> in about 10% of all calls (regardless of the * {@link #isNightly()} mode). */ public static boolean rarely() { return randomInt(100) >= 90; }
/** * An alias for {@link #randomIntBetween(int, int)}. * * @see #scaledRandomIntBetween(int, int) */ public static int between(int min, int max) { return randomIntBetween(min, max); }
@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);
@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()); } } }
if (min > max) throw new IllegalArgumentException("max must be >= min: " + min + ", " + max); double point = Math.min(1, Math.abs(randomGaussian()) * 0.3) * multiplier(); double range = max - min; int scaled = (int) Math.round(Math.min(point * range, range)); if (isNightly()) { return max - scaled; } else {
/** * Return a random Locale from the available locales on the system. * * <p>Warning: This test assumes the returned array of locales is repeatable from jvm execution * to jvm execution. It _may_ be different from jvm to jvm and as such, it can render * tests execute in a different way.</p> */ public static Locale randomLocale() { Locale[] availableLocales = Locale.getAvailableLocales(); Arrays.sort(availableLocales, new Comparator<Locale>() { public int compare(Locale o1, Locale o2) { return o1.toString().compareTo(o2.toString()); } }); return randomFrom(availableLocales); }
/** * Reverse of {@link #assumeTrue(boolean)}. */ public static void assumeFalse(boolean condition) { assumeTrue(!condition); }
/** * An alias for {@link #randomLongBetween}. */ public static long between(long min, long max) { return randomLongBetween(min, max); }
/** * @deprecated Use {@link #randomAsciiLettersOfLengthBetween} instead. */ @Deprecated public static String randomAsciiOfLengthBetween(int minCodeUnits, int maxCodeUnits) { return randomAsciiLettersOfLengthBetween(minCodeUnits, maxCodeUnits); }
public static void assumeNoException(String msg, Exception e) { RandomizedTest.assumeNoException(msg, e); }
private void randomlyResetClients() throws IOException { // only reset the clients on nightly tests, it causes heavy load... if (RandomizedTest.isNightly() && rarely(random)) { final Collection<NodeAndClient> nodesAndClients = nodes.values(); for (NodeAndClient nodeAndClient : nodesAndClients) { nodeAndClient.resetClient(); } } }
/** * The exact opposite of {@link #rarely()}. */ public static boolean frequently() { return !rarely(); }
if (min > max) throw new IllegalArgumentException("max must be >= min: " + min + ", " + max); double point = Math.min(1, Math.abs(randomGaussian()) * 0.3) * multiplier(); double range = max - min; int scaled = (int) Math.round(Math.min(point * range, range)); if (isNightly()) { return max - scaled; } else {
/** * Return a random Locale from the available locales on the system. * * <p>Warning: This test assumes the returned array of locales is repeatable from jvm execution * to jvm execution. It _may_ be different from jvm to jvm and as such, it can render * tests execute in a different way.</p> */ public static Locale randomLocale() { Locale[] availableLocales = Locale.getAvailableLocales(); Arrays.sort(availableLocales, new Comparator<Locale>() { public int compare(Locale o1, Locale o2) { return o1.toString().compareTo(o2.toString()); } }); return randomFrom(availableLocales); }
/** * Reverse of {@link #assumeTrue(String, boolean)}. */ public static void assumeFalse(String message, boolean condition) { assumeTrue(message, !condition); }
/** * An alias for {@link #randomLongBetween}. */ public static long between(long min, long max) { return randomLongBetween(min, max); }
/** * @deprecated Use {@link #randomAsciiLettersOfLengthBetween} instead. */ @Deprecated public static String randomAsciiOfLengthBetween(int minCodeUnits, int maxCodeUnits) { return randomAsciiLettersOfLengthBetween(minCodeUnits, maxCodeUnits); }
/** Assumes that Mockito/Bytebuddy is available and can be used to mock classes (e.g., fails if Java version is too new). */ public static void assumeWorkingMockito() { // we use reflection here, because we do not have ByteBuddy/Mockito in all modules and the test framework! try { Class.forName("net.bytebuddy.ClassFileVersion").getMethod("ofThisVm").invoke(null); } catch (InvocationTargetException e) { RandomizedTest.assumeNoException("SOLR-11606: ByteBuddy used by Mockito is not working with this JVM version.", e.getTargetException()); } catch (ReflectiveOperationException e) { fail("ByteBuddy and Mockito are not available on classpath: " + e.toString()); } }
public static int randomInt() { return getRandom().nextInt(); } public static float randomFloat() { return getRandom().nextFloat(); }