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());
}
Aggregations