@@ -19,6 +19,7 @@ package statistics
19
19
import (
20
20
"math/rand"
21
21
"testing"
22
+ "time"
22
23
23
24
"github.com/stretchr/testify/require"
24
25
"go.opentelemetry.io/otel"
@@ -143,3 +144,69 @@ func TestEventsBroken(t *testing.T) {
143
144
})
144
145
}
145
146
}
147
+
148
+ func TestBytesAPISent (t * testing.T ) {
149
+ for _ , tt := range tests {
150
+ t .Run (tt .name , func (* testing.T ) {
151
+ stats , err := NewStatistics (tt .meter )
152
+ require .Nil (t , err )
153
+ v := uint64 (rand .Int ())
154
+ stats .BytesAPISentAdd (v )
155
+ assert .Equal (t , v , stats .BytesAPISent ())
156
+ })
157
+ }
158
+ }
159
+
160
+ func TestBytesAPIAccepted (t * testing.T ) {
161
+ for _ , tt := range tests {
162
+ t .Run (tt .name , func (* testing.T ) {
163
+ stats , err := NewStatistics (tt .meter )
164
+ require .Nil (t , err )
165
+ v := uint64 (rand .Int ())
166
+ stats .BytesAPIAcceptedAdd (v )
167
+ assert .Equal (t , v , stats .BytesAPIAccepted ())
168
+ })
169
+ }
170
+ }
171
+
172
+ func TestExport (t * testing.T ) {
173
+ stats , err := NewStatistics (nil )
174
+ require .Nil (t , err )
175
+
176
+ stats .BuffersEnqueuedAdd (1000 )
177
+ stats .BuffersProcessedAdd (100 )
178
+ stats .BuffersDroppedAdd (10 )
179
+ stats .BuffersBrokenAdd (1 )
180
+
181
+ stats .EventsEnqueuedAdd (2000 )
182
+ stats .EventsProcessedAdd (200 )
183
+ stats .EventsDroppedAdd (20 )
184
+ stats .EventsBrokenAdd (2 )
185
+
186
+ stats .BytesAPISentAdd (3000 )
187
+ stats .BytesAPIAcceptedAdd (300 )
188
+
189
+ exp := stats .Export (time .Second )
190
+ assert .Equal (t , & ExportedStatistics {
191
+ Buffers : QueueStats {
192
+ enqueued : 1000 ,
193
+ processed : 100 ,
194
+ dropped : 10 ,
195
+ broken : 1 ,
196
+ processingTime : time .Second ,
197
+ },
198
+ Events : QueueStats {
199
+ enqueued : 2000 ,
200
+ processed : 200 ,
201
+ dropped : 20 ,
202
+ broken : 2 ,
203
+ processingTime : time .Second ,
204
+ },
205
+ Transfer : TransferStats {
206
+ bytesSent : 3000 ,
207
+ bytesAccepted : 300 ,
208
+ buffersProcessed : 100 ,
209
+ processingTime : time .Second ,
210
+ },
211
+ }, exp )
212
+ }
0 commit comments