@@ -40,8 +40,9 @@ public void histogramAccumulateQuantities() {
40
40
final CalculatedValue <HistogramStatistic .HistogramSupportingData > value = accumulator .calculate (Collections .emptyMap ());
41
41
final HistogramStatistic .HistogramSupportingData supportingData = value .getData ();
42
42
final HistogramStatistic .HistogramSnapshot histogram = supportingData .getHistogramSnapshot ();
43
+ Assert .assertEquals (100L , histogram .getEntriesCount ());
43
44
for (final Double2LongMap .Entry entry : histogram .getValues ()) {
44
- Assert .assertEquals (entry .getLongValue (), 1L );
45
+ Assert .assertEquals (1L , entry .getLongValue ());
45
46
}
46
47
}
47
48
@@ -59,8 +60,9 @@ public void histogramAccumulateHistogram() {
59
60
final CalculatedValue <HistogramStatistic .HistogramSupportingData > value = merged .calculate (Collections .emptyMap ());
60
61
final HistogramStatistic .HistogramSupportingData supportingData = value .getData ();
61
62
final HistogramStatistic .HistogramSnapshot histogram = supportingData .getHistogramSnapshot ();
63
+ Assert .assertEquals (100L , histogram .getEntriesCount ());
62
64
for (final Double2LongMap .Entry entry : histogram .getValues ()) {
63
- Assert .assertEquals (entry .getLongValue (), 1L );
65
+ Assert .assertEquals (1L , entry .getLongValue ());
64
66
}
65
67
}
66
68
@@ -90,6 +92,7 @@ public void histogramAccumulateMultipleHistogram() {
90
92
final CalculatedValue <HistogramStatistic .HistogramSupportingData > value = merged .calculate (Collections .emptyMap ());
91
93
final HistogramStatistic .HistogramSupportingData supportingData = value .getData ();
92
94
final HistogramStatistic .HistogramSnapshot histogram = supportingData .getHistogramSnapshot ();
95
+ Assert .assertEquals (251L , histogram .getEntriesCount ());
93
96
for (final Double2LongMap .Entry entry : histogram .getValues ()) {
94
97
final int val = (int ) entry .getDoubleKey ();
95
98
if (val < 50 ) {
@@ -104,6 +107,38 @@ public void histogramAccumulateMultipleHistogram() {
104
107
Assert .assertEquals (2000d , histogram .getValueAtPercentile (99.9d ), 1d );
105
108
}
106
109
110
+ /**
111
+ * Check that neither the entries count or bucket values overflow an integer while accumulating.
112
+ */
113
+ @ Test
114
+ public void histogramAccumulateHistogramsCheckNoOverflow () {
115
+ final Accumulator <HistogramStatistic .HistogramSupportingData > merged = HISTOGRAM_STATISTIC .createCalculator ();
116
+
117
+ for (int i = 0 ; i < 3 ; ++i ) {
118
+ final HistogramStatistic .Histogram histogram = new HistogramStatistic .Histogram ();
119
+ histogram .recordValue (0 , 1000000000 );
120
+ final HistogramStatistic .HistogramSupportingData supportingData = new HistogramStatistic .HistogramSupportingData .Builder ()
121
+ .setHistogramSnapshot (histogram .getSnapshot ())
122
+ .build ();
123
+ final CalculatedValue <HistogramStatistic .HistogramSupportingData > calculatedValue =
124
+ new CalculatedValue .Builder <HistogramStatistic .HistogramSupportingData >()
125
+ .setValue (new Quantity .Builder ().setValue ((double ) 1000000000 ).build ())
126
+ .setData (supportingData )
127
+ .build ();
128
+ merged .accumulate (calculatedValue );
129
+ }
130
+
131
+ final CalculatedValue <HistogramStatistic .HistogramSupportingData > value = merged .calculate (Collections .emptyMap ());
132
+ final HistogramStatistic .HistogramSupportingData supportingData = value .getData ();
133
+ final HistogramStatistic .HistogramSnapshot histogram = supportingData .getHistogramSnapshot ();
134
+ Assert .assertEquals (3000000000L , histogram .getEntriesCount ());
135
+ for (final Double2LongMap .Entry entry : histogram .getValues ()) {
136
+ if (entry .getDoubleKey () == 0 ) {
137
+ Assert .assertEquals (3000000000L , entry .getLongValue ());
138
+ }
139
+ }
140
+ }
141
+
107
142
@ Test
108
143
public void histogramQuantityConversion () {
109
144
final Accumulator <HistogramStatistic .HistogramSupportingData > accumulator = HISTOGRAM_STATISTIC .createCalculator ();
@@ -185,6 +220,7 @@ public void histogramUnitConversion() {
185
220
}
186
221
187
222
Assert .assertEquals (99.5d , histogram .getValueAtPercentile (99.9d ), 1d );
223
+ Assert .assertEquals (100 , histogram .getEntriesCount ());
188
224
}
189
225
190
226
@ Test
@@ -199,6 +235,7 @@ public void histogramEnds() {
199
235
200
236
Assert .assertEquals (10d , histogram .getValueAtPercentile (0 ), 1d );
201
237
Assert .assertEquals (50d , histogram .getValueAtPercentile (100 ), 1d );
238
+ Assert .assertEquals (2 , histogram .getEntriesCount ());
202
239
}
203
240
204
241
private static final StatisticFactory STATISTIC_FACTORY = new StatisticFactory ();
0 commit comments