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


Java ElasticsearchIntegrationTest類代碼示例

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


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

示例1: testReportsCounters

import org.elasticsearch.test.ElasticsearchIntegrationTest; //導入依賴的package包/類
@Test
public void testReportsCounters() {
    String metricName = "com.codahale.metrics.elasticsearch.test.counter";

    Counter counter = registry.counter(metricName);
    counter.inc();

    waitForReporter();
    flushAndRefresh();

    SearchResponse searchResponse = searchWithTimeout(
            new SearchRequestBuilder(ElasticsearchIntegrationTest.client())
                    .setIndices("_all")
                    .setTypes(MetricElasticsearchTypes.COUNTER).setSize(20)
                    .setQuery(QueryBuilders.matchAllQuery()), 1);
    Assert.assertEquals(true, searchResponse.getHits().getHits().length > 0);
    Map<String, Object> searchHitSource = searchResponse.getHits()
            .getHits()[0].getSource();
    Assert.assertEquals(prefix + "." + metricName,
            searchHitSource.get("@name"));
    Assert.assertEquals(1, searchHitSource.get("count"));
}
 
開發者ID:tomcashman,項目名稱:metrics-elasticsearch,代碼行數:23,代碼來源:ElasticsearchHttpReporterTest.java

示例2: testReportsTimers

import org.elasticsearch.test.ElasticsearchIntegrationTest; //導入依賴的package包/類
@Test
public void testReportsTimers() {
    String metricName = "com.codahale.metrics.elasticsearch.test.timer";

    Timer timer = registry.timer(metricName);
    timer.update(1000, TimeUnit.MILLISECONDS);

    waitForReporter();
    flushAndRefresh();

    SearchResponse searchResponse = searchWithTimeout(
            new SearchRequestBuilder(ElasticsearchIntegrationTest.client())
                    .setIndices("_all")
                    .setTypes(MetricElasticsearchTypes.TIMER).setSize(20)
                    .setQuery(QueryBuilders.matchAllQuery()), 1);
    Assert.assertEquals(true, searchResponse.getHits().getHits().length > 0);
    Map<String, Object> searchHitSource = searchResponse.getHits()
            .getHits()[0].getSource();
    Assert.assertEquals(prefix + "." + metricName,
            searchHitSource.get("@name"));
    Assert.assertEquals(1, searchHitSource.get("count"));
}
 
開發者ID:tomcashman,項目名稱:metrics-elasticsearch,代碼行數:23,代碼來源:ElasticsearchHttpReporterTest.java

示例3: testReportsMeters

import org.elasticsearch.test.ElasticsearchIntegrationTest; //導入依賴的package包/類
@Test
public void testReportsMeters() {
    String metricName = "com.codahale.metrics.elasticsearch.test.meter";

    Meter meter = registry.meter(metricName);
    meter.mark();

    waitForReporter();
    flushAndRefresh();

    SearchResponse searchResponse = searchWithTimeout(
            new SearchRequestBuilder(ElasticsearchIntegrationTest.client())
                    .setIndices("_all").setSize(20)
                    .setTypes(MetricElasticsearchTypes.METER)
                    .setQuery(QueryBuilders.matchAllQuery()), 1);
    Assert.assertEquals(true, searchResponse.getHits().getHits().length > 0);
    Map<String, Object> searchHitSource = searchResponse.getHits()
            .getHits()[0].getSource();
    Assert.assertEquals(prefix + "." + metricName,
            searchHitSource.get("@name"));
    Assert.assertEquals(1, searchHitSource.get("count"));
}
 
開發者ID:tomcashman,項目名稱:metrics-elasticsearch,代碼行數:23,代碼來源:ElasticsearchHttpReporterTest.java

示例4: testReportsHistograms

import org.elasticsearch.test.ElasticsearchIntegrationTest; //導入依賴的package包/類
@Test
public void testReportsHistograms() {
    String metricName = "com.codahale.metrics.elasticsearch.test.histogram";

    Histogram histogram = registry.histogram(metricName);
    histogram.update(1);

    waitForReporter();
    flushAndRefresh();

    SearchResponse searchResponse = searchWithTimeout(
            new SearchRequestBuilder(ElasticsearchIntegrationTest.client())
                    .setIndices("_all").setSize(20)
                    .setTypes(MetricElasticsearchTypes.HISTOGRAM)
                    .setQuery(QueryBuilders.matchAllQuery()), 1);
    Assert.assertEquals(true, searchResponse.getHits().getHits().length > 0);
    Map<String, Object> searchHitSource = searchResponse.getHits()
            .getHits()[0].getSource();
    Assert.assertEquals(prefix + "." + metricName,
            searchHitSource.get("@name"));
    Assert.assertEquals(1, searchHitSource.get("count"));
}
 
