forked from rewardStyle/kinetic
-
Notifications
You must be signed in to change notification settings - Fork 1
/
consumer_stats_test.go
204 lines (162 loc) · 6.38 KB
/
consumer_stats_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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
package kinetic
import (
"math/rand"
"testing"
"time"
metrics "github.com/rcrowley/go-metrics"
. "github.com/smartystreets/goconvey/convey"
)
func init() {
rand.Seed(time.Now().UnixNano())
}
func TestConsumerStatsCollector(t *testing.T) {
Convey("given a NilConsumerStatsCollector", t, func() {
var sc ConsumerStatsCollector = &NilConsumerStatsCollector{}
So(sc, ShouldNotBeNil)
Convey("check that AddConsumed does not error", func() {
sc.AddConsumed(1)
})
Convey("check that AddDelivered does not error", func() {
sc.AddDelivered(1)
})
Convey("check that AddProcessed does not error", func() {
sc.AddProcessed(1)
})
Convey("check that UpdateBatchSize does not error", func() {
sc.UpdateBatchSize(1)
})
Convey("check that AddGetRecordsCalled does not error", func() {
sc.AddGetRecordsCalled(1)
})
Convey("check that AddReadProvisionedThroughputExceeded does not error", func() {
sc.AddReadProvisionedThroughputExceeded(1)
})
Convey("check that AddGetRecordsTimeout does not error", func() {
sc.AddGetRecordsTimeout(1)
})
Convey("check that AddGetRecordsReadTimeout does not error", func() {
sc.AddGetRecordsReadTimeout(1)
})
Convey("check that UpdateProcessedDuration does not error", func() {
sc.UpdateProcessedDuration(1)
})
Convey("check that UpdateGetRecordsDuration does not error", func() {
sc.UpdateGetRecordsDuration(1)
})
Convey("check that UpdateGetRecordsReadResponseDuration does not error", func() {
sc.UpdateGetRecordsReadResponseDuration(1)
})
Convey("check that UpdateGetRecordsUnmarshalDuration does not error", func() {
sc.UpdateGetRecordsUnmarshalDuration(1)
})
Convey("check that AddCheckpointInsert does not error", func() {
sc.AddCheckpointInsert(1)
})
Convey("check that AddCheckpointDone does not error", func() {
sc.AddCheckpointDone(1)
})
Convey("check that UpdateCheckpointSize does not error", func() {
sc.UpdateCheckpointSize(1)
})
Convey("check that AddCheckpointSent does not error", func() {
sc.AddCheckpointSent(1)
})
Convey("check that AddCheckpointSuccess does not error", func() {
sc.AddCheckpointSuccess(1)
})
Convey("check that AddCheckpointError does not error", func() {
sc.AddCheckpointError(1)
})
})
Convey("given a DefaultConsumerStatsCollector", t, func() {
r := metrics.NewRegistry()
var sc ConsumerStatsCollector = NewDefaultConsumerStatsCollector(r)
So(sc, ShouldNotBeNil)
Convey("check that AddConsumed does not error", func() {
count := rand.Int()
sc.AddConsumed(count)
So(sc.(*DefaultConsumerStatsCollector).Consumed.Count(), ShouldEqual, int64(count))
})
Convey("check that AddDelivered does not error", func() {
count := rand.Int()
sc.AddDelivered(count)
So(sc.(*DefaultConsumerStatsCollector).Delivered.Count(), ShouldEqual, int64(count))
})
Convey("check that AddProcessed does not error", func() {
count := rand.Int()
sc.AddProcessed(count)
So(sc.(*DefaultConsumerStatsCollector).Processed.Count(), ShouldEqual, int64(count))
})
Convey("check that UpdateBatchSize does not error", func() {
count := rand.Int()
sc.UpdateBatchSize(count)
So(sc.(*DefaultConsumerStatsCollector).BatchSize.Value(), ShouldEqual, int64(count))
})
Convey("check that AddGetRecordsCalled does not error", func() {
count := rand.Int()
sc.AddGetRecordsCalled(count)
So(sc.(*DefaultConsumerStatsCollector).GetRecordsCalled.Count(), ShouldEqual, int64(count))
})
Convey("check that AddReadProvisionedThroughputExceeded does not error", func() {
count := rand.Int()
sc.AddReadProvisionedThroughputExceeded(count)
So(sc.(*DefaultConsumerStatsCollector).ReadProvisionedThroughputExceeded.Count(), ShouldEqual, int64(count))
})
Convey("check that AddGetRecordsTimeout does not error", func() {
count := rand.Int()
sc.AddGetRecordsTimeout(count)
So(sc.(*DefaultConsumerStatsCollector).GetRecordsTimeout.Count(), ShouldEqual, int64(count))
})
Convey("check that AddGetRecordsReadTimeout does not error", func() {
count := rand.Int()
sc.AddGetRecordsReadTimeout(count)
So(sc.(*DefaultConsumerStatsCollector).GetRecordsReadTimeout.Count(), ShouldEqual, int64(count))
})
Convey("check that UpdateProcessedDuration does not error", func() {
sc.UpdateProcessedDuration(time.Second)
So(sc.(*DefaultConsumerStatsCollector).ProcessedDuration.Value(), ShouldEqual, 1000000000)
})
Convey("check that UpdateGetRecordsDuration does not error", func() {
sc.UpdateGetRecordsDuration(time.Second)
So(sc.(*DefaultConsumerStatsCollector).GetRecordsDuration.Value(), ShouldEqual, 1000000000)
})
Convey("check that UpdateGetRecordsReadResponseDuration does not error", func() {
sc.UpdateGetRecordsReadResponseDuration(time.Second)
So(sc.(*DefaultConsumerStatsCollector).GetRecordsReadResponseDuration.Value(), ShouldEqual, 1000000000)
})
Convey("check that UpdateGetRecordsUnmarshalDuration does not error", func() {
sc.UpdateGetRecordsUnmarshalDuration(time.Second)
So(sc.(*DefaultConsumerStatsCollector).GetRecordsUnmarshalDuration.Value(), ShouldEqual, 1000000000)
})
Convey("check that AddCheckpointInsert does not error", func() {
count := rand.Int()
sc.AddCheckpointInsert(count)
So(sc.(*DefaultConsumerStatsCollector).CheckpointInsert.Count(), ShouldEqual, int64(count))
})
Convey("check that AddCheckpointDone does not error", func() {
count := rand.Int()
sc.AddCheckpointDone(count)
So(sc.(*DefaultConsumerStatsCollector).CheckpointDone.Count(), ShouldEqual, int64(count))
})
Convey("check that UpdateCheckpointSize does not error", func() {
count := rand.Int()
sc.UpdateCheckpointSize(count)
So(sc.(*DefaultConsumerStatsCollector).CheckpointSize.Value(), ShouldEqual, int64(count))
})
Convey("check that AddCheckpointSent does not error", func() {
count := rand.Int()
sc.AddCheckpointSent(count)
So(sc.(*DefaultConsumerStatsCollector).CheckpointSent.Count(), ShouldEqual, int64(count))
})
Convey("check that AddCheckpointSuccess does not error", func() {
count := rand.Int()
sc.AddCheckpointSuccess(count)
So(sc.(*DefaultConsumerStatsCollector).CheckpointSuccess.Count(), ShouldEqual, int64(count))
})
Convey("check that AddCheckpointError does not error", func() {
count := rand.Int()
sc.AddCheckpointError(count)
So(sc.(*DefaultConsumerStatsCollector).CheckpointError.Count(), ShouldEqual, int64(count))
})
})
}