com.carrotsearch.randomizedtesting.RandomizedContext Java Examples

The following examples show how to use com.carrotsearch.randomizedtesting.RandomizedContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractXContentTestCaseTests.java    From crate with Apache License 2.0 6 votes vote down vote up
public void testInsertRandomFieldsAndShuffle() throws Exception {
    XContentBuilder builder = XContentFactory.jsonBuilder();
    builder.startObject();
    {
        builder.field("field", 1);
    }
    builder.endObject();
    BytesReference insertRandomFieldsAndShuffle = RandomizedContext.current().runWithPrivateRandomness(1,
            () -> AbstractXContentTestCase.insertRandomFieldsAndShuffle(
                    BytesReference.bytes(builder),
                    XContentType.JSON,
                    true,
                    new String[] {},
                    null,
                    this::createParser));
    try (XContentParser parser = createParser(XContentType.JSON.xContent(), insertRandomFieldsAndShuffle)) {
        Map<String, Object> mapOrdered = parser.mapOrdered();
        assertThat(mapOrdered.size(), equalTo(2));
        assertThat(mapOrdered.keySet().iterator().next(), not(equalTo("field")));
    }
}
 
Example #2
Source File: CoordinatorTests.java    From crate with Apache License 2.0 6 votes vote down vote up
public void testRepeatableTests() throws Exception {
    final Callable<Long> test = () -> {
        resetNodeIndexBeforeEachTest();
        final Cluster cluster = new Cluster(randomIntBetween(1, 5));
        cluster.runRandomly();
        final long afterRunRandomly = value(cluster.getAnyNode().getLastAppliedClusterState());
        cluster.stabilise();
        final long afterStabilisation = value(cluster.getAnyNode().getLastAppliedClusterState());
        return afterRunRandomly ^ afterStabilisation;
    };
    final long seed = randomLong();
    logger.info("First run with seed [{}]", seed);
    final long result1 = RandomizedContext.current().runWithPrivateRandomness(seed, test);
    logger.info("Second run with seed [{}]", seed);
    final long result2 = RandomizedContext.current().runWithPrivateRandomness(seed, test);
    assertEquals(result1, result2);
}
 
Example #3
Source File: SolrTestCaseJ4.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
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();
    if (log.isInfoEnabled()) {
      log.info("Randomized ssl ({}) and clientAuth ({}) via: {}",
          result.isSSLMode(), result.isClientAuthMode(), sslRandomizer.debug);
    }
    return result;
  }
 
Example #4
Source File: RunListenerPrintReproduceInfo.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void testRunStarted(Description description) throws Exception {
  suiteFailed = false;
  testFailed = false;
  scope = LifecycleScope.SUITE;

  Class<?> targetClass = RandomizedContext.current().getTargetClass();
  suppressReproduceLine = targetClass.isAnnotationPresent(LuceneTestCase.SuppressReproduceLine.class);
  testClassesRun.add(targetClass.getSimpleName());
}
 
Example #5
Source File: ESIntegTestCase.java    From crate with Apache License 2.0 5 votes vote down vote up
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);
        }
    });
}
 
Example #6
Source File: MockBigArrays.java    From crate with Apache License 2.0 5 votes vote down vote up
private MockBigArrays(PageCacheRecycler recycler, CircuitBreakerService breakerService, boolean checkBreaker) {
    super(recycler, breakerService, CircuitBreaker.REQUEST, 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);
}
 
Example #7
Source File: TestRuleTemporaryFilesCleanup.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
Path getPerTestClassTempDir() {
  if (tempDirBase == null) {
    RandomizedContext ctx = RandomizedContext.current();
    Class<?> clazz = ctx.getTargetClass();
    String prefix = clazz.getName();
    prefix = prefix.replaceFirst("^org.apache.lucene.", "lucene.");
    prefix = prefix.replaceFirst("^org.apache.solr.", "solr.");

    int attempt = 0;
    Path f;
    boolean success = false;
    do {
      if (attempt++ >= TEMP_NAME_RETRY_THRESHOLD) {
        throw new RuntimeException(
            "Failed to get a temporary name too many times, check your temp directory and consider manually cleaning it: "
              + javaTempDir.toAbsolutePath());            
      }
      f = javaTempDir.resolve(prefix + "_" + ctx.getRunnerSeedAsString() 
            + "-" + String.format(Locale.ENGLISH, "%03d", attempt));
      try {
        Files.createDirectory(f);
        success = true;
      } catch (IOException ignore) {}
    } while (!success);

    tempDirBase = f;
    registerToRemoveAfterSuite(tempDirBase);
  }
  return tempDirBase;
}
 