開發者ID:tomcashman,項目名稱:metrics-elasticsearch,代碼行數:23,代碼來源:ElasticsearchHttpReporterTest.java

示例5: testReportsCounters

import org.elasticsearch.test.ElasticsearchIntegrationTest; //導入依賴的package包/類
@Test
public void testReportsCounters() {
    String metricName = "com.codahale.metrics.elasticsearch.test.counter";

    Counter counter = registry.counter(metricName);
    counter.inc();

    waitForReporter();
    flushAndRefresh();

    SearchResponse searchResponse = searchWithTimeout(
            new SearchRequestBuilder(ElasticsearchIntegrationTest.client())
                    .setIndices("_all")
                    .setTypes(MetricElasticsearchTypes.COUNTER)
                    .setQuery(QueryBuilders.matchAllQuery()), 1);
    Assert.assertEquals(true, searchResponse.getHits().getHits().length > 0);
    Map<String, Object> searchHitSource = searchResponse.getHits()
            .getHits()[0].getSource();
    Assert.assertEquals(prefix + "." + metricName,
            searchHitSource.get("@name"));
    Assert.assertEquals(1, searchHitSource.get("count"));
}
 
開發者ID:tomcashman,項目名稱:metrics-elasticsearch,代碼行數:23,代碼來源:ElasticsearchTransportReporterTest.java

示例6: testReportsTimers

import org.elasticsearch.test.ElasticsearchIntegrationTest; //導入依賴的package包/類
@Test
public void testReportsTimers() {
    String metricName = "com.codahale.metrics.elasticsearch.test.timer";

    Timer timer = registry.timer(metricName);
    timer.update(1000, TimeUnit.MILLISECONDS);

    waitForReporter();
    flushAndRefresh();

    SearchResponse searchResponse = searchWithTimeout(
            new SearchRequestBuilder(ElasticsearchIntegrationTest.client())
                    .setIndices("_all")
                    .setTypes(MetricElasticsearchTypes.TIMER)
                    .setQuery(QueryBuilders.matchAllQuery()), 1);
    Assert.assertEquals(true, searchResponse.getHits().getHits().length > 0);
    Map<String, Object> searchHitSource = searchResponse.getHits()
            .getHits()[0].getSource();
    Assert.assertEquals(prefix + "." + metricName,
            searchHitSource.get("@name"));
    Assert.assertEquals(1, searchHitSource.get("count"));
}
 
開發者ID:tomcashman,項目名稱:metrics-elasticsearch,代碼行數:23,代碼來源:ElasticsearchTransportReporterTest.java

示例7: testReportsMeters

import org.elasticsearch.test.ElasticsearchIntegrationTest; //導入依賴的package包/類
@Test
public void testReportsMeters() {
    String metricName = "com.codahale.metrics.elasticsearch.test.meter";

    Meter meter = registry.meter(metricName);
    meter.mark();

    waitForReporter();
    flushAndRefresh();

    SearchResponse searchResponse = searchWithTimeout(
            new SearchRequestBuilder(ElasticsearchIntegrationTest.client())
                    .setIndices("_all")
                    .setTypes(MetricElasticsearchTypes.METER)
                    .setQuery(QueryBuilders.matchAllQuery()), 1);
    Assert.assertEquals(true, searchResponse.getHits().getHits().length > 0);
    Map<String, Object> searchHitSource = searchResponse.getHits()
            .getHits()[0].getSource();
    Assert.assertEquals(prefix + "." + metricName,
            searchHitSource.get("@name"));
    Assert.assertEquals(1, searchHitSource.get("count"));
}
 
開發者ID:tomcashman,項目名稱:metrics-elasticsearch,代碼行數:23,代碼來源:ElasticsearchTransportReporterTest.java

示例8: testReportsHistograms

import org.elasticsearch.test.ElasticsearchIntegrationTest; //導入依賴的package包/類
@Test
public void testReportsHistograms() {
    String metricName = "com.codahale.metrics.elasticsearch.test.histogram";

    Histogram histogram = registry.histogram(metricName);
    histogram.update(1);

    waitForReporter();
    flushAndRefresh();

    SearchResponse searchResponse = searchWithTimeout(
            new SearchRequestBuilder(ElasticsearchIntegrationTest.client())
                    .setIndices("_all")
                    .setTypes(MetricElasticsearchTypes.HISTOGRAM)
                    .setQuery(QueryBuilders.matchAllQuery()), 1);
    Assert.assertEquals(true, searchResponse.getHits().getHits().length > 0);
    Map<String, Object> searchHitSource = searchResponse.getHits()
            .getHits()[0].getSource();
    Assert.assertEquals(prefix + "." + metricName,
            searchHitSource.get("@name"));
    Assert.assertEquals(1, searchHitSource.get("count"));
}
 
