@@ -15,16 +15,13 @@ 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
- type sizerInt64 struct {}
21
-
22
- func (s sizerInt64 ) Sizeof (el int64 ) int64 {
23
- return el
24
- }
25
-
26
21
func TestMemoryQueue (t * testing.T ) {
27
- q := newMemoryQueue [int64 ](Settings [int64 ]{Sizer : sizerInt64 {}, Capacity : 7 })
22
+ set := newSettings (request .SizerTypeItems , 7 )
23
+ q := newMemoryQueue [int64 ](set )
24
+ require .NoError (t , q .Start (context .Background (), componenttest .NewNopHost ()))
28
25
require .NoError (t , q .Offer (context .Background (), 1 ))
29
26
assert .EqualValues (t , 1 , q .Size ())
30
27
assert .EqualValues (t , 7 , q .Capacity ())
@@ -50,10 +47,14 @@ func TestMemoryQueue(t *testing.T) {
50
47
51
48
require .NoError (t , q .Shutdown (context .Background ()))
52
49
assert .False (t , consume (q , func (context.Context , int64 ) error { t .FailNow (); return nil }))
50
+ require .NoError (t , q .Shutdown (context .Background ()))
53
51
}
54
52
55
53
func TestMemoryQueueBlockingCancelled (t * testing.T ) {
56
- q := newMemoryQueue [int64 ](Settings [int64 ]{Sizer : sizerInt64 {}, Capacity : 5 , BlockOnOverflow : true })
54
+ set := newSettings (request .SizerTypeItems , 5 )
55
+ set .BlockOnOverflow = true
56
+ q := newMemoryQueue [int64 ](set )
57
+ require .NoError (t , q .Start (context .Background (), componenttest .NewNopHost ()))
57
58
require .NoError (t , q .Offer (context .Background (), 3 ))
58
59
ctx , cancel := context .WithCancel (context .Background ())
59
60
wg := sync.WaitGroup {}
@@ -73,7 +74,9 @@ func TestMemoryQueueBlockingCancelled(t *testing.T) {
73
74
}
74
75
75
76
func TestMemoryQueueDrainWhenShutdown (t * testing.T ) {
76
- q := newMemoryQueue [int64 ](Settings [int64 ]{Sizer : sizerInt64 {}, Capacity : 7 })
77
+ set := newSettings (request .SizerTypeItems , 7 )
78
+ q := newMemoryQueue [int64 ](set )
79
+ require .NoError (t , q .Start (context .Background (), componenttest .NewNopHost ()))
77
80
require .NoError (t , q .Offer (context .Background (), 1 ))
78
81
require .NoError (t , q .Offer (context .Background (), 3 ))
79
82
@@ -90,28 +93,40 @@ func TestMemoryQueueDrainWhenShutdown(t *testing.T) {
90
93
}))
91
94
assert .EqualValues (t , 0 , q .Size ())
92
95
assert .False (t , consume (q , func (context.Context , int64 ) error { t .FailNow (); return nil }))
96
+ require .NoError (t , q .Shutdown (context .Background ()))
93
97
}
94
98
95
99
func TestMemoryQueueOfferInvalidSize (t * testing.T ) {
96
- q := newMemoryQueue [int64 ](Settings [int64 ]{Sizer : sizerInt64 {}, Capacity : 1 })
100
+ set := newSettings (request .SizerTypeItems , 1 )
101
+ q := newMemoryQueue [int64 ](set )
102
+ require .NoError (t , q .Start (context .Background (), componenttest .NewNopHost ()))
97
103
require .ErrorIs (t , q .Offer (context .Background (), - 1 ), errInvalidSize )
104
+ require .NoError (t , q .Shutdown (context .Background ()))
98
105
}
99
106
100
107
func TestMemoryQueueRejectOverCapacityElements (t * testing.T ) {
101
- q := newMemoryQueue [int64 ](Settings [int64 ]{Sizer : sizerInt64 {}, Capacity : 7 , BlockOnOverflow : true })
108
+ set := newSettings (request .SizerTypeItems , 1 )
109
+ set .BlockOnOverflow = true
110
+ q := newMemoryQueue [int64 ](set )
111
+ require .NoError (t , q .Start (context .Background (), componenttest .NewNopHost ()))
102
112
require .ErrorIs (t , q .Offer (context .Background (), 8 ), errSizeTooLarge )
113
+ require .NoError (t , q .Shutdown (context .Background ()))
103
114
}
104
115
105
116
func TestMemoryQueueOfferZeroSize (t * testing.T ) {
106
- q := newMemoryQueue [int64 ](Settings [int64 ]{Sizer : sizerInt64 {}, Capacity : 1 })
117
+ set := newSettings (request .SizerTypeItems , 1 )
118
+ q := newMemoryQueue [int64 ](set )
119
+ require .NoError (t , q .Start (context .Background (), componenttest .NewNopHost ()))
107
120
require .NoError (t , q .Offer (context .Background (), 0 ))
108
121
require .NoError (t , q .Shutdown (context .Background ()))
109
122
// Because the size 0 is ignored, nothing to drain.
110
123
assert .False (t , consume (q , func (context.Context , int64 ) error { t .FailNow (); return nil }))
111
124
}
112
125
113
- func TestMemoryQueueZeroCapacity (t * testing.T ) {
114
- q := newMemoryQueue [int64 ](Settings [int64 ]{Sizer : sizerInt64 {}, Capacity : 1 })
126
+ func TestMemoryQueueOverflow (t * testing.T ) {
127
+ set := newSettings (request .SizerTypeItems , 1 )
128
+ q := newMemoryQueue [int64 ](set )
129
+ require .NoError (t , q .Start (context .Background (), componenttest .NewNopHost ()))
115
130
require .NoError (t , q .Offer (context .Background (), 1 ))
116
131
require .ErrorIs (t , q .Offer (context .Background (), 1 ), ErrQueueIsFull )
117
132
require .NoError (t , q .Shutdown (context .Background ()))
@@ -120,7 +135,9 @@ func TestMemoryQueueZeroCapacity(t *testing.T) {
120
135
func TestMemoryQueueWaitForResultPassErrorBack (t * testing.T ) {
121
136
wg := sync.WaitGroup {}
122
137
myErr := errors .New ("test error" )
123
- q := newMemoryQueue [int64 ](Settings [int64 ]{Sizer : sizerInt64 {}, Capacity : 100 , WaitForResult : true })
138
+ set := newSettings (request .SizerTypeItems , 100 )
139
+ set .WaitForResult = true
140
+ q := newMemoryQueue [int64 ](set )
124
141
require .NoError (t , q .Start (context .Background (), componenttest .NewNopHost ()))
125
142
wg .Add (1 )
126
143
go func () {
@@ -138,7 +155,9 @@ func TestMemoryQueueWaitForResultPassErrorBack(t *testing.T) {
138
155
func TestMemoryQueueWaitForResultCancelIncomingRequest (t * testing.T ) {
139
156
wg := sync.WaitGroup {}
140
157
stop := make (chan struct {})
141
- q := newMemoryQueue [int64 ](Settings [int64 ]{Sizer : sizerInt64 {}, Capacity : 100 , WaitForResult : true })
158
+ set := newSettings (request .SizerTypeItems , 100 )
159
+ set .WaitForResult = true
160
+ q := newMemoryQueue [int64 ](set )
142
161
require .NoError (t , q .Start (context .Background (), componenttest .NewNopHost ()))
143
162
144
163
// Consume async new data.
@@ -167,7 +186,9 @@ func TestMemoryQueueWaitForResultCancelIncomingRequest(t *testing.T) {
167
186
func TestMemoryQueueWaitForResultSizeAndCapacity (t * testing.T ) {
168
187
wg := sync.WaitGroup {}
169
188
stop := make (chan struct {})
170
- q := newMemoryQueue [int64 ](Settings [int64 ]{Sizer : sizerInt64 {}, Capacity : 100 , WaitForResult : true })
189
+ set := newSettings (request .SizerTypeItems , 100 )
190
+ set .WaitForResult = true
191
+ q := newMemoryQueue [int64 ](set )
171
192
require .NoError (t , q .Start (context .Background (), componenttest .NewNopHost ()))
172
193
173
194
// Consume async new data.
@@ -197,7 +218,9 @@ func TestMemoryQueueWaitForResultSizeAndCapacity(t *testing.T) {
197
218
func BenchmarkMemoryQueueWaitForResult (b * testing.B ) {
198
219
wg := sync.WaitGroup {}
199
220
consumed := & atomic.Int64 {}
200
- q := newMemoryQueue [int64 ](Settings [int64 ]{Sizer : sizerInt64 {}, Capacity : 1000 , WaitForResult : true })
221
+ set := newSettings (request .SizerTypeItems , 100 )
222
+ set .WaitForResult = true
223
+ q := newMemoryQueue [int64 ](set )
201
224
require .NoError (b , q .Start (context .Background (), componenttest .NewNopHost ()))
202
225
203
226
// Consume async new data.
0 commit comments