public static int between(int min, int max) { return RandomNumbers.randomIntBetween(RandomizedContext.current().getRandom(), min, max); }
/** * Ensures we're running with an initialized {@link RandomizedContext}. */ private static void checkContext() { // Will throw an exception if not available. RandomizedContext.current(); } }
/** * Shortcut for {@link RandomizedContext#current()}. */ public static RandomizedContext getContext() { return RandomizedContext.current(); }
/** * Shortcut for {@link RandomizedContext#current()}. */ public static RandomizedContext getContext() { return RandomizedContext.current(); }
/** * Ensures we're running with an initialized {@link RandomizedContext}. */ private static void checkContext() { // Will throw an exception if not available. RandomizedContext.current(); } }
private TestCluster buildWithPrivateContext(final Scope scope, final long seed) throws Exception { return RandomizedContext.current().runWithPrivateRandomness(seed, new Callable<TestCluster>() { @Override public TestCluster call() throws Exception { return buildTestCluster(scope, seed); } }); }
/** * 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 RandomizedContext.current().closeAtEnd(resource, LifecycleScope.TEST); }
/** * 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 RandomizedContext.current().closeAtEnd(resource, LifecycleScope.SUITE); }
@Test public void getContextByHand() { RandomizedContext context = RandomizedContext.current(); Random rnd = context.getRandom(); System.out.println("Random, next int: " + rnd.nextInt()); }
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); }
public static void initClassLogLevels() { Class currentClass = RandomizedContext.current().getTargetClass(); LogLevel annotation = (LogLevel) currentClass.getAnnotation(LogLevel.class); if (annotation == null) { return; } Map<String, Level> previousLevels = LogLevel.Configurer.setLevels(annotation.value()); savedClassLogLevels.putAll(previousLevels); }
@BeforeClass public static void printMasterContext() { System.out.println("# Static context (@BeforeClass)"); System.out.println(getContext().getRunnerSeedAsString()); System.out.println(RandomizedContext.current().getRandomness()); }
public static int between(int min, int max) { return RandomNumbers.randomIntBetween(RandomizedContext.current().getRandom(), min, max); }
@Test public void printContext() { System.out.println("# Test context (@Test)"); System.out.println(getContext().getRunnerSeedAsString()); System.out.println(RandomizedContext.current().getRandomness()); }
@Before public void initMethodLogLevels() { Method method = RandomizedContext.current().getTargetMethod(); LogLevel annotation = method.getAnnotation(LogLevel.class); if (annotation == null) { return; } Map<String, Level> previousLevels = LogLevel.Configurer.setLevels(annotation.value()); savedMethodLogLevels.putAll(previousLevels); }
@Override public void evaluate() throws Throwable { Class<?> testClass; try { testClass = RandomizedContext.current().getTargetClass(); } catch (Throwable t) { testClass = description.getTestClass(); } validate(testClass); base.evaluate(); } };
@Override public void evaluate() throws Throwable { Class<?> testClass; try { testClass = RandomizedContext.current().getTargetClass(); } catch (Throwable t) { testClass = description.getTestClass(); } validate(testClass); base.evaluate(); } };
@Test public void nightlyOnlyWithAssume() throws Exception { // Only run if Nightly test group is explicitly enabled using -Dtests.nightly=true Assume.assumeTrue(RandomizedContext.current().getGroupEvaluator().isGroupEnabled(Nightly.class)); }
private static SSLTestConfig buildSSLConfig() { SSLRandomizer sslRandomizer = SSLRandomizer.getSSLRandomizerForClass(RandomizedContext.current().getTargetClass()); if (Constants.MAC_OS_X) { // see SOLR-9039 // If a solution is found to remove this, please make sure to also update // TestMiniSolrCloudClusterSSL.testSslAndClientAuth as well. sslRandomizer = new SSLRandomizer(sslRandomizer.ssl, 0.0D, (sslRandomizer.debug + " w/ MAC_OS_X supressed clientAuth")); } SSLTestConfig result = sslRandomizer.createSSLTestConfig(); log.info("Randomized ssl ({}) and clientAuth ({}) via: {}", result.isSSLMode(), result.isClientAuthMode(), sslRandomizer.debug); return result; }
protected void startNode(long seed) throws Exception { ElassandraDaemon.instance.node(RandomizedContext.current().runWithPrivateRandomness(seed, this::newNode)); // we must wait for the node to actually be up and running. otherwise the node might have started, // elected itself master but might not yet have removed the // SERVICE_UNAVAILABLE/1/state not recovered / initialized block ClusterAdminClient clusterAdminClient = client().admin().cluster(); ClusterHealthRequestBuilder builder = clusterAdminClient.prepareHealth(); ClusterHealthResponse clusterHealthResponse = builder.setWaitForGreenStatus().get(); assertFalse(clusterHealthResponse.isTimedOut()); }