@@ -15,6 +15,7 @@ import (
15
15
"github.com/stretchr/testify/require"
16
16
17
17
"go.opentelemetry.io/collector/component/componenttest"
18
+ "go.opentelemetry.io/collector/exporter/exporterhelper/internal/request"
18
19
)
19
20
20
21
type sizerInt64 struct {}
@@ -24,7 +25,9 @@ func (s sizerInt64) Sizeof(el int64) int64 {
24
25
}
25
26
26
27
func TestMemoryQueue (t * testing.T ) {
27
- q := newMemoryQueue [int64 ](Settings [int64 ]{Sizer : sizerInt64 {}, Capacity : 7 })
28
+ set := newSettings (request .SizerTypeItems , 7 )
29
+ q := newMemoryQueue [int64 ](set )
30
+ require .NoError (t , q .Start (context .Background (), componenttest .NewNopHost ()))
28
31
require .NoError (t , q .Offer (context .Background (), 1 ))
29
32
assert .EqualValues (t , 1 , q .Size ())
30
33
assert .EqualValues (t , 7 , q .Capacity ())
@@ -50,10 +53,14 @@ func TestMemoryQueue(t *testing.T) {
50
53
51
54
require .NoError (t , q .Shutdown (context .Background ()))
52
55
assert .False (t , consume (q , func (context.Context , int64 ) error { t .FailNow (); return nil }))
56
+ require .NoError (t , q .Shutdown (context .Background ()))
53
57
}
54
58
55
59
func TestMemoryQueueBlockingCancelled (t * testing.T ) {
56
- q := newMemoryQueue [int64 ](Settings [int64 ]{Sizer : sizerInt64 {}, Capacity : 5 , BlockOnOverflow : true })
60
+ set := newSettings (request .SizerTypeItems , 5 )
61
+ set .BlockOnOverflow = true
62
+ q := newMemoryQueue [int64 ](set )
63
+ require .NoError (t , q .Start (context .Background (), componenttest .NewNopHost ()))
57
64
require .NoError (t , q .Offer (context .Background (), 3 ))
58
65
ctx , cancel := context .WithCancel (context .Background ())
59
66
wg := sync.WaitGroup {}
@@ -73,7 +80,9 @@ func TestMemoryQueueBlockingCancelled(t *testing.T) {
73
80
}
74
81
75
82
func TestMemoryQueueDrainWhenShutdown (t * testing.T ) {
76
- q := newMemoryQueue [int64 ](Settings [int64 ]{Sizer : sizerInt64 {}, Capacity : 7 })
83
+ set := newSettings (request .SizerTypeItems , 7 )
84
+ q := newMemoryQueue [int64 ](set )
85
+ require .NoError (t , q .Start (context .Background (), componenttest .NewNopHost ()))
77
86
require .NoError (t , q .Offer (context .Background (), 1 ))
78
87
require .NoError (t , q .Offer (context .Background (), 3 ))
79
88
@@ -90,28 +99,40 @@ func TestMemoryQueueDrainWhenShutdown(t *testing.T) {
90
99
}))
91
100
assert .EqualValues (t , 0 , q .Size ())
92
101
assert .False (t , consume (q , func (context.Context , int64 ) error { t .FailNow (); return nil }))
102
+ require .NoError (t , q .Shutdown (context .Background ()))
93
103
}
94
104
95
105
func TestMemoryQueueOfferInvalidSize (t * testing.T ) {
96
- q := newMemoryQueue [int64 ](Settings [int64 ]{Sizer : sizerInt64 {}, Capacity : 1 })
106
+ set := newSettings (request .SizerTypeItems , 1 )
107
+ q := newMemoryQueue [int64 ](set )
108
+ require .NoError (t , q .Start (context .Background (), componenttest .NewNopHost ()))
97
109
require .ErrorIs (t , q .Offer (context .Background (), - 1 ), errInvalidSize )
110
+ require .NoError (t , q .Shutdown (context .Background ()))
98
111
}
99
112
100
113
func TestMemoryQueueRejectOverCapacityElements (t * testing.T ) {
101
- q := newMemoryQueue [int64 ](Settings [int64 ]{Sizer : sizerInt64 {}, Capacity : 7 , BlockOnOverflow : true })
114
+ set := newSettings (request .SizerTypeItems , 1 )
115
+ set .BlockOnOverflow = true
116
+ q := newMemoryQueue [int64 ](set )
117
+ require .NoError (t , q .Start (context .Background (), componenttest .NewNopHost ()))
102
118
require .ErrorIs (t , q .Offer (context .Background (), 8 ), errSizeTooLarge )
119
+ require .NoError (t , q .Shutdown (context .Background ()))
103
120
}
104
121
105
122
func TestMemoryQueueOfferZeroSize (t * testing.T ) {
106
- q := newMemoryQueue [int64 ](Settings [int64 ]{Sizer : sizerInt64 {}, Capacity : 1 })
123
+ set := newSettings (request .SizerTypeItems , 1 )
124
+ q := newMemoryQueue [int64 ](set )
125
+ require .NoError (t , q .Start (context .Background (), componenttest .NewNopHost ()))
107
126
require .NoError (t , q .Offer (context .Background (), 0 ))
108
127
require .NoError (t , q .Shutdown (context .Background ()))
109
128
// Because the size 0 is ignored, nothing to drain.
110
129
assert .False (t , consume (q , func (context.Context , int64 ) error { t .FailNow (); return nil }))
111
130
}
112
131
113
- func TestMemoryQueueZeroCapacity (t * testing.T ) {
114
- q := newMemoryQueue [int64 ](Settings [int64 ]{Sizer : sizerInt64 {}, Capacity : 1 })
132
+ func TestMemoryQueueOverflow (t * testing.T ) {
133
+ set := newSettings (request .SizerTypeItems , 1 )
134
+ q := newMemoryQueue [int64 ](set )
135
+ require .NoError (t , q .Start (context .Background (), componenttest .NewNopHost ()))
115
136
require .NoError (t , q .Offer (context .Background (), 1 ))
116
137
require .ErrorIs (t , q .Offer (context .Background (), 1 ), ErrQueueIsFull )
117
138
require .NoError (t , q .Shutdown (context .Background ()))
@@ -120,7 +141,9 @@ func TestMemoryQueueZeroCapacity(t *testing.T) {
120
141
func TestMemoryQueueWaitForResultPassErrorBack (t * testing.T ) {
121
142
wg := sync.WaitGroup {}
122
143
myErr := errors .New ("test error" )
123
- q := newMemoryQueue [int64 ](Settings [int64 ]{Sizer : sizerInt64 {}, Capacity : 100 , WaitForResult : true })
144
+ set := newSettings (request .SizerTypeItems , 100 )
145
+ set .WaitForResult = true
146
+ q := newMemoryQueue [int64 ](set )
124
147
require .NoError (t , q .Start (context .Background (), componenttest .NewNopHost ()))
125
148
wg .Add (1 )
126
149
go func () {
@@ -138,7 +161,9 @@ func TestMemoryQueueWaitForResultPassErrorBack(t *testing.T) {
138
161
func TestMemoryQueueWaitForResultCancelIncomingRequest (t * testing.T ) {
139
162
wg := sync.WaitGroup {}
140
163
stop := make (chan struct {})
141
- q := newMemoryQueue [int64 ](Settings [int64 ]{Sizer : sizerInt64 {}, Capacity : 100 , WaitForResult : true })
164
+ set := newSettings (request .SizerTypeItems , 100 )
165
+ set .WaitForResult = true
166
+ q := newMemoryQueue [int64 ](set )
142
167
require .NoError (t , q .Start (context .Background (), componenttest .NewNopHost ()))
143
168
144
169
// Consume async new data.
@@ -167,7 +192,9 @@ func TestMemoryQueueWaitForResultCancelIncomingRequest(t *testing.T) {
167
192
func TestMemoryQueueWaitForResultSizeAndCapacity (t * testing.T ) {
168
193
wg := sync.WaitGroup {}
169
194
stop := make (chan struct {})
170
- q := newMemoryQueue [int64 ](Settings [int64 ]{Sizer : sizerInt64 {}, Capacity : 100 , WaitForResult : true })
195
+ set := newSettings (request .SizerTypeItems , 100 )
196
+ set .WaitForResult = true
197
+ q := newMemoryQueue [int64 ](set )
171
198
require .NoError (t , q .Start (context .Background (), componenttest .NewNopHost ()))
172
199
173
200
// Consume async new data.
@@ -197,7 +224,9 @@ func TestMemoryQueueWaitForResultSizeAndCapacity(t *testing.T) {
197
224
func BenchmarkMemoryQueueWaitForResult (b * testing.B ) {
198
225
wg := sync.WaitGroup {}
199
226
consumed := & atomic.Int64 {}
200
- q := newMemoryQueue [int64 ](Settings [int64 ]{Sizer : sizerInt64 {}, Capacity : 1000 , WaitForResult : true })
227
+ set := newSettings (request .SizerTypeItems , 100 )
228
+ set .WaitForResult = true
229
+ q := newMemoryQueue [int64 ](set )
201
230
require .NoError (b , q .Start (context .Background (), componenttest .NewNopHost ()))
202
231
203
232
// Consume async new data.
0 commit comments