| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package metric |
| 5 |
|
| 6 |
import ( |
| 7 |
"testing" |
| 8 |
|
| 9 |
"github.com/stretchr/testify/assert" |
| 10 |
) |
| 11 |
|
| 12 |
func TestAggregationErr(t *testing.T) { |
| 13 |
t.Run("DropOperation", func(t *testing.T) { |
| 14 |
assert.NoError(t, AggregationDrop{}.err()) |
| 15 |
}) |
| 16 |
|
| 17 |
t.Run("SumOperation", func(t *testing.T) { |
| 18 |
assert.NoError(t, AggregationSum{}.err()) |
| 19 |
}) |
| 20 |
|
| 21 |
t.Run("LastValueOperation", func(t *testing.T) { |
| 22 |
assert.NoError(t, AggregationLastValue{}.err()) |
| 23 |
}) |
| 24 |
|
| 25 |
t.Run("ExplicitBucketHistogramOperation", func(t *testing.T) { |
| 26 |
assert.NoError(t, AggregationExplicitBucketHistogram{}.err()) |
| 27 |
|
| 28 |
assert.NoError(t, AggregationExplicitBucketHistogram{ |
| 29 |
Boundaries: []float64{0}, |
| 30 |
NoMinMax: true, |
| 31 |
}.err()) |
| 32 |
|
| 33 |
assert.NoError(t, AggregationExplicitBucketHistogram{ |
| 34 |
Boundaries: []float64{0, 5, 10, 25, 50, 75, 100, 250, 500, 1000}, |
| 35 |
}.err()) |
| 36 |
}) |
| 37 |
|
| 38 |
t.Run("NonmonotonicHistogramBoundaries", func(t *testing.T) { |
| 39 |
assert.ErrorIs(t, AggregationExplicitBucketHistogram{ |
| 40 |
Boundaries: []float64{2, 1}, |
| 41 |
}.err(), errAgg) |
| 42 |
|
| 43 |
assert.ErrorIs(t, AggregationExplicitBucketHistogram{ |
| 44 |
Boundaries: []float64{0, 1, 2, 1, 3, 4}, |
| 45 |
}.err(), errAgg) |
| 46 |
}) |
| 47 |
|
| 48 |
t.Run("ExponentialHistogramOperation", func(t *testing.T) { |
| 49 |
assert.NoError(t, AggregationBase2ExponentialHistogram{ |
| 50 |
MaxSize: 160, |
| 51 |
MaxScale: 20, |
| 52 |
}.err()) |
| 53 |
|
| 54 |
assert.NoError(t, AggregationBase2ExponentialHistogram{ |
| 55 |
MaxSize: 1, |
| 56 |
NoMinMax: true, |
| 57 |
}.err()) |
| 58 |
|
| 59 |
assert.NoError(t, AggregationBase2ExponentialHistogram{ |
| 60 |
MaxSize: 1024, |
| 61 |
MaxScale: -3, |
| 62 |
}.err()) |
| 63 |
}) |
| 64 |
|
| 65 |
t.Run("InvalidExponentialHistogramOperation", func(t *testing.T) { |
| 66 |
// MazSize must be greater than 0 |
| 67 |
assert.ErrorIs(t, AggregationBase2ExponentialHistogram{}.err(), errAgg) |
| 68 |
|
| 69 |
// MaxScale Must be <=20 |
| 70 |
assert.ErrorIs(t, AggregationBase2ExponentialHistogram{ |
| 71 |
MaxSize: 1, |
| 72 |
MaxScale: 30, |
| 73 |
}.err(), errAgg) |
| 74 |
}) |
| 75 |
} |
| 76 |
|
| 77 |
func TestExplicitBucketHistogramDeepCopy(t *testing.T) { |
| 78 |
const orig = 0.0 |
| 79 |
b := []float64{orig} |
| 80 |
h := AggregationExplicitBucketHistogram{Boundaries: b} |
| 81 |
cpH := h.copy().(AggregationExplicitBucketHistogram) |
| 82 |
b[0] = orig + 1 |
| 83 |
assert.Equal(t, orig, cpH.Boundaries[0], "changing the underlying slice data should not affect the copy") |
| 84 |
} |