Search in sources :

Example 1 with MockBigArrays

use of org.elasticsearch.common.util.MockBigArrays in project elasticsearch by elastic.

the class AggregatorTestCase method createAggregator.

protected <A extends Aggregator, B extends AggregationBuilder> A createAggregator(B aggregationBuilder, IndexSearcher indexSearcher, MappedFieldType... fieldTypes) throws IOException {
    IndexSettings indexSettings = createIndexSettings();
    SearchContext searchContext = createSearchContext(indexSearcher, indexSettings);
    CircuitBreakerService circuitBreakerService = new NoneCircuitBreakerService();
    when(searchContext.bigArrays()).thenReturn(new MockBigArrays(Settings.EMPTY, circuitBreakerService));
    // TODO: now just needed for top_hits, this will need to be revised for other agg unit tests:
    MapperService mapperService = mapperServiceMock();
    when(mapperService.hasNested()).thenReturn(false);
    when(searchContext.mapperService()).thenReturn(mapperService);
    IndexFieldDataService ifds = new IndexFieldDataService(indexSettings, new IndicesFieldDataCache(Settings.EMPTY, new IndexFieldDataCache.Listener() {
    }), circuitBreakerService, mapperService);
    when(searchContext.fieldData()).thenReturn(ifds);
    SearchLookup searchLookup = new SearchLookup(mapperService, ifds, new String[] { "type" });
    when(searchContext.lookup()).thenReturn(searchLookup);
    QueryShardContext queryShardContext = queryShardContextMock(fieldTypes, indexSettings, circuitBreakerService);
    when(searchContext.getQueryShardContext()).thenReturn(queryShardContext);
    @SuppressWarnings("unchecked") A aggregator = (A) aggregationBuilder.build(searchContext, null).create(null, true);
    return aggregator;
}
Also used : IndexSettings(org.elasticsearch.index.IndexSettings) SearchContext(org.elasticsearch.search.internal.SearchContext) MockBigArrays(org.elasticsearch.common.util.MockBigArrays) IndicesFieldDataCache(org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache) IndexFieldDataService(org.elasticsearch.index.fielddata.IndexFieldDataService) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) CircuitBreakerService(org.elasticsearch.indices.breaker.CircuitBreakerService) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) MapperService(org.elasticsearch.index.mapper.MapperService) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) SearchLookup(org.elasticsearch.search.lookup.SearchLookup)

Example 2 with MockBigArrays

use of org.elasticsearch.common.util.MockBigArrays in project elasticsearch by elastic.

the class TermsAggregatorTests method testMixLongAndDouble.

public void testMixLongAndDouble() throws Exception {
    for (TermsAggregatorFactory.ExecutionMode executionMode : TermsAggregatorFactory.ExecutionMode.values()) {
        TermsAggregationBuilder aggregationBuilder = new TermsAggregationBuilder("_name", ValueType.LONG).executionHint(executionMode.toString()).field("number").order(Terms.Order.term(true));
        List<InternalAggregation> aggs = new ArrayList<>();
        int numLongs = randomIntBetween(1, 3);
        for (int i = 0; i < numLongs; i++) {
            final Directory dir;
            try (IndexReader reader = createIndexWithLongs()) {
                dir = ((DirectoryReader) reader).directory();
                IndexSearcher searcher = new IndexSearcher(reader);
                MappedFieldType fieldType = new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.LONG);
                fieldType.setName("number");
                fieldType.setHasDocValues(true);
                aggs.add(buildInternalAggregation(aggregationBuilder, fieldType, searcher));
            }
            dir.close();
        }
        int numDoubles = randomIntBetween(1, 3);
        for (int i = 0; i < numDoubles; i++) {
            final Directory dir;
            try (IndexReader reader = createIndexWithDoubles()) {
                dir = ((DirectoryReader) reader).directory();
                IndexSearcher searcher = new IndexSearcher(reader);
                MappedFieldType fieldType = new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.DOUBLE);
                fieldType.setName("number");
                fieldType.setHasDocValues(true);
                aggs.add(buildInternalAggregation(aggregationBuilder, fieldType, searcher));
            }
            dir.close();
        }
        InternalAggregation.ReduceContext ctx = new InternalAggregation.ReduceContext(new MockBigArrays(Settings.EMPTY, new NoneCircuitBreakerService()), null, true);
        for (InternalAggregation internalAgg : aggs) {
            InternalAggregation mergedAggs = internalAgg.doReduce(aggs, ctx);
            assertTrue(mergedAggs instanceof DoubleTerms);
            long expected = numLongs + numDoubles;
            List<Terms.Bucket> buckets = ((DoubleTerms) mergedAggs).getBuckets();
            assertEquals(4, buckets.size());
            assertEquals("1.0", buckets.get(0).getKeyAsString());
            assertEquals(expected, buckets.get(0).getDocCount());
            assertEquals("10.0", buckets.get(1).getKeyAsString());
            assertEquals(expected * 2, buckets.get(1).getDocCount());
            assertEquals("100.0", buckets.get(2).getKeyAsString());
            assertEquals(expected * 2, buckets.get(2).getDocCount());
            assertEquals("1000.0", buckets.get(3).getKeyAsString());
            assertEquals(expected, buckets.get(3).getDocCount());
        }
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) ArrayList(java.util.ArrayList) MockBigArrays(org.elasticsearch.common.util.MockBigArrays) InternalAggregation(org.elasticsearch.search.aggregations.InternalAggregation) IndexReader(org.apache.lucene.index.IndexReader) MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType) Directory(org.apache.lucene.store.Directory) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService)

