Search in sources :

Example 51 with NoneCircuitBreakerService

use of org.opensearch.indices.breaker.NoneCircuitBreakerService in project OpenSearch by opensearch-project.

the class InternalVariableWidthHistogramTests method testSameMinMerge.

/**
 * When buckets have the same min after the reduce phase, they should be merged.
 */
public void testSameMinMerge() {
    InternalVariableWidthHistogram dummy_histogram = createEmptyTestInstance();
    List<InternalVariableWidthHistogram.Bucket> buckets = new ArrayList<>();
    for (long value : new long[] { 1, 100, 700 }) {
        InternalVariableWidthHistogram.Bucket.BucketBounds bounds;
        if (value == 1 || value == 100) {
            bounds = new InternalVariableWidthHistogram.Bucket.BucketBounds(1, value);
        } else {
            bounds = new InternalVariableWidthHistogram.Bucket.BucketBounds(value, value + 1);
        }
        InternalVariableWidthHistogram.Bucket bucket = new InternalVariableWidthHistogram.Bucket(value, bounds, 1, format, InternalAggregations.EMPTY);
        buckets.add(bucket);
    }
    InternalVariableWidthHistogram histogram = dummy_histogram.create(buckets);
    MockBigArrays bigArrays = new MockBigArrays(new MockPageCacheRecycler(Settings.EMPTY), new NoneCircuitBreakerService());
    ScriptService mockScriptService = mockScriptService();
    MultiBucketConsumerService.MultiBucketConsumer bucketConsumer = new MultiBucketConsumerService.MultiBucketConsumer(DEFAULT_MAX_BUCKETS, new NoneCircuitBreakerService().getBreaker(CircuitBreaker.REQUEST));
    InternalAggregation.ReduceContext context = InternalAggregation.ReduceContext.forFinalReduction(bigArrays, mockScriptService, bucketConsumer, PipelineAggregator.PipelineTree.EMPTY);
    ArrayList<InternalAggregation> aggs = new ArrayList<>();
    aggs.add(histogram);
    List<InternalVariableWidthHistogram.Bucket> reduced_buckets = ((InternalVariableWidthHistogram) histogram.reduce(aggs, context)).getBuckets();
    // Expected clusters: [ (1), (100), (700) ]
    // Expected clusters after same min merge: [ (1, 100), (700) ]
    // Expected centroids: [ 101/2, 700 ]
    // Expected keys: [ 1, 700 ]
    // Expected doc counts: [2, 1]
    double double_error = 1d / 10000d;
    assertEquals(2, reduced_buckets.size());
    assertEquals(1d, reduced_buckets.get(0).min(), double_error);
    assertEquals((101d / 2d), (double) reduced_buckets.get(0).getKey(), double_error);
    assertEquals(2, reduced_buckets.get(0).getDocCount());
    assertEquals(700d, reduced_buckets.get(1).min(), double_error);
    assertEquals(700d, (double) reduced_buckets.get(1).getKey(), double_error);
    assertEquals(1, reduced_buckets.get(1).getDocCount());
}
Also used : MockPageCacheRecycler(org.opensearch.common.util.MockPageCacheRecycler) ArrayList(java.util.ArrayList) MockBigArrays(org.opensearch.common.util.MockBigArrays) ScriptService(org.opensearch.script.ScriptService) InternalAggregation(org.opensearch.search.aggregations.InternalAggregation) MultiBucketConsumerService(org.opensearch.search.aggregations.MultiBucketConsumerService) NoneCircuitBreakerService(org.opensearch.indices.breaker.NoneCircuitBreakerService)

Aggregations

NoneCircuitBreakerService (org.opensearch.indices.breaker.NoneCircuitBreakerService)51 MockPageCacheRecycler (org.opensearch.common.util.MockPageCacheRecycler)30 MockBigArrays (org.opensearch.common.util.MockBigArrays)24 NetworkService (org.opensearch.common.network.NetworkService)20 NamedWriteableRegistry (org.opensearch.common.io.stream.NamedWriteableRegistry)15 ArrayList (java.util.ArrayList)14 TestThreadPool (org.opensearch.threadpool.TestThreadPool)14 Before (org.junit.Before)11 MockNioTransport (org.opensearch.transport.nio.MockNioTransport)10 Directory (org.apache.lucene.store.Directory)9 IOException (java.io.IOException)8 ScriptService (org.opensearch.script.ScriptService)8 IndexSearcher (org.apache.lucene.search.IndexSearcher)7 ActionListener (org.opensearch.action.ActionListener)7 InternalAggregation (org.opensearch.search.aggregations.InternalAggregation)7 List (java.util.List)6 IndexReader (org.apache.lucene.index.IndexReader)6 ThreadPool (org.opensearch.threadpool.ThreadPool)6 Collections (java.util.Collections)5 HashSet (java.util.HashSet)5