当前位置: 首页>>代码示例>>Java>>正文


Java RandomPicks类代码示例

本文整理汇总了Java中com.carrotsearch.randomizedtesting.generators.RandomPicks的典型用法代码示例。如果您正苦于以下问题:Java RandomPicks类的具体用法?Java RandomPicks怎么用?Java RandomPicks使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


RandomPicks类属于com.carrotsearch.randomizedtesting.generators包,在下文中一共展示了RandomPicks类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setRandomIndexTranslogSettings

import com.carrotsearch.randomizedtesting.generators.RandomPicks; //导入依赖的package包/类
private static Settings.Builder setRandomIndexTranslogSettings(Random random, Settings.Builder builder) {
    if (random.nextBoolean()) {
        builder.put(IndexSettings.INDEX_TRANSLOG_FLUSH_THRESHOLD_SIZE_SETTING.getKey(), new ByteSizeValue(RandomNumbers.randomIntBetween(random, 1, 300), ByteSizeUnit.MB));
    }
    if (random.nextBoolean()) {
        builder.put(IndexSettings.INDEX_TRANSLOG_FLUSH_THRESHOLD_SIZE_SETTING.getKey(), new ByteSizeValue(1, ByteSizeUnit.PB)); // just don't flush
    }
    if (random.nextBoolean()) {
        builder.put(IndexSettings.INDEX_TRANSLOG_DURABILITY_SETTING.getKey(), RandomPicks.randomFrom(random, Translog.Durability.values()));
    }

    if (random.nextBoolean()) {
        builder.put(IndexSettings.INDEX_TRANSLOG_SYNC_INTERVAL_SETTING.getKey(), RandomNumbers.randomIntBetween(random, 100, 5000), TimeUnit.MILLISECONDS);
    }

    return builder;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:ESIntegTestCase.java

示例2: RandomizingClient

import com.carrotsearch.randomizedtesting.generators.RandomPicks; //导入依赖的package包/类
public RandomizingClient(Client client, Random random) {
    super(client);
    // we don't use the QUERY_AND_FETCH types that break quite a lot of tests
    // given that they return `size*num_shards` hits instead of `size`
    defaultSearchType = RandomPicks.randomFrom(random, Arrays.asList(
            SearchType.DFS_QUERY_THEN_FETCH,
            SearchType.QUERY_THEN_FETCH));
    if (random.nextInt(10) == 0) {
        defaultPreference = RandomPicks.randomFrom(random, EnumSet.of(Preference.PRIMARY_FIRST, Preference.LOCAL)).type();
    } else if (random.nextInt(10) == 0) {
        String s = TestUtil.randomRealisticUnicodeString(random, 1, 10);
        defaultPreference = s.startsWith("_") ? null : s; // '_' is a reserved character
    } else {
        defaultPreference = null;
    }
    this.batchedReduceSize = 2 + random.nextInt(10);

}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:RandomizingClient.java

示例3: doCreateTestQueryBuilder

import com.carrotsearch.randomizedtesting.generators.RandomPicks; //导入依赖的package包/类
/**
 * @return a {@link HasChildQueryBuilder} with random values all over the place
 */
@Override
protected HasChildQueryBuilder doCreateTestQueryBuilder() {
    int min = randomIntBetween(0, Integer.MAX_VALUE / 2);
    int max = randomIntBetween(min, Integer.MAX_VALUE);

    QueryBuilder innerQueryBuilder = RandomQueryBuilder.createQuery(random());
    if (randomBoolean()) {
        requiresRewrite = true;
        innerQueryBuilder = new WrapperQueryBuilder(innerQueryBuilder.toString());
    }

    HasChildQueryBuilder hqb = new HasChildQueryBuilder(CHILD_TYPE, innerQueryBuilder,
            RandomPicks.randomFrom(random(), ScoreMode.values()));
    hqb.minMaxChildren(min, max);
    hqb.ignoreUnmapped(randomBoolean());
    if (randomBoolean()) {
        hqb.innerHit(new InnerHitBuilder()
                .setName(randomAsciiOfLengthBetween(1, 10))
                .setSize(randomIntBetween(0, 100))
                .addSort(new FieldSortBuilder(STRING_FIELD_NAME_2).order(SortOrder.ASC)), hqb.ignoreUnmapped());
    }
    return hqb;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:HasChildQueryBuilderTests.java

示例4: doCreateTestQueryBuilder

import com.carrotsearch.randomizedtesting.generators.RandomPicks; //导入依赖的package包/类
/**
 * @return a {@link HasChildQueryBuilder} with random values all over the place
 */
@Override
protected NestedQueryBuilder doCreateTestQueryBuilder() {
    QueryBuilder innerQueryBuilder = RandomQueryBuilder.createQuery(random());
    if (randomBoolean()) {
        requiresRewrite = true;
        innerQueryBuilder = new WrapperQueryBuilder(innerQueryBuilder.toString());
    }
    NestedQueryBuilder nqb = new NestedQueryBuilder("nested1", innerQueryBuilder,
            RandomPicks.randomFrom(random(), ScoreMode.values()));
    nqb.ignoreUnmapped(randomBoolean());
    if (randomBoolean()) {
        nqb.innerHit(new InnerHitBuilder()
                .setName(randomAsciiOfLengthBetween(1, 10))
                .setSize(randomIntBetween(0, 100))
                .addSort(new FieldSortBuilder(INT_FIELD_NAME).order(SortOrder.ASC)), nqb.ignoreUnmapped());
    }
    return nqb;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:NestedQueryBuilderTests.java

示例5: testBuiltInAnalyzersAreCached

import com.carrotsearch.randomizedtesting.generators.RandomPicks; //导入依赖的package包/类
public void testBuiltInAnalyzersAreCached() throws IOException {
    Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build();
    Settings indexSettings = Settings.builder()
            .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
    IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index", indexSettings);
    IndexAnalyzers indexAnalyzers = new AnalysisRegistry(new Environment(settings),
            emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap())
            .build(idxSettings);
    IndexAnalyzers otherIndexAnalyzers = new AnalysisRegistry(new Environment(settings), emptyMap(), emptyMap(), emptyMap(),
            emptyMap(), emptyMap()).build(idxSettings);
    final int numIters = randomIntBetween(5, 20);
    for (int i = 0; i < numIters; i++) {
        PreBuiltAnalyzers preBuiltAnalyzers = RandomPicks.randomFrom(random(), PreBuiltAnalyzers.values());
        assertSame(indexAnalyzers.get(preBuiltAnalyzers.name()), otherIndexAnalyzers.get(preBuiltAnalyzers.name()));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:AnalysisRegistryTests.java

示例6: getTranslogDirs

import com.carrotsearch.randomizedtesting.generators.RandomPicks; //导入依赖的package包/类
private Set<Path> getTranslogDirs(String indexName) throws IOException {
    ClusterState state = client().admin().cluster().prepareState().get().getState();
    GroupShardsIterator shardIterators = state.getRoutingTable().activePrimaryShardsGrouped(new String[]{indexName}, false);
    final Index idx = state.metaData().index(indexName).getIndex();
    List<ShardIterator> iterators = iterableAsArrayList(shardIterators);
    ShardIterator shardIterator = RandomPicks.randomFrom(random(), iterators);
    ShardRouting shardRouting = shardIterator.nextOrNull();
    assertNotNull(shardRouting);
    assertTrue(shardRouting.primary());
    assertTrue(shardRouting.assignedToNode());
    String nodeId = shardRouting.currentNodeId();
    NodesStatsResponse nodeStatses = client().admin().cluster().prepareNodesStats(nodeId).setFs(true).get();
    Set<Path> translogDirs = new TreeSet<>(); // treeset makes sure iteration order is deterministic
    for (FsInfo.Path fsPath : nodeStatses.getNodes().get(0).getFs()) {
        String path = fsPath.getPath();
        final String relativeDataLocationPath =  "indices/"+ idx.getUUID() +"/" + Integer.toString(shardRouting.getId()) + "/translog";
        Path translogPath = PathUtils.get(path).resolve(relativeDataLocationPath);
        if (Files.isDirectory(translogPath)) {
            translogDirs.add(translogPath);
        }
    }
    return translogDirs;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:TruncateTranslogIT.java

示例7: testRangeQuery

import com.carrotsearch.randomizedtesting.generators.RandomPicks; //导入依赖的package包/类
public void testRangeQuery() throws Exception {
    Settings indexSettings = Settings.builder()
        .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
    IndexSettings idxSettings = IndexSettingsModule.newIndexSettings(randomAsciiOfLengthBetween(1, 10), indexSettings);
    QueryShardContext context = new QueryShardContext(0, idxSettings, null, null, null, null, null, xContentRegistry(),
            null, null, () -> nowInMillis);
    RangeFieldMapper.RangeFieldType ft = new RangeFieldMapper.RangeFieldType(type);
    ft.setName(FIELDNAME);
    ft.setIndexOptions(IndexOptions.DOCS);

    ShapeRelation relation = RandomPicks.randomFrom(random(), ShapeRelation.values());
    boolean includeLower = random().nextBoolean();
    boolean includeUpper = random().nextBoolean();
    Object from = nextFrom();
    Object to = nextTo(from);

    assertEquals(getExpectedRangeQuery(relation, from, to, includeLower, includeUpper),
        ft.rangeQuery(from, to, includeLower, includeUpper, relation, context));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:RangeFieldTypeTests.java

示例8: testSerialization

import com.carrotsearch.randomizedtesting.generators.RandomPicks; //导入依赖的package包/类
public void testSerialization() throws Exception {
    UnassignedInfo.Reason reason = RandomPicks.randomFrom(random(), UnassignedInfo.Reason.values());
    UnassignedInfo meta = reason == UnassignedInfo.Reason.ALLOCATION_FAILED ?
        new UnassignedInfo(reason, randomBoolean() ? randomAsciiOfLength(4) : null, null, randomIntBetween(1, 100), System.nanoTime(),
                           System.currentTimeMillis(), false, AllocationStatus.NO_ATTEMPT):
        new UnassignedInfo(reason, randomBoolean() ? randomAsciiOfLength(4) : null);
    BytesStreamOutput out = new BytesStreamOutput();
    meta.writeTo(out);
    out.close();

    UnassignedInfo read = new UnassignedInfo(out.bytes().streamInput());
    assertThat(read.getReason(), equalTo(meta.getReason()));
    assertThat(read.getUnassignedTimeInMillis(), equalTo(meta.getUnassignedTimeInMillis()));
    assertThat(read.getMessage(), equalTo(meta.getMessage()));
    assertThat(read.getDetails(), equalTo(meta.getDetails()));
    assertThat(read.getNumFailedAllocations(), equalTo(meta.getNumFailedAllocations()));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:UnassignedInfoTests.java

示例9: testBuildWithCountryDbAndCityFields

import com.carrotsearch.randomizedtesting.generators.RandomPicks; //导入依赖的package包/类
public void testBuildWithCountryDbAndCityFields() throws Exception {
    GeoIpProcessor.Factory factory = new GeoIpProcessor.Factory(databaseReaders);
    Map<String, Object> config = new HashMap<>();
    config.put("field", "_field");
    config.put("database_file", "GeoLite2-Country.mmdb.gz");
    EnumSet<GeoIpProcessor.Property> cityOnlyProperties = EnumSet.complementOf(GeoIpProcessor.Property.ALL_COUNTRY_PROPERTIES);
    String cityProperty = RandomPicks.randomFrom(Randomness.get(), cityOnlyProperties).toString();
    config.put("properties", Collections.singletonList(cityProperty));
    try {
        factory.create(null, null, config);
        fail("Exception expected");
    } catch (ElasticsearchParseException e) {
        assertThat(e.getMessage(), equalTo("[properties] illegal property value [" + cityProperty +
                "]. valid values are [IP, COUNTRY_ISO_CODE, COUNTRY_NAME, CONTINENT_NAME]"));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:GeoIpProcessorFactoryTests.java

示例10: RandomDocument

import com.carrotsearch.randomizedtesting.generators.RandomPicks; //导入依赖的package包/类
protected RandomDocument(int fieldCount, int maxTermCount, Options options, String[] fieldNames, String[] sampleTerms, BytesRef[] sampleTermBytes) {
  if (fieldCount > fieldNames.length) {
    throw new IllegalArgumentException();
  }
  this.fieldNames = new String[fieldCount];
  fieldTypes = new FieldType[fieldCount];
  tokenStreams = new RandomTokenStream[fieldCount];
  Arrays.fill(fieldTypes, fieldType(options));
  final Set<String> usedFileNames = new HashSet<>();
  for (int i = 0; i < fieldCount; ++i) {
    do {
      this.fieldNames[i] = RandomPicks.randomFrom(random(), fieldNames);
    } while (usedFileNames.contains(this.fieldNames[i]));
    usedFileNames.add(this.fieldNames[i]);
    tokenStreams[i] = new RandomTokenStream(TestUtil.nextInt(random(), 1, maxTermCount), sampleTerms, sampleTermBytes);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:18,代码来源:BaseTermVectorsFormatTestCase.java

示例11: randomLong

import com.carrotsearch.randomizedtesting.generators.RandomPicks; //导入依赖的package包/类
static long randomLong() {
  if (random().nextBoolean()) {
    long l = 1;
    if (random().nextBoolean()) {
      l *= -1;
    }
    for (long i : PRIMES) {
      final int m = random().nextInt(3);
      for (int j = 0; j < m; ++j) {
        l *= i;
      }
    }
    return l;
  } else if (random().nextBoolean()) {
    return random().nextLong();
  } else {
    return RandomPicks.randomFrom(random(), Arrays.asList(Long.MIN_VALUE, Long.MAX_VALUE, 0L, -1L, 1L));
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:20,代码来源:TestMathUtil.java

示例12: RandomDocument

import com.carrotsearch.randomizedtesting.generators.RandomPicks; //导入依赖的package包/类
protected RandomDocument(int fieldCount, int maxTermCount, Options options, String[] fieldNames, String[] sampleTerms, BytesRef[] sampleTermBytes) {
  if (fieldCount > fieldNames.length) {
    throw new IllegalArgumentException();
  }
  this.fieldNames = new String[fieldCount];
  fieldTypes = new FieldType[fieldCount];
  tokenStreams = new RandomTokenStream[fieldCount];
  Arrays.fill(fieldTypes, fieldType(options));
  final Set<String> usedFileNames = new HashSet<String>();
  for (int i = 0; i < fieldCount; ++i) {
    do {
      this.fieldNames[i] = RandomPicks.randomFrom(random(), fieldNames);
    } while (usedFileNames.contains(this.fieldNames[i]));
    usedFileNames.add(this.fieldNames[i]);
    tokenStreams[i] = new RandomTokenStream(_TestUtil.nextInt(random(), 1, maxTermCount), sampleTerms, sampleTermBytes);
  }
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:18,代码来源:BaseTermVectorsFormatTestCase.java

示例13: newDirectoryImpl

import com.carrotsearch.randomizedtesting.generators.RandomPicks; //导入依赖的package包/类
static Directory newDirectoryImpl(Random random, String clazzName) {
  if (clazzName.equals("random")) {
    if (rarely(random)) {
      clazzName = RandomPicks.randomFrom(random, CORE_DIRECTORIES);
    } else {
      clazzName = "RAMDirectory";
    }
  }

  try {
    final Class<? extends Directory> clazz = CommandLineUtil.loadDirectoryClass(clazzName);
    // If it is a FSDirectory type, try its ctor(File)
    if (FSDirectory.class.isAssignableFrom(clazz)) {
      final File dir = _TestUtil.getTempDir("index");
      dir.mkdirs(); // ensure it's created so we 'have' it.
      return newFSDirectoryImpl(clazz.asSubclass(FSDirectory.class), dir);
    }

    // try empty ctor
    return clazz.newInstance();
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:25,代码来源:LuceneTestCase.java

示例14: createRandomIndexes

import com.carrotsearch.randomizedtesting.generators.RandomPicks; //导入依赖的package包/类
private void createRandomIndexes(int maxSegments) throws IOException {
  dir = newDirectory();
  numDocs = atLeast(150);
  final int numTerms = _TestUtil.nextInt(random(), 1, numDocs / 5);
  Set<String> randomTerms = new HashSet<String>();
  while (randomTerms.size() < numTerms) {
    randomTerms.add(_TestUtil.randomSimpleString(random()));
  }
  terms = new ArrayList<String>(randomTerms);
  final long seed = random().nextLong();
  final IndexWriterConfig iwc = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(new Random(seed)));
  iwc.setMergePolicy(TestSortingMergePolicy.newSortingMergePolicy(sorter));
  iw = new RandomIndexWriter(new Random(seed), dir, iwc);
  for (int i = 0; i < numDocs; ++i) {
    final Document doc = randomDocument();
    iw.addDocument(doc);
    if (i == numDocs / 2 || (i != numDocs - 1 && random().nextInt(8) == 0)) {
      iw.commit();
    }
    if (random().nextInt(15) == 0) {
      final String term = RandomPicks.randomFrom(random(), terms);
      iw.deleteDocuments(new Term("s", term));
    }
  }
  reader = iw.getReader();
}
 
开发者ID:jimaguere,项目名称:Maskana-Gestor-de-Conocimiento,代码行数:27,代码来源:TestEarlyTermination.java

示例15: testEarlyTermination

import com.carrotsearch.randomizedtesting.generators.RandomPicks; //导入依赖的package包/类
public void testEarlyTermination() throws IOException {
  createRandomIndexes(5);
  final int numHits = _TestUtil.nextInt(random(), 1, numDocs / 10);
  final Sort sort = new Sort(new SortField("ndv1", SortField.Type.LONG, false));
  final boolean fillFields = random().nextBoolean();
  final boolean trackDocScores = random().nextBoolean();
  final boolean trackMaxScore = random().nextBoolean();
  final boolean inOrder = random().nextBoolean();
  final TopFieldCollector collector1 = TopFieldCollector.create(sort, numHits, fillFields, trackDocScores, trackMaxScore, inOrder);
  final TopFieldCollector collector2 = TopFieldCollector.create(sort, numHits, fillFields, trackDocScores, trackMaxScore, inOrder);

  final IndexSearcher searcher = newSearcher(reader);
  final int iters = atLeast(5);
  for (int i = 0; i < iters; ++i) {
    final TermQuery query = new TermQuery(new Term("s", RandomPicks.randomFrom(random(), terms)));
    searcher.search(query, collector1);
    searcher.search(query, new EarlyTerminatingSortingCollector(collector2, sorter, numHits));
  }
  assertTrue(collector1.getTotalHits() >= collector2.getTotalHits());
  assertTopDocsEquals(collector1.topDocs().scoreDocs, collector2.topDocs().scoreDocs);
}
 
开发者ID:jimaguere,项目名称:Maskana-Gestor-de-Conocimiento,代码行数:22,代码来源:TestEarlyTermination.java


注:本文中的com.carrotsearch.randomizedtesting.generators.RandomPicks类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。