-
Notifications
You must be signed in to change notification settings - Fork 18
/
mock_sink.go
51 lines (43 loc) · 1.18 KB
/
mock_sink.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
package stats
import "sync"
// MockSink describes an in-memory Sink used for testing.
//
// DEPRECATED: use "github.com/lyft/gostats/mock" instead.
type MockSink struct {
Counters map[string]uint64
Timers map[string]uint64
Gauges map[string]uint64
cLock sync.Mutex
tLock sync.Mutex
gLock sync.Mutex
}
// NewMockSink returns a MockSink that flushes stats to in-memory maps. An
// instance of MockSink is not safe for concurrent use.
//
// DEPRECATED: use "github.com/lyft/gostats/mock" instead.
func NewMockSink() (m *MockSink) {
m = &MockSink{
Counters: make(map[string]uint64),
Timers: make(map[string]uint64),
Gauges: make(map[string]uint64),
}
return
}
// FlushCounter satisfies the Sink interface.
func (m *MockSink) FlushCounter(name string, value uint64) {
m.cLock.Lock()
defer m.cLock.Unlock()
m.Counters[name] += value
}
// FlushGauge satisfies the Sink interface.
func (m *MockSink) FlushGauge(name string, value uint64) {
m.gLock.Lock()
defer m.gLock.Unlock()
m.Gauges[name] = value
}
// FlushTimer satisfies the Sink interface.
func (m *MockSink) FlushTimer(name string, value float64) { //nolint:revive
m.tLock.Lock()
defer m.tLock.Unlock()
m.Timers[name]++
}