Search in sources :

Example 1 with MockBigArrays

use of org.opensearch.common.util.MockBigArrays in project OpenSearch by opensearch-project.

the class InternalMatrixStatsTests method testReduceRandom.

@Override
public void testReduceRandom() {
    int numValues = 10000;
    int numShards = randomIntBetween(1, 20);
    int valuesPerShard = (int) Math.floor(numValues / numShards);
    List<Double> aValues = new ArrayList<>();
    List<Double> bValues = new ArrayList<>();
    RunningStats runningStats = new RunningStats();
    List<InternalAggregation> shardResults = new ArrayList<>();
    int valuePerShardCounter = 0;
    for (int i = 0; i < numValues; i++) {
        double valueA = randomDouble();
        aValues.add(valueA);
        double valueB = randomDouble();
        bValues.add(valueB);
        runningStats.add(new String[] { "a", "b" }, new double[] { valueA, valueB });
        if (++valuePerShardCounter == valuesPerShard) {
            shardResults.add(new InternalMatrixStats("_name", 1L, runningStats, null, Collections.emptyMap()));
            runningStats = new RunningStats();
            valuePerShardCounter = 0;
        }
    }
    if (valuePerShardCounter != 0) {
        shardResults.add(new InternalMatrixStats("_name", 1L, runningStats, null, Collections.emptyMap()));
    }
    MultiPassStats multiPassStats = new MultiPassStats("a", "b");
    multiPassStats.computeStats(aValues, bValues);
    ScriptService mockScriptService = mockScriptService();
    MockBigArrays bigArrays = new MockBigArrays(new MockPageCacheRecycler(Settings.EMPTY), new NoneCircuitBreakerService());
    InternalAggregation.ReduceContext context = InternalAggregation.ReduceContext.forFinalReduction(bigArrays, mockScriptService, b -> {
    }, PipelineTree.EMPTY);
    InternalMatrixStats reduced = (InternalMatrixStats) shardResults.get(0).reduce(shardResults, context);
    multiPassStats.assertNearlyEqual(reduced.getResults());
}
Also used : MockPageCacheRecycler(org.opensearch.common.util.MockPageCacheRecycler) ArrayList(java.util.ArrayList) MockBigArrays(org.opensearch.common.util.MockBigArrays) InternalAggregation(org.opensearch.search.aggregations.InternalAggregation) ScriptService(org.opensearch.script.ScriptService) NoneCircuitBreakerService(org.opensearch.indices.breaker.NoneCircuitBreakerService)

Example 2 with MockBigArrays

use of org.opensearch.common.util.MockBigArrays in project OpenSearch by opensearch-project.

the class Netty4HttpServerPipeliningTests method setup.

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

Example 3 with MockBigArrays

use of org.opensearch.common.util.MockBigArrays in project OpenSearch by opensearch-project.

the class ReleasableBytesStreamOutputTests method testRelease.

public void testRelease() throws Exception {
    MockBigArrays mockBigArrays = new MockBigArrays(new MockPageCacheRecycler(Settings.EMPTY), new NoneCircuitBreakerService());
    try (ReleasableBytesStreamOutput output = getRandomReleasableBytesStreamOutput(mockBigArrays)) {
        output.writeBoolean(randomBoolean());
    }
    MockBigArrays.ensureAllArraysAreReleased();
}
Also used : MockPageCacheRecycler(org.opensearch.common.util.MockPageCacheRecycler) MockBigArrays(org.opensearch.common.util.MockBigArrays) NoneCircuitBreakerService(org.opensearch.indices.breaker.NoneCircuitBreakerService)

Example 4 with MockBigArrays

use of org.opensearch.common.util.MockBigArrays in project OpenSearch by opensearch-project.

the class GatewayMetaStatePersistedStateTests method setUp.

@Override
public void setUp() throws Exception {
    bigArrays = new MockBigArrays(new MockPageCacheRecycler(Settings.EMPTY), new NoneCircuitBreakerService());
    nodeEnvironment = newNodeEnvironment();
    localNode = new DiscoveryNode("node1", buildNewFakeTransportAddress(), Collections.emptyMap(), Sets.newHashSet(DiscoveryNodeRole.MASTER_ROLE), Version.CURRENT);
    clusterName = new ClusterName(randomAlphaOfLength(10));
    settings = Settings.builder().put(ClusterName.CLUSTER_NAME_SETTING.getKey(), clusterName.value()).build();
    super.setUp();
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) MockPageCacheRecycler(org.opensearch.common.util.MockPageCacheRecycler) ClusterName(org.opensearch.cluster.ClusterName) MockBigArrays(org.opensearch.common.util.MockBigArrays) NoneCircuitBreakerService(org.opensearch.indices.breaker.NoneCircuitBreakerService)

Example 5 with MockBigArrays

use of org.opensearch.common.util.MockBigArrays in project OpenSearch by opensearch-project.

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);
    final AtomicLong bytes = new AtomicLong(0);
    BestDocsDeferringCollector collector = new BestDocsDeferringCollector(numDocs, new MockBigArrays(new MockPageCacheRecycler(Settings.EMPTY), new NoneCircuitBreakerService()), bytes::addAndGet);
    Set<Integer> deferredCollectedDocIds = new HashSet<>();
    collector.setDeferredCollector(Collections.singleton(testCollector(deferredCollectedDocIds)));
    collector.preCollection();
    indexSearcher.search(termQuery, collector);
    collector.postCollection();
    collector.prepareSelectedBuckets(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) MockPageCacheRecycler(org.opensearch.common.util.MockPageCacheRecycler) Term(org.apache.lucene.index.Term) MockBigArrays(org.opensearch.common.util.MockBigArrays) Document(org.apache.lucene.document.Document) ScoreDoc(org.apache.lucene.search.ScoreDoc) TopDocs(org.apache.lucene.search.TopDocs) AtomicLong(java.util.concurrent.atomic.AtomicLong) 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.opensearch.indices.breaker.NoneCircuitBreakerService) HashSet(java.util.HashSet)

Aggregations

MockBigArrays (org.opensearch.common.util.MockBigArrays)25 MockPageCacheRecycler (org.opensearch.common.util.MockPageCacheRecycler)25 NoneCircuitBreakerService (org.opensearch.indices.breaker.NoneCircuitBreakerService)24 ArrayList (java.util.ArrayList)8 InternalAggregation (org.opensearch.search.aggregations.InternalAggregation)8 TestThreadPool (org.opensearch.threadpool.TestThreadPool)8 ScriptService (org.opensearch.script.ScriptService)7 Before (org.junit.Before)6 NetworkService (org.opensearch.common.network.NetworkService)5 BigArrays (org.opensearch.common.util.BigArrays)5 MultiBucketConsumerService (org.opensearch.search.aggregations.MultiBucketConsumerService)5 IndexReader (org.apache.lucene.index.IndexReader)4 IndexSearcher (org.apache.lucene.search.IndexSearcher)4 Directory (org.apache.lucene.store.Directory)4 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)3 QueryCachingPolicy (org.apache.lucene.search.QueryCachingPolicy)3 Mockito.anyString (org.mockito.Mockito.anyString)3 MappedFieldType (org.opensearch.index.mapper.MappedFieldType)3 QueryShardContext (org.opensearch.index.query.QueryShardContext)3 IndexShard (org.opensearch.index.shard.IndexShard)3