Search in sources :

Example 6 with MockBigArrays

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

the class NettyTransportMultiPortTests method startTransport.

private TcpTransport<?> startTransport(Settings settings, ThreadPool threadPool) {
    BigArrays bigArrays = new MockBigArrays(Settings.EMPTY, new NoneCircuitBreakerService());
    TcpTransport<?> transport = new Netty4Transport(settings, threadPool, new NetworkService(settings, Collections.emptyList()), bigArrays, new NamedWriteableRegistry(Collections.emptyList()), new NoneCircuitBreakerService());
    transport.start();
    assertThat(transport.lifecycleState(), is(Lifecycle.State.STARTED));
    return transport;
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) BigArrays(org.elasticsearch.common.util.BigArrays) MockBigArrays(org.elasticsearch.common.util.MockBigArrays) NetworkService(org.elasticsearch.common.network.NetworkService) MockBigArrays(org.elasticsearch.common.util.MockBigArrays) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService)

Example 7 with MockBigArrays

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

the class Netty4HttpChannelTests 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 8 with MockBigArrays

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

the class BestDocsDeferringCollectorTests method testReplay.

public void testReplay() throws Exception {
    Directory directory = newDirectory();
    RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory);
    int numDocs = randomIntBetween(1, 128);
    int maxNumValues = randomInt(16);
    for (int i = 0; i < numDocs; i++) {
        Document document = new Document();
        document.add(new StringField("field", String.valueOf(randomInt(maxNumValues)), Field.Store.NO));
        indexWriter.addDocument(document);
    }
    indexWriter.close();
    IndexReader indexReader = DirectoryReader.open(directory);
    IndexSearcher indexSearcher = new IndexSearcher(indexReader);
    TermQuery termQuery = new TermQuery(new Term("field", String.valueOf(randomInt(maxNumValues))));
    TopDocs topDocs = indexSearcher.search(termQuery, numDocs);
    BestDocsDeferringCollector collector = new BestDocsDeferringCollector(numDocs, new MockBigArrays(Settings.EMPTY, new NoneCircuitBreakerService()));
    Set<Integer> deferredCollectedDocIds = new HashSet<>();
    collector.setDeferredCollector(Collections.singleton(testCollector(deferredCollectedDocIds)));
    collector.preCollection();
    indexSearcher.search(termQuery, collector);
    collector.postCollection();
    collector.replay(0);
    assertEquals(topDocs.scoreDocs.length, deferredCollectedDocIds.size());
    for (ScoreDoc scoreDoc : topDocs.scoreDocs) {
        assertTrue("expected docid [" + scoreDoc.doc + "] is missing", deferredCollectedDocIds.contains(scoreDoc.doc));
    }
    collector.close();
    indexReader.close();
    directory.close();
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) TermQuery(org.apache.lucene.search.TermQuery) Term(org.apache.lucene.index.Term) MockBigArrays(org.elasticsearch.common.util.MockBigArrays) Document(org.apache.lucene.document.Document) ScoreDoc(org.apache.lucene.search.ScoreDoc) TopDocs(org.apache.lucene.search.TopDocs) StringField(org.apache.lucene.document.StringField) IndexReader(org.apache.lucene.index.IndexReader) RandomIndexWriter(org.apache.lucene.index.RandomIndexWriter) Directory(org.apache.lucene.store.Directory) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) HashSet(java.util.HashSet)

Example 9 with MockBigArrays

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

the class InternalAggregationTestCase method testReduceRandom.

public final void testReduceRandom() {
    String name = randomAsciiOfLength(5);
    List<T> inputs = new ArrayList<>();
    List<InternalAggregation> toReduce = new ArrayList<>();
    int toReduceSize = between(1, 200);
    for (int i = 0; i < toReduceSize; i++) {
        T t = randomBoolean() ? createUnmappedInstance(name) : createTestInstance(name);
        inputs.add(t);
        toReduce.add(t);
    }
    ScriptService mockScriptService = mockScriptService();
    MockBigArrays bigArrays = new MockBigArrays(Settings.EMPTY, new NoneCircuitBreakerService());
    if (randomBoolean() && toReduce.size() > 1) {
        Collections.shuffle(toReduce, random());
        // we leave at least one element in the list
        int r = Math.max(1, randomIntBetween(0, toReduceSize - 2));
        List<InternalAggregation> internalAggregations = toReduce.subList(0, r);
        InternalAggregation.ReduceContext context = new InternalAggregation.ReduceContext(bigArrays, mockScriptService, false);
        @SuppressWarnings("unchecked") T reduced = (T) inputs.get(0).reduce(internalAggregations, context);
        toReduce = toReduce.subList(r, toReduceSize);
        toReduce.add(reduced);
    }
    InternalAggregation.ReduceContext context = new InternalAggregation.ReduceContext(bigArrays, mockScriptService, true);
    @SuppressWarnings("unchecked") T reduced = (T) inputs.get(0).reduce(toReduce, context);
    assertReduced(reduced, inputs);
}
Also used : ArrayList(java.util.ArrayList) MockBigArrays(org.elasticsearch.common.util.MockBigArrays) ScriptService(org.elasticsearch.script.ScriptService) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService)

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