Example #8
Source File: TestCodecLoadingDeadlock.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeadlock() throws Exception {
  LuceneTestCase.assumeFalse("This test fails on UNIX with Turkish default locale (https://issues.apache.org/jira/browse/LUCENE-6036)",
    new Locale("tr").getLanguage().equals(Locale.getDefault().getLanguage()));

  // pick random codec names for stress test in separate process:
  final Random rnd = RandomizedContext.current().getRandom();
  Set<String> avail;
  final String codecName = new ArrayList<>(avail = Codec.availableCodecs())
      .get(rnd.nextInt(avail.size()));
  final String pfName = new ArrayList<>(avail = PostingsFormat.availablePostingsFormats())
      .get(rnd.nextInt(avail.size()));
  final String dvfName = new ArrayList<>(avail = DocValuesFormat.availableDocValuesFormats())
      .get(rnd.nextInt(avail.size()));

  System.out.println(String.format(Locale.ROOT,
      "codec: %s, pf: %s, dvf: %s", codecName, pfName, dvfName));

  // Fork a separate JVM to reinitialize classes.
  final Process p = new ProcessBuilder(
    Paths.get(System.getProperty("java.home"), "bin", "java").toString(),
    "-cp",
    System.getProperty("java.class.path"),
    getClass().getName(),
    codecName,
    pfName,
    dvfName
  ).inheritIO().start();
  if (p.waitFor(MAX_TIME_SECONDS * 2, TimeUnit.SECONDS)) {
    assertEquals("Process died abnormally?", 0, p.waitFor());
  } else {
    p.destroyForcibly().waitFor();
    fail("Process did not exit after 60 secs?");
  }
}
 
Example #9
Source File: SolrTestCaseJ4.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public static void initClassLogLevels() {
  @SuppressWarnings({"rawtypes"})
  Class currentClass = RandomizedContext.current().getTargetClass();
  @SuppressWarnings({"unchecked"})
  LogLevel annotation = (LogLevel) currentClass.getAnnotation(LogLevel.class);
  if (annotation == null) {
    return;
  }
  Map<String, Level> previousLevels = LogLevel.Configurer.setLevels(annotation.value());
  savedClassLogLevels.putAll(previousLevels);
}
 
Example #10
Source File: SolrTestCaseJ4.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #11
Source File: ReproduceInfoPrinterRunListener.java    From t-digest with Apache License 2.0 5 votes vote down vote up
private void printReproLine() {
    final StringBuilder b = new StringBuilder();
    b.append("NOTE: reproduce with: mvn test -Dtests.seed=").append(RandomizedContext.current().getRunnerSeedAsString());
    if (System.getProperty("runSlowTests") != null) {
        b.append(" -DrunSlowTests=").append(System.getProperty("runSlowTests"));
    }
    b.append(" -Dtests.class=").append(RandomizedContext.current().getTargetClass().getName());
    System.out.println(b.toString());
}
 