開發者ID:tomcashman,項目名稱:metrics-elasticsearch,代碼行數:23,代碼來源:ElasticsearchTransportReporterTest.java

示例9: testReportsWithAlternateTimestampField

import org.elasticsearch.test.ElasticsearchIntegrationTest; //導入依賴的package包/類
@Test
public void testReportsWithAlternateTimestampField() {
    reporter.stop();
    reporter = ElasticsearchHttpReporter
            .forRegistryAndIndexPrefix(registry, "test")
            .withTimestampFieldName("@timeywimey")
            .withClock(Clock.defaultClock()).prefixedWith(prefix)
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS)
            .withBulkRequestLimit(10).filter(MetricFilter.ALL)
            .build("localhost:9201");
    reporter.start(1, TimeUnit.SECONDS);

    String metricName = "com.codahale.metrics.elasticsearch.test.counter";

    Counter counter = registry.counter(metricName);
    counter.inc();

    waitForReporter();
    flushAndRefresh();

    SearchResponse searchResponse = searchWithTimeout(
            new SearchRequestBuilder(ElasticsearchIntegrationTest.client())
                    .setIndices("_all")
                    .setTypes(MetricElasticsearchTypes.COUNTER).setSize(20)
                    .setQuery(QueryBuilders.matchAllQuery()), 1);
    Assert.assertEquals(true, searchResponse.getHits().getHits().length > 0);
    Map<String, Object> searchHitSource = searchResponse.getHits()
            .getHits()[0].getSource();
    Assert.assertEquals(prefix + "." + metricName,
            searchHitSource.get("@name"));
    Assert.assertEquals(1, searchHitSource.get("count"));
    Assert.assertEquals(true, searchHitSource.containsKey("@timeywimey"));
}
 
開發者ID:tomcashman,項目名稱:metrics-elasticsearch,代碼行數:35,代碼來源:ElasticsearchHttpReporterTest.java

示例10: setUp

import org.elasticsearch.test.ElasticsearchIntegrationTest; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
    super.setUp();
    reporter = ElasticsearchTransportReporter
            .forRegistryAndIndexPrefix(registry, "test")
            .withClock(Clock.defaultClock()).prefixedWith(prefix)
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS)
            .withBulkRequestLimit(10).filter(MetricFilter.ALL)
            .build(ElasticsearchIntegrationTest.client());
    reporter.start(1, TimeUnit.SECONDS);
}
 
開發者ID:tomcashman,項目名稱:metrics-elasticsearch,代碼行數:13,代碼來源:ElasticsearchTransportReporterTest.java

示例11: testReportsWithAlternateTimestampField

import org.elasticsearch.test.ElasticsearchIntegrationTest; //導入依賴的package包/類
@Test
public void testReportsWithAlternateTimestampField() {
    reporter.stop();
    reporter = ElasticsearchTransportReporter
            .forRegistryAndIndexPrefix(registry, "test")
            .withTimestampFieldName("@timeywimey")
            .withClock(Clock.defaultClock()).prefixedWith(prefix)
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS)
            .withBulkRequestLimit(10).filter(MetricFilter.ALL)
            .build(ElasticsearchIntegrationTest.client());
    reporter.start(1, TimeUnit.SECONDS);

    String metricName = "com.codahale.metrics.elasticsearch.test.counter";

    Counter counter = registry.counter(metricName);
    counter.inc();

    waitForReporter();
    flushAndRefresh();

    SearchResponse searchResponse = searchWithTimeout(
            new SearchRequestBuilder(ElasticsearchIntegrationTest.client())
                    .setIndices("_all")
                    .setTypes(MetricElasticsearchTypes.COUNTER)
                    .setQuery(QueryBuilders.matchAllQuery()), 1);
    Assert.assertEquals(true, searchResponse.getHits().getHits().length > 0);
    Map<String, Object> searchHitSource = searchResponse.getHits()
            .getHits()[0].getSource();
    Assert.assertEquals(prefix + "." + metricName,
            searchHitSource.get("@name"));
    Assert.assertEquals(1, searchHitSource.get("count"));
    Assert.assertEquals(true, searchHitSource.containsKey("@timeywimey"));
}
 
開發者ID:tomcashman,項目名稱:metrics-elasticsearch,代碼行數:35,代碼來源:ElasticsearchTransportReporterTest.java

