Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ private ExponentialHistogramMerger(int bucketLimit, ExponentialHistogramCircuitB

// Only intended for testing, using this in production means an unnecessary reduction of precision
private ExponentialHistogramMerger(int bucketLimit, int maxScale, ExponentialHistogramCircuitBreaker circuitBreaker) {
this.bucketLimit = bucketLimit;
// We need at least four buckets to represent any possible distribution
this.bucketLimit = Math.max(4, bucketLimit);
this.maxScale = maxScale;
this.circuitBreaker = circuitBreaker;
downscaleStats = new DownscaleStats();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,28 @@ public void testUpscalingDoesNotExceedIndexLimits() {
}
}

public void testMinimumBucketCountBounded() {
FixedCapacityExponentialHistogram a = createAutoReleasedHistogram(2);
a.tryAddBucket(-1, 1, false);
a.tryAddBucket(0, 1, false);

FixedCapacityExponentialHistogram b = createAutoReleasedHistogram(2);
b.tryAddBucket(-1, 1, true);
b.tryAddBucket(0, 1, true);

// What we try here is not possible: the provided buckets are not mergeable to three buckets
try (ReleasableExponentialHistogram merged = ExponentialHistogram.merge(3, breaker(), a, b)) {
FixedCapacityExponentialHistogram expectedResult = createAutoReleasedHistogram(4);
expectedResult.tryAddBucket(-1, 1, false);
expectedResult.tryAddBucket(0, 1, false);
expectedResult.tryAddBucket(-1, 1, true);
expectedResult.tryAddBucket(0, 1, true);

assertBucketsEqual(merged.negativeBuckets(), expectedResult.negativeBuckets());
assertBucketsEqual(merged.positiveBuckets(), expectedResult.positiveBuckets());
}
}

/**
* Verify that the resulting histogram is independent of the order of elements and therefore merges performed.
*/
Expand Down