Example #12
Source File: DataTypeTesting.java    From crate with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T> Supplier<T> getDataGenerator(DataType<T> type) {
    Random random = RandomizedContext.current().getRandom();
    switch (type.id()) {
        case ByteType.ID:
            return () -> (T) (Byte) (byte) random.nextInt(Byte.MAX_VALUE);
        case BooleanType.ID:
            return () -> (T) (Boolean) random.nextBoolean();

        case StringType.ID:
            return () -> (T) RandomizedTest.randomAsciiLettersOfLength(random.nextInt(10));

        case IpType.ID:
            return () -> {
                if (random.nextBoolean()) {
                    return (T) randomIPv4Address(random);
                } else {
                    return (T) randomIPv6Address(random);
                }
            };

        case DoubleType.ID:
            return () -> (T) (Double) random.nextDouble();

        case FloatType.ID:
            return () -> (T) (Float) random.nextFloat();

        case ShortType.ID:
            return () -> (T) (Short) (short) random.nextInt(Short.MAX_VALUE);

        case IntegerType.ID:
            return () -> (T) (Integer) random.nextInt();

        case LongType.ID:
        case TimestampType.ID_WITH_TZ:
        case TimestampType.ID_WITHOUT_TZ:
            return () -> (T) (Long) random.nextLong();

        case GeoPointType.ID:
            return () -> (T) new PointImpl(
                BiasedNumbers.randomDoubleBetween(random, -180, 180),
                BiasedNumbers.randomDoubleBetween(random, -90, 90),
                JtsSpatialContext.GEO
            );

        case GeoShapeType.ID:
            return () -> {
                // Can't use immutable Collections.singletonMap; insert-analyzer mutates the map
                Map<String, Object> geoShape = new HashMap<>(2);
                geoShape.put("coordinates", Arrays.asList(10.2d, 32.2d));
                geoShape.put("type", "Point");
                return (T) geoShape;
            };

        case ObjectType.ID:
            Supplier<?> innerValueGenerator = getDataGenerator(randomType());
            return () -> {
                // Can't use immutable Collections.singletonMap; insert-analyzer mutates the map
                HashMap<String, Object> map = new HashMap<>();
                map.put("x", innerValueGenerator.get());
                return (T) map;
            };
        case IntervalType.ID:
            return () -> {
                return (T) new Period().withSeconds(RandomNumbers.randomIntBetween(random, 0, Integer.MAX_VALUE));
            };

    }

    throw new AssertionError("No data generator for type " + type.getName());
}
 
Example #13
Source File: GeoTestUtil.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
/** Keep it simple, we don't need to take arbitrary Random for geo tests */
private static Random random() {
 return RandomizedContext.current().getRandom();
}
 
Example #14
Source File: DataTypeTesting.java    From crate with Apache License 2.0 4 votes vote down vote up
public static DataType<?> randomType() {
    return RandomPicks.randomFrom(RandomizedContext.current().getRandom(), ALL_TYPES_EXCEPT_ARRAYS);
}
 
Example #15
Source File: SQLTransportExecutor.java    From crate with Apache License 2.0 4 votes vote down vote up
private SQLResponse executeTransportOrJdbc(TestExecutionConfig config,
                                           String stmt,
                                           @Nullable Object[] args,
                                           TimeValue timeout) {
    String pgUrl = clientProvider.pgUrl();
    Random random = RandomizedContext.current().getRandom();

    List<String> sessionList = new ArrayList<>();
    sessionList.add("set search_path to "
                    + StreamSupport.stream(searchPath.spliterator(), false)
                        // explicitly setting the pg catalog schema will make it the current schema so attempts to
                        // create un-fully-qualified relations will fail. we filter it out and will implicitly
                        // remain the first in the search path.
                        .filter(s -> !s.equals(PgCatalogSchemaInfo.NAME))
                        .collect(Collectors.joining(", "))
    );

    if (!config.isHashJoinEnabled()) {
        sessionList.add("set enable_hashjoin=false");
        LOGGER.trace("Executing with enable_hashjoin=false: {}", stmt);
    }

    if (pgUrl != null && config.isJdbcEnabled()) {
        LOGGER.trace("Executing with pgJDBC: {}", stmt);
        return executeWithPg(
            stmt,
            args,
            pgUrl,
            random,
            sessionList);
    }
    try {
        if (!sessionList.isEmpty()) {
            try (Session session = newSession()) {
                sessionList.forEach((setting) -> exec(setting, session));
                return execute(stmt, args, session).actionGet(timeout);
            }
        }
        return execute(stmt, args).actionGet(timeout);
    } catch (ElasticsearchTimeoutException e) {
        LOGGER.error("Timeout on SQL statement: {} {}", stmt, e);
        throw e;
    }
}
 