示例12: testReportsWithBulkRequestLimit

import org.elasticsearch.test.ElasticsearchIntegrationTest; //導入依賴的package包/類
@Test
public void testReportsWithBulkRequestLimit() {
    DecimalFormat formatter = new DecimalFormat("00");
    String metricNamePrefix = "com.codahale.metrics.elasticsearch.test.counter";
    for (int i = 0; i < 15; i++) {
        Counter counter = registry.counter(metricNamePrefix
                + formatter.format(i));
        counter.inc();
    }
    waitForReporter();
    flushAndRefresh();

    SearchResponse searchResponse = nestedAggregationWithTimeout(
            new SearchRequestBuilder(ElasticsearchIntegrationTest.client())
                    .setIndices("_all")
                    .setTypes(MetricElasticsearchTypes.COUNTER)
                    .setQuery(QueryBuilders.matchAllQuery())
                    .setSize(0)
                    .addAggregation(
                            AggregationBuilders
                                    .terms("timestamps")
                                    .size(50)
                                    .field("@timestamp")
                                    .order(Order.term(true))
                                    .subAggregation(
                                            AggregationBuilders
                                                    .terms("names")
                                                    .size(50)
                                                    .field("@name")
                                                    .order(Order.term(true)))),
            15);

    InternalTerms timestamps = searchResponse.getAggregations().get(
            "timestamps");
    Collection<Bucket> timestampBuckets = timestamps.getBuckets();
    Assert.assertEquals(true, timestampBuckets.size() > 0);
    for (Bucket bucket : timestampBuckets) {
        InternalTerms names = bucket.getAggregations().get("names");
        if(names.getBuckets().size() >= 15) {
            for (int i = 0; i < names.getBuckets().size(); i++) {
                Assert.assertEquals(
                        prefix + "." + metricNamePrefix + formatter.format(i),
                        ((Bucket) names.getBuckets().toArray()[i]).getKey());
            }
            return;
        }
    }
    Assert.fail("Insufficient metrics reported");
}
 
開發者ID:tomcashman,項目名稱:metrics-elasticsearch,代碼行數:50,代碼來源:ElasticsearchHttpReporterTest.java

示例13: testReportsGaugeOfType

import org.elasticsearch.test.ElasticsearchIntegrationTest; //導入依賴的package包/類
private <T> void testReportsGaugeOfType(Class<T> type, final T value) {
    String metricName = "com.codahale.metrics.elasticsearch.test.guage."
            + type.getSimpleName().toLowerCase();

    registry.register(metricName, new Gauge<T>() {
        @Override
        public T getValue() {
            return value;
        }
    });

    waitForReporter();
    flushAndRefresh();

    SearchResponse searchResponse = searchWithTimeout(
            new SearchRequestBuilder(ElasticsearchIntegrationTest.client())
                    .setIndices("_all")
                    .setTypes(MetricElasticsearchTypes.GAUGE)
                    .setQuery(
                            QueryBuilders.matchPhraseQuery("@name", prefix
                                    + "." + metricName)), 1);
    Assert.assertEquals(true, searchResponse.getHits().getHits().length > 0);
    Map<String, Object> searchHitSource = searchResponse.getHits()
            .getHits()[0].getSource();
    Assert.assertEquals(prefix + "." + metricName,
            searchHitSource.get("@name"));
    if (value instanceof Float) {
        // Note: Elasticsearch returns Float value as Double
        Assert.assertEquals(Double.valueOf(value.toString()),
                (Double) searchHitSource.get("floatValue"));
    } else if (value instanceof Double) {
        Assert.assertEquals((Double) value,
                (Double) searchHitSource.get("doubleValue"));
    } else if (value instanceof Byte) {
        // Note: Elasticsearch returns Byte value as Integer
        Assert.assertEquals(((Byte) value).intValue(),
                ((Integer) searchHitSource.get("byteValue")).intValue());
    } else if (value instanceof Short) {
        // Note: Elasticsearch returns Short value as Integer
        Assert.assertEquals(((Short) value).intValue(),
                ((Integer) searchHitSource.get("shortValue")).intValue());
    } else if (value instanceof Integer) {
        Assert.assertEquals((Integer) value,
                (Integer) searchHitSource.get("integerValue"));
    } else if (value instanceof Long) {
        Assert.assertEquals((Long) value,
                (Long) searchHitSource.get("longValue"));
    } else {
        Assert.assertEquals((String) value,
                (String) searchHitSource.get("stringValue"));
    }
}
 
開發者ID:tomcashman,項目名稱:metrics-elasticsearch,代碼行數:53,代碼來源:ElasticsearchHttpReporterTest.java


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