-
Notifications
You must be signed in to change notification settings - Fork 38
/
metriccache_test.go
64 lines (47 loc) · 1.67 KB
/
metriccache_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package metricfrequencyprocessor
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/pmetric"
)
func TestEmptyRead(t *testing.T) {
cache := newCache()
result := cache.List("a")
assert.Equal(t, emptyResult, result)
}
func TestSingleRegister(t *testing.T) {
cache := newCache()
cache.Register("a", newDataPoint(timestamp1, 0.0))
result := cache.List("a")
assert.Equal(t, map[pcommon.Timestamp]float64{timestamp1: 0.0}, result)
}
func TestTwoRegistersOfSingleMetric(t *testing.T) {
cache := newCache()
cache.Register("a", newDataPoint(timestamp1, 0.0))
cache.Register("a", newDataPoint(timestamp2, 1.0))
result := cache.List("a")
assert.Equal(t, map[pcommon.Timestamp]float64{timestamp1: 0.0, timestamp2: 1.0}, result)
}
func TestTwoRegistersOnTwoMetrics(t *testing.T) {
cache := newCache()
cache.Register("a", newDataPoint(timestamp1, 0.0))
cache.Register("b", newDataPoint(timestamp2, 1.0))
result1 := cache.List("a")
result2 := cache.List("b")
assert.Equal(t, map[pcommon.Timestamp]float64{timestamp1: 0.0}, result1)
assert.Equal(t, map[pcommon.Timestamp]float64{timestamp2: 1.0}, result2)
}
var emptyResult = make(map[pcommon.Timestamp]float64)
var timestamp1 = pcommon.NewTimestampFromTime(time.Unix(0, 0))
var timestamp2 = pcommon.NewTimestampFromTime(time.Unix(1, 0))
func newCache() *metricCache {
return newMetricCache(createDefaultConfig().(*Config).cacheConfig)
}
func newDataPoint(timestamp pcommon.Timestamp, value float64) pmetric.NumberDataPoint {
result := pmetric.NewNumberDataPoint()
result.SetTimestamp(timestamp)
result.SetDoubleValue(value)
return result
}