Example #16
Source File: SolrTestCaseJ4.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
/**
 * Sets various sys props related to user specified or randomized choices regarding the types 
 * of numerics that should be used in tests.
 *
 * @see #NUMERIC_DOCVALUES_SYSPROP
 * @see #NUMERIC_POINTS_SYSPROP
 * @see #clearNumericTypesProperties
 * @lucene.experimental
 * @lucene.internal
 */
@SuppressWarnings({"rawtypes"})
private static void randomizeNumericTypesProperties() {

  final boolean useDV = random().nextBoolean();
  System.setProperty(NUMERIC_DOCVALUES_SYSPROP, ""+useDV);
  
  // consume a consistent amount of random data even if sysprop/annotation is set
  final boolean randUsePoints = 0 != random().nextInt(5);  // 80% likelihood

  final String usePointsStr = System.getProperty(USE_NUMERIC_POINTS_SYSPROP);
  final boolean usePoints = (null == usePointsStr) ? randUsePoints : Boolean.parseBoolean(usePointsStr);
  
  if (RandomizedContext.current().getTargetClass().isAnnotationPresent(SolrTestCaseJ4.SuppressPointFields.class)
      || (! usePoints)) {
    log.info("Using TrieFields (NUMERIC_POINTS_SYSPROP=false) w/NUMERIC_DOCVALUES_SYSPROP={}", useDV);
    
    org.apache.solr.schema.PointField.TEST_HACK_IGNORE_USELESS_TRIEFIELD_ARGS = false;
    private_RANDOMIZED_NUMERIC_FIELDTYPES.put(Integer.class, "solr.TrieIntField");
    private_RANDOMIZED_NUMERIC_FIELDTYPES.put(Float.class, "solr.TrieFloatField");
    private_RANDOMIZED_NUMERIC_FIELDTYPES.put(Long.class, "solr.TrieLongField");
    private_RANDOMIZED_NUMERIC_FIELDTYPES.put(Double.class, "solr.TrieDoubleField");
    private_RANDOMIZED_NUMERIC_FIELDTYPES.put(Date.class, "solr.TrieDateField");
    private_RANDOMIZED_NUMERIC_FIELDTYPES.put(Enum.class, "solr.EnumField");
    
    System.setProperty(NUMERIC_POINTS_SYSPROP, "false");
  } else {
    log.info("Using PointFields (NUMERIC_POINTS_SYSPROP=true) w/NUMERIC_DOCVALUES_SYSPROP={}", useDV);

    org.apache.solr.schema.PointField.TEST_HACK_IGNORE_USELESS_TRIEFIELD_ARGS = true;
    private_RANDOMIZED_NUMERIC_FIELDTYPES.put(Integer.class, "solr.IntPointField");
    private_RANDOMIZED_NUMERIC_FIELDTYPES.put(Float.class, "solr.FloatPointField");
    private_RANDOMIZED_NUMERIC_FIELDTYPES.put(Long.class, "solr.LongPointField");
    private_RANDOMIZED_NUMERIC_FIELDTYPES.put(Double.class, "solr.DoublePointField");
    private_RANDOMIZED_NUMERIC_FIELDTYPES.put(Date.class, "solr.DatePointField");
    private_RANDOMIZED_NUMERIC_FIELDTYPES.put(Enum.class, "solr.EnumFieldType");
    
    System.setProperty(NUMERIC_POINTS_SYSPROP, "true");
  }
  for (Map.Entry<Class,String> entry : RANDOMIZED_NUMERIC_FIELDTYPES.entrySet()) {
    System.setProperty("solr.tests." + entry.getKey().getSimpleName() + "FieldType",
                       entry.getValue());

  }
}
 
