當前位置: 首頁>>代碼示例>>Java>>正文


Java ESTestCase類代碼示例

本文整理匯總了Java中org.elasticsearch.test.ESTestCase的典型用法代碼示例。如果您正苦於以下問題:Java ESTestCase類的具體用法?Java ESTestCase怎麽用?Java ESTestCase使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ESTestCase類屬於org.elasticsearch.test包,在下文中一共展示了ESTestCase類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: buildRecoveryTarget

import org.elasticsearch.test.ESTestCase; //導入依賴的package包/類
private static RecoverySource buildRecoveryTarget(boolean primary, ShardRoutingState state) {
    switch (state) {
        case UNASSIGNED:
        case INITIALIZING:
            if (primary) {
                return ESTestCase.randomFrom(RecoverySource.StoreRecoverySource.EMPTY_STORE_INSTANCE,
                    RecoverySource.StoreRecoverySource.EXISTING_STORE_INSTANCE);
            } else {
                return RecoverySource.PeerRecoverySource.INSTANCE;
            }
        case STARTED:
        case RELOCATING:
            return null;
        default:
            throw new IllegalStateException("illegal state");
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:18,代碼來源:TestShardRouting.java

示例2: ensureAllArraysAreReleased

import org.elasticsearch.test.ESTestCase; //導入依賴的package包/類
public static void ensureAllArraysAreReleased() throws Exception {
    final Map<Object, Object> masterCopy = new HashMap<>(ACQUIRED_ARRAYS);
    if (!masterCopy.isEmpty()) {
        // not empty, we might be executing on a shared cluster that keeps on obtaining
        // and releasing arrays, lets make sure that after a reasonable timeout, all master
        // copy (snapshot) have been released
        boolean success = ESTestCase.awaitBusy(() -> Sets.haveEmptyIntersection(masterCopy.keySet(), ACQUIRED_ARRAYS.keySet()));
        if (!success) {
            masterCopy.keySet().retainAll(ACQUIRED_ARRAYS.keySet());
            ACQUIRED_ARRAYS.keySet().removeAll(masterCopy.keySet()); // remove all existing master copy we will report on
            if (!masterCopy.isEmpty()) {
                final Object cause = masterCopy.entrySet().iterator().next().getValue();
                throw new RuntimeException(masterCopy.size() + " arrays have not been released", cause instanceof Throwable ? (Throwable) cause : null);
            }
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:18,代碼來源:MockBigArrays.java

示例3: ensureAllPagesAreReleased

import org.elasticsearch.test.ESTestCase; //導入依賴的package包/類
public static void ensureAllPagesAreReleased() throws Exception {
    final Map<Object, Throwable> masterCopy = new HashMap<>(ACQUIRED_PAGES);
    if (!masterCopy.isEmpty()) {
        // not empty, we might be executing on a shared cluster that keeps on obtaining
        // and releasing pages, lets make sure that after a reasonable timeout, all master
        // copy (snapshot) have been released
        boolean success =
                ESTestCase.awaitBusy(() -> Sets.haveEmptyIntersection(masterCopy.keySet(), ACQUIRED_PAGES.keySet()));
        if (!success) {
            masterCopy.keySet().retainAll(ACQUIRED_PAGES.keySet());
            ACQUIRED_PAGES.keySet().removeAll(masterCopy.keySet()); // remove all existing master copy we will report on
            if (!masterCopy.isEmpty()) {
                final Throwable t = masterCopy.entrySet().iterator().next().getValue();
                throw new RuntimeException(masterCopy.size() + " pages have not been released", t);
            }
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:19,代碼來源:MockPageCacheRecycler.java

示例4: testEnglishFilterFactory

import org.elasticsearch.test.ESTestCase; //導入依賴的package包/類
public void testEnglishFilterFactory() throws IOException {
    int iters = scaledRandomIntBetween(20, 100);
    for (int i = 0; i < iters; i++) {
        Version v = VersionUtils.randomVersion(random());
        Settings settings = Settings.builder()
                .put("index.analysis.filter.my_english.type", "stemmer")
                .put("index.analysis.filter.my_english.language", "english")
                .put("index.analysis.analyzer.my_english.tokenizer","whitespace")
                .put("index.analysis.analyzer.my_english.filter","my_english")
                .put(SETTING_VERSION_CREATED,v)
                .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
                .build();

        ESTestCase.TestAnalysis analysis = AnalysisTestsHelper.createTestAnalysisFromSettings(settings);
        TokenFilterFactory tokenFilter = analysis.tokenFilter.get("my_english");
        assertThat(tokenFilter, instanceOf(StemmerTokenFilterFactory.class));
        Tokenizer tokenizer = new WhitespaceTokenizer();
        tokenizer.setReader(new StringReader("foo bar"));
        TokenStream create = tokenFilter.create(tokenizer);
        IndexAnalyzers indexAnalyzers = analysis.indexAnalyzers;
        NamedAnalyzer analyzer = indexAnalyzers.get("my_english");
        assertThat(create, instanceOf(PorterStemFilter.class));
        assertAnalyzesTo(analyzer, "consolingly", new String[]{"consolingli"});
    }

}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:27,代碼來源:StemmerTokenFilterFactoryTests.java

示例5: testDefault

import org.elasticsearch.test.ESTestCase; //導入依賴的package包/類
public void testDefault() throws IOException {
    int default_hash_count = 1;
    int default_bucket_size = 512;
    int default_hash_set_size = 1;
    Settings settings = Settings.builder()
        .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
        .build();
    ESTestCase.TestAnalysis analysis = AnalysisTestsHelper.createTestAnalysisFromSettings(settings);
    TokenFilterFactory tokenFilter = analysis.tokenFilter.get("min_hash");
    String source = "the quick brown fox";
    Tokenizer tokenizer = new WhitespaceTokenizer();
    tokenizer.setReader(new StringReader(source));

    // with_rotation is true by default, and hash_set_size is 1, so even though the source doesn't
    // have enough tokens to fill all the buckets, we still expect 512 tokens.
    assertStreamHasNumberOfTokens(tokenFilter.create(tokenizer),
        default_hash_count * default_bucket_size * default_hash_set_size);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:19,代碼來源:MinHashFilterFactoryTests.java

示例6: testSettings

import org.elasticsearch.test.ESTestCase; //導入依賴的package包/類
public void testSettings() throws IOException {
    Settings settings = Settings.builder()
        .put("index.analysis.filter.test_min_hash.type", "min_hash")
        .put("index.analysis.filter.test_min_hash.hash_count", "1")
        .put("index.analysis.filter.test_min_hash.bucket_count", "2")
        .put("index.analysis.filter.test_min_hash.hash_set_size", "1")
        .put("index.analysis.filter.test_min_hash.with_rotation", false)
        .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
        .build();
    ESTestCase.TestAnalysis analysis = AnalysisTestsHelper.createTestAnalysisFromSettings(settings);
    TokenFilterFactory tokenFilter = analysis.tokenFilter.get("test_min_hash");
    String source = "sushi";
    Tokenizer tokenizer = new WhitespaceTokenizer();
    tokenizer.setReader(new StringReader(source));

    // despite the fact that bucket_count is 2 and hash_set_size is 1,
    // because with_rotation is false, we only expect 1 token here.
    assertStreamHasNumberOfTokens(tokenFilter.create(tokenizer), 1);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:20,代碼來源:MinHashFilterFactoryTests.java

示例7: testCorrectPositionIncrementSetting

import org.elasticsearch.test.ESTestCase; //導入依賴的package包/類
public void testCorrectPositionIncrementSetting() throws IOException {
    Builder builder = Settings.builder().put("index.analysis.filter.my_stop.type", "stop");
    if (random().nextBoolean()) {
        builder.put("index.analysis.filter.my_stop.version", Version.LATEST);
    } else {
        // don't specify
    }
    builder.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString());
    ESTestCase.TestAnalysis analysis = AnalysisTestsHelper.createTestAnalysisFromSettings(builder.build());
    TokenFilterFactory tokenFilter = analysis.tokenFilter.get("my_stop");
    assertThat(tokenFilter, instanceOf(StopTokenFilterFactory.class));
    Tokenizer tokenizer = new WhitespaceTokenizer();
    tokenizer.setReader(new StringReader("foo bar"));
    TokenStream create = tokenFilter.create(tokenizer);
    assertThat(create, instanceOf(StopFilter.class));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:17,代碼來源:StopTokenFilterTests.java

示例8: testMultiTerms

import org.elasticsearch.test.ESTestCase; //導入依賴的package包/類
public void testMultiTerms() throws IOException {
    ESTestCase.TestAnalysis analysis = AnalysisTestsHelper.createTestAnalysisFromSettings(Settings.builder()
        .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
        .put("index.analysis.filter.my_word_delimiter.type", type)
        .put("index.analysis.filter.my_word_delimiter.catenate_all", "true")
        .put("index.analysis.filter.my_word_delimiter.preserve_original", "true")
        .build());

    TokenFilterFactory tokenFilter = analysis.tokenFilter.get("my_word_delimiter");
    String source = "PowerShot 500-42 wi-fi wi-fi-4000 j2se O'Neil's";
    String[] expected = new String[]{"PowerShot", "PowerShot", "Power", "Shot", "50042", "500-42", "500", "42",
        "wifi", "wi-fi", "wi", "fi", "wifi4000", "wi-fi-4000", "wi", "fi", "4000", "j2se", "j2se", "j", "2", "se",
        "ONeil", "O'Neil's", "O", "Neil" };
    Tokenizer tokenizer = new WhitespaceTokenizer();
    tokenizer.setReader(new StringReader(source));
    int[] expectedIncr = new int[]{1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1};
    int[] expectedPosLen = new int[]{2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 3, 3, 1, 1, 1, 3, 3, 1, 1, 1, 2, 2, 1, 1};
    assertTokenStreamContents(tokenFilter.create(tokenizer), expected, null, null, null,
            expectedIncr, expectedPosLen, null);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:21,代碼來源:WordDelimiterGraphTokenFilterFactoryTests.java

示例9: testPartsAndCatenate

import org.elasticsearch.test.ESTestCase; //導入依賴的package包/類
/** Correct offset order when doing both parts and concatenation: PowerShot is a synonym of Power */
public void testPartsAndCatenate() throws IOException {
    ESTestCase.TestAnalysis analysis = AnalysisTestsHelper.createTestAnalysisFromSettings(Settings.builder()
        .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
        .put("index.analysis.filter.my_word_delimiter.type", type)
        .put("index.analysis.filter.my_word_delimiter.catenate_words", "true")
        .put("index.analysis.filter.my_word_delimiter.generate_word_parts", "true")
        .build());
    TokenFilterFactory tokenFilter = analysis.tokenFilter.get("my_word_delimiter");
    String source = "PowerShot";
    int[] expectedIncr = new int[]{1, 0, 1};
    int[] expectedPosLen = new int[]{2, 1, 1};
    String[] expected = new String[]{"PowerShot", "Power", "Shot" };
    Tokenizer tokenizer = new WhitespaceTokenizer();
    tokenizer.setReader(new StringReader(source));
    assertTokenStreamContents(tokenFilter.create(tokenizer), expected, null, null, null,
        expectedIncr, expectedPosLen, null);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:19,代碼來源:WordDelimiterGraphTokenFilterFactoryTests.java

示例10: createAnalysis

import org.elasticsearch.test.ESTestCase; //導入依賴的package包/類
public ESTestCase.TestAnalysis createAnalysis() throws IOException {
    Settings settings = Settings
                        .builder()
                        .loadFromStream("lemmagen.json", getClass().getResourceAsStream("lemmagen.json"))
                        .build();

    Settings nodeSettings = Settings
                            .builder()
                            .put("path.home", (new File("")).getAbsolutePath())
                            .put("path.conf", (new File("")).getAbsolutePath())
                            .build();

    Index index = new Index("test", "_na_");

    ESTestCase.TestAnalysis analysis = createTestAnalysis(index, nodeSettings, settings, new AnalysisLemmagenPlugin());

    return analysis;
}
 
開發者ID:vhyza,項目名稱:elasticsearch-analysis-lemmagen,代碼行數:19,代碼來源:LemmagenAnalysisTest.java

示例11: buildUnassignedInfo

import org.elasticsearch.test.ESTestCase; //導入依賴的package包/類
private static UnassignedInfo buildUnassignedInfo(ShardRoutingState state) {
    switch (state) {
        case UNASSIGNED:
        case INITIALIZING:
            return new UnassignedInfo(ESTestCase.randomFrom(UnassignedInfo.Reason.values()), "auto generated for test");
        case STARTED:
        case RELOCATING:
            return null;
        default:
            throw new IllegalStateException("illegal state");
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:13,代碼來源:TestShardRouting.java

示例12: randomRecoverySource

import org.elasticsearch.test.ESTestCase; //導入依賴的package包/類
public static RecoverySource randomRecoverySource() {
    return ESTestCase.randomFrom(RecoverySource.StoreRecoverySource.EMPTY_STORE_INSTANCE,
        RecoverySource.StoreRecoverySource.EXISTING_STORE_INSTANCE,
        RecoverySource.PeerRecoverySource.INSTANCE,
        RecoverySource.LocalShardsRecoverySource.INSTANCE,
        new RecoverySource.SnapshotRecoverySource(
            new Snapshot("repo", new SnapshotId(randomAsciiOfLength(8), UUIDs.randomBase64UUID())),
            Version.CURRENT,
            "some_index"));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:11,代碼來源:TestShardRouting.java

示例13: makeStats

import org.elasticsearch.test.ESTestCase; //導入依賴的package包/類
/** Create a fake NodeStats for the given node and usage */
public static NodeStats makeStats(String nodeName, DiskUsage usage) {
    FsInfo.Path[] paths = new FsInfo.Path[1];
    FsInfo.Path path = new FsInfo.Path("/dev/null", null,
        usage.getTotalBytes(), usage.getFreeBytes(), usage.getFreeBytes());
    paths[0] = path;
    FsInfo fsInfo = new FsInfo(System.currentTimeMillis(), null, paths);
    return new NodeStats(new DiscoveryNode(nodeName, ESTestCase.buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT),
        System.currentTimeMillis(),
        null, null, null, null, null,
        fsInfo,
        null, null, null,
        null, null, null);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:15,代碼來源:MockInternalClusterInfoService.java

示例14: testForSlice

import org.elasticsearch.test.ESTestCase; //導入依賴的package包/類
public void testForSlice() {
    R original = newRequest();
    original.setAbortOnVersionConflict(randomBoolean());
    original.setRefresh(randomBoolean());
    original.setTimeout(parseTimeValue(randomPositiveTimeValue(), "timeout"));
    original.setWaitForActiveShards(
            randomFrom(ActiveShardCount.ALL, ActiveShardCount.NONE, ActiveShardCount.ONE, ActiveShardCount.DEFAULT));
    original.setRetryBackoffInitialTime(parseTimeValue(randomPositiveTimeValue(), "retry_backoff_initial_time"));
    original.setMaxRetries(between(0, 1000));
    original.setSlices(between(2, 1000));
    original.setRequestsPerSecond(
            randomBoolean() ? Float.POSITIVE_INFINITY : randomValueOtherThanMany(r -> r < 0, ESTestCase::randomFloat));
    original.setSize(randomBoolean() ? AbstractBulkByScrollRequest.SIZE_ALL_MATCHES : between(0, Integer.MAX_VALUE));

    TaskId slicingTask = new TaskId(randomAsciiOfLength(5), randomLong());
    SearchRequest sliceRequest = new SearchRequest();
    R forSliced = original.forSlice(slicingTask, sliceRequest);
    assertEquals(original.isAbortOnVersionConflict(), forSliced.isAbortOnVersionConflict());
    assertEquals(original.isRefresh(), forSliced.isRefresh());
    assertEquals(original.getTimeout(), forSliced.getTimeout());
    assertEquals(original.getWaitForActiveShards(), forSliced.getWaitForActiveShards());
    assertEquals(original.getRetryBackoffInitialTime(), forSliced.getRetryBackoffInitialTime());
    assertEquals(original.getMaxRetries(), forSliced.getMaxRetries());
    assertEquals("only the parent task should store results", false, forSliced.getShouldStoreResult());
    assertEquals("slice requests always have a single worker", 1, forSliced.getSlices());
    assertEquals("requests_per_second is split between all workers", original.getRequestsPerSecond() / original.getSlices(),
            forSliced.getRequestsPerSecond(), Float.MIN_NORMAL);
    assertEquals("size is split evenly between all workers", original.getSize() == AbstractBulkByScrollRequest.SIZE_ALL_MATCHES
            ? AbstractBulkByScrollRequest.SIZE_ALL_MATCHES : original.getSize() / original.getSlices(), forSliced.getSize());
    assertEquals(slicingTask, forSliced.getParentTask());

    extraForSliceAssertions(original, forSliced);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:34,代碼來源:AbstractBulkByScrollRequestTestCase.java

示例15: mutate

import org.elasticsearch.test.ESTestCase; //導入依賴的package包/類
private static RescoreBuilder<?> mutate(RescoreBuilder<?> original) throws IOException {
    RescoreBuilder<?> mutation = ESTestCase.copyWriteable(original, namedWriteableRegistry, QueryRescorerBuilder::new);
    if (randomBoolean()) {
        Integer windowSize = original.windowSize();
        if (windowSize != null) {
            mutation.windowSize(windowSize + 1);
        } else {
            mutation.windowSize(randomIntBetween(0, 100));
        }
    } else {
        QueryRescorerBuilder queryRescorer = (QueryRescorerBuilder) mutation;
        switch (randomIntBetween(0, 3)) {
        case 0:
            queryRescorer.setQueryWeight(queryRescorer.getQueryWeight() + 0.1f);
            break;
        case 1:
            queryRescorer.setRescoreQueryWeight(queryRescorer.getRescoreQueryWeight() + 0.1f);
            break;
        case 2:
            QueryRescoreMode other;
            do {
                other = randomFrom(QueryRescoreMode.values());
            } while (other == queryRescorer.getScoreMode());
            queryRescorer.setScoreMode(other);
            break;
        case 3:
            // only increase the boost to make it a slightly different query
            queryRescorer.getRescoreQuery().boost(queryRescorer.getRescoreQuery().boost() + 0.1f);
            break;
        default:
            throw new IllegalStateException("unexpected random mutation in test");
        }
    }
    return mutation;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:36,代碼來源:QueryRescoreBuilderTests.java


注:本文中的org.elasticsearch.test.ESTestCase類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。