Example 3 with MockBigArrays

use of org.elasticsearch.common.util.MockBigArrays in project elasticsearch by elastic.

the class Netty4HttpServerTransportTests method setup.

@Before
public void setup() throws Exception {
    networkService = new NetworkService(Settings.EMPTY, Collections.emptyList());
    threadPool = new TestThreadPool("test");
    bigArrays = new MockBigArrays(Settings.EMPTY, new NoneCircuitBreakerService());
}
Also used : NetworkService(org.elasticsearch.common.network.NetworkService) MockBigArrays(org.elasticsearch.common.util.MockBigArrays) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) Before(org.junit.Before)

Example 4 with MockBigArrays

use of org.elasticsearch.common.util.MockBigArrays in project elasticsearch by elastic.

the class Netty4HttpServerPipeliningTests method setup.

@Before
public void setup() throws Exception {
    networkService = new NetworkService(Settings.EMPTY, Collections.emptyList());
    threadPool = new TestThreadPool("test");
    bigArrays = new MockBigArrays(Settings.EMPTY, new NoneCircuitBreakerService());
}
Also used : NetworkService(org.elasticsearch.common.network.NetworkService) MockBigArrays(org.elasticsearch.common.util.MockBigArrays) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) Before(org.junit.Before)

Example 5 with MockBigArrays

use of org.elasticsearch.common.util.MockBigArrays in project elasticsearch by elastic.

the class Netty4SizeHeaderFrameDecoderTests method startThreadPool.

@Before
public void startThreadPool() {
    threadPool = new ThreadPool(settings);
    NetworkService networkService = new NetworkService(settings, Collections.emptyList());
    BigArrays bigArrays = new MockBigArrays(Settings.EMPTY, new NoneCircuitBreakerService());
    nettyTransport = new Netty4Transport(settings, threadPool, networkService, bigArrays, new NamedWriteableRegistry(Collections.emptyList()), new NoneCircuitBreakerService());
    nettyTransport.start();
    TransportAddress[] boundAddresses = nettyTransport.boundAddress().boundAddresses();
    TransportAddress transportAddress = (TransportAddress) randomFrom(boundAddresses);
    port = transportAddress.address().getPort();
    host = transportAddress.address().getAddress();
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) BigArrays(org.elasticsearch.common.util.BigArrays) MockBigArrays(org.elasticsearch.common.util.MockBigArrays) TransportAddress(org.elasticsearch.common.transport.TransportAddress) ThreadPool(org.elasticsearch.threadpool.ThreadPool) NetworkService(org.elasticsearch.common.network.NetworkService) MockBigArrays(org.elasticsearch.common.util.MockBigArrays) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) Before(org.junit.Before)

Aggregations

MockBigArrays (org.elasticsearch.common.util.MockBigArrays)9 NoneCircuitBreakerService (org.elasticsearch.indices.breaker.NoneCircuitBreakerService)9 NetworkService (org.elasticsearch.common.network.NetworkService)5 Before (org.junit.Before)4 TestThreadPool (org.elasticsearch.threadpool.TestThreadPool)3 ArrayList (java.util.ArrayList)2 IndexReader (org.apache.lucene.index.IndexReader)2 IndexSearcher (org.apache.lucene.search.IndexSearcher)2 Directory (org.apache.lucene.store.Directory)2 NamedWriteableRegistry (org.elasticsearch.common.io.stream.NamedWriteableRegistry)2 BigArrays (org.elasticsearch.common.util.BigArrays)2 HashSet (java.util.HashSet)1 Document (org.apache.lucene.document.Document)1 StringField (org.apache.lucene.document.StringField)1 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)1 Term (org.apache.lucene.index.Term)1 ScoreDoc (org.apache.lucene.search.ScoreDoc)1 TermQuery (org.apache.lucene.search.TermQuery)1 TopDocs (org.apache.lucene.search.TopDocs)1 TransportAddress (org.elasticsearch.common.transport.TransportAddress)1