Example #17
Source File: TestRuleTemporaryFilesCleanup.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
protected void afterAlways(List<Throwable> errors) throws Throwable {
  // Drain cleanup queue and clear it.
  final Path [] everything;
  final String tempDirBasePath;
  synchronized (cleanupQueue) {
    tempDirBasePath = (tempDirBase != null ? tempDirBase.toAbsolutePath().toString() : null);
    tempDirBase = null;

    Collections.reverse(cleanupQueue);
    everything = new Path [cleanupQueue.size()];
    cleanupQueue.toArray(everything);
    cleanupQueue.clear();
  }

  // Only check and throw an IOException on un-removable files if the test
  // was successful. Otherwise just report the path of temporary files
  // and leave them there.
  if (failureMarker.wasSuccessful()) {

    try {
      IOUtils.rm(everything);
    } catch (IOException e) {
      Class<?> suiteClass = RandomizedContext.current().getTargetClass();
      if (suiteClass.isAnnotationPresent(SuppressTempFileChecks.class)) {
        System.err.println("WARNING: Leftover undeleted temporary files (bugUrl: "
            + suiteClass.getAnnotation(SuppressTempFileChecks.class).bugUrl() + "): "
            + e.getMessage());
        return;
      }
      throw e;
    }
    if (fileSystem != FileSystems.getDefault()) {
      fileSystem.close();
    }
  } else {
    if (tempDirBasePath != null) {
      System.err.println("NOTE: leaving temporary files on disk at: " + tempDirBasePath);
    }
  }
}
 
Example #18
Source File: TestRuleTemporaryFilesCleanup.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
private FileSystem initializeFileSystem() {
  Class<?> targetClass = RandomizedContext.current().getTargetClass();
  Set<String> avoid = new HashSet<>();
  if (targetClass.isAnnotationPresent(SuppressFileSystems.class)) {
    SuppressFileSystems a = targetClass.getAnnotation(SuppressFileSystems.class);
    avoid.addAll(Arrays.asList(a.value()));
  }
  FileSystem fs = FileSystems.getDefault();
  if (LuceneTestCase.VERBOSE && allowed(avoid, VerboseFS.class)) {
    fs = new VerboseFS(fs, new TestRuleSetupAndRestoreClassEnv.ThreadNameFixingPrintStreamInfoStream(System.out)).getFileSystem(null);
  }
  
  Random random = RandomizedContext.current().getRandom();
  
  // speed up tests by omitting actual fsync calls to the hardware most of the time.
  if (targetClass.isAnnotationPresent(SuppressFsync.class) || random.nextInt(100) > 0) {
    if (allowed(avoid, DisableFsyncFS.class)) {
      fs = new DisableFsyncFS(fs).getFileSystem(null);
    }
  }
  
  // impacts test reproducibility across platforms.
  if (random.nextInt(100) > 0) {
    if (allowed(avoid, ShuffleFS.class)) {
      fs = new ShuffleFS(fs, random.nextLong()).getFileSystem(null);
    }
  }
  
  // otherwise, wrap with mockfilesystems for additional checks. some 
  // of these have side effects (e.g. concurrency) so it doesn't always happen.
  if (random.nextInt(10) > 0) {
    if (allowed(avoid, LeakFS.class)) {
      fs = new LeakFS(fs).getFileSystem(null);
    }
    if (allowed(avoid, HandleLimitFS.class)) {
      fs = new HandleLimitFS(fs, MAX_OPEN_FILES).getFileSystem(null);
    }
    // windows is currently slow
    if (random.nextInt(10) == 0) {
      // don't try to emulate windows on windows: they don't get along
      if (!Constants.WINDOWS && allowed(avoid, WindowsFS.class)) {
        fs = new WindowsFS(fs).getFileSystem(null);
      }
    }
    if (allowed(avoid, ExtrasFS.class)) {
      fs = new ExtrasFS(fs, random.nextInt(4) == 0, random.nextBoolean()).getFileSystem(null);
    }
  }
  if (LuceneTestCase.VERBOSE) {
    System.out.println("filesystem: " + fs.provider());
  }

  return fs.provider().getFileSystem(URI.create("file:///"));
}
 
Example #19
Source File: RunListenerPrintReproduceInfo.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
private void reportAdditionalFailureInfo(final String testName) {
  if (suppressReproduceLine) {
    return;
  }
  if (TEST_LINE_DOCS_FILE.endsWith(JENKINS_LARGE_LINE_DOCS_FILE)) {
    System.err.println("NOTE: download the large Jenkins line-docs file by running " +
      "'ant get-jenkins-line-docs' in the lucene directory.");
  }

  final StringBuilder b = new StringBuilder();
  b.append("NOTE: reproduce with: ant test ");

  // Test case, method, seed.
  addVmOpt(b, "testcase", RandomizedContext.current().getTargetClass().getSimpleName());
  addVmOpt(b, "tests.method", testName);
  addVmOpt(b, "tests.seed", RandomizedContext.current().getRunnerSeedAsString());

  // Test groups and multipliers.
  if (RANDOM_MULTIPLIER > 1) addVmOpt(b, "tests.multiplier", RANDOM_MULTIPLIER);
  if (TEST_NIGHTLY) addVmOpt(b, SYSPROP_NIGHTLY, TEST_NIGHTLY);
  if (TEST_WEEKLY) addVmOpt(b, SYSPROP_WEEKLY, TEST_WEEKLY);
  if (TEST_SLOW) addVmOpt(b, SYSPROP_SLOW, TEST_SLOW);
  if (TEST_MONSTER) addVmOpt(b, SYSPROP_MONSTER, TEST_MONSTER);
  if (TEST_AWAITSFIX) addVmOpt(b, SYSPROP_AWAITSFIX, TEST_AWAITSFIX);
  if (TEST_BADAPPLES) addVmOpt(b, SYSPROP_BADAPPLES, TEST_BADAPPLES);

  // Codec, postings, directories.
  if (!TEST_CODEC.equals("random")) addVmOpt(b, "tests.codec", TEST_CODEC);
  if (!TEST_POSTINGSFORMAT.equals("random")) addVmOpt(b, "tests.postingsformat", TEST_POSTINGSFORMAT);
  if (!TEST_DOCVALUESFORMAT.equals("random")) addVmOpt(b, "tests.docvaluesformat", TEST_DOCVALUESFORMAT);
  if (!TEST_DIRECTORY.equals("random")) addVmOpt(b, "tests.directory", TEST_DIRECTORY);

  // Environment.
  if (!TEST_LINE_DOCS_FILE.equals(DEFAULT_LINE_DOCS_FILE)) addVmOpt(b, "tests.linedocsfile", TEST_LINE_DOCS_FILE);
  if (classEnvRule != null && classEnvRule.isInitialized()) {
    addVmOpt(b, "tests.locale", classEnvRule.locale.toLanguageTag());
    if (classEnvRule.timeZone != null) {
      addVmOpt(b, "tests.timezone", classEnvRule.timeZone.getID());
    }
  }

  if (LuceneTestCase.assertsAreEnabled) {
    addVmOpt(b, "tests.asserts", "true");
  } else {
    addVmOpt(b, "tests.asserts", "false");
  }

  addVmOpt(b, "tests.file.encoding", System.getProperty("file.encoding"));

  System.err.println(b.toString());
}
 
Example #20
Source File: ShapeTestUtil.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
/** Keep it simple, we don't need to take arbitrary Random for geo tests */
private static Random random() {
  return RandomizedContext.current().getRandom();
}
 
Example #21
Source File: LuceneTestCase.java    From lucene-solr with Apache License 2.0 2 votes vote down vote up
/**
 * 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);
}
 
Example #22
Source File: LuceneTestCase.java    From lucene-solr with Apache License 2.0 2 votes vote down vote up
/**
 * 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);
}
 
Example #23
Source File: LuceneTestCase.java    From lucene-solr with Apache License 2.0 2 votes vote down vote up
/**
 * Access to the current {@link RandomizedContext}'s Random instance. It is safe to use
 * this method from multiple threads, etc., but it should be called while within a runner's
 * scope (so no static initializers). The returned {@link Random} instance will be 
 * <b>different</b> when this method is called inside a {@link BeforeClass} hook (static 
 * suite scope) and within {@link Before}/ {@link After} hooks or test methods. 
 * 
 * <p>The returned instance must not be shared with other threads or cross a single scope's 
 * boundary. For example, a {@link Random} acquired within a test method shouldn't be reused
 * for another test case.
 * 
 * <p>There is an overhead connected with getting the {@link Random} for a particular context
 * and thread. It is better to cache the {@link Random} locally if tight loops with multiple
 * invocations are present or create a derivative local {@link Random} for millions of calls 
 * like this:
 * <pre>
 * Random random = new Random(random().nextLong());
 * // tight loop with many invocations. 
 * </pre>
 */
public static Random random() {
  return RandomizedContext.current().getRandom();
}