1- package priorityqueue
1+ package priorityqueue_test
22
33import (
44 "fmt"
99 "time"
1010
1111 "github.com/google/uuid"
12+ priorityqueue "github.com/roadrunner-server/priority_queue"
1213 "github.com/stretchr/testify/assert"
1314 "github.com/stretchr/testify/require"
1415)
@@ -40,7 +41,7 @@ func (t Test) Priority() int64 {
4041}
4142
4243func TestBinHeap_Init (t * testing.T ) {
43- a := []Item {
44+ a := []priorityqueue. Item {
4445 NewTest (2 , uuid .NewString (), uuid .NewString ()),
4546 NewTest (23 , uuid .NewString (), uuid .NewString ()),
4647 NewTest (33 , uuid .NewString (), uuid .NewString ()),
@@ -54,7 +55,7 @@ func TestBinHeap_Init(t *testing.T) {
5455 NewTest (99 , uuid .NewString (), uuid .NewString ()),
5556 }
5657
57- bh := NewBinHeap [Item ](12 )
58+ bh := priorityqueue. NewBinHeap [priorityqueue. Item ](12 )
5859
5960 for i := 0 ; i < len (a ); i ++ {
6061 bh .Insert (a [i ])
@@ -86,7 +87,7 @@ func TestBinHeap_Init(t *testing.T) {
8687}
8788
8889func TestBinHeap_MaxLen (t * testing.T ) {
89- a := []Item {
90+ a := []priorityqueue. Item {
9091 NewTest (2 , uuid .NewString (), uuid .NewString ()),
9192 NewTest (23 , uuid .NewString (), uuid .NewString ()),
9293 NewTest (33 , uuid .NewString (), uuid .NewString ()),
@@ -100,10 +101,10 @@ func TestBinHeap_MaxLen(t *testing.T) {
100101 NewTest (99 , uuid .NewString (), uuid .NewString ()),
101102 }
102103
103- bh := NewBinHeap [Item ](1 )
104+ bh := priorityqueue. NewBinHeap [priorityqueue. Item ](1 )
104105
105106 go func () {
106- res := make ([]Item , 0 , 12 )
107+ res := make ([]priorityqueue. Item , 0 , 12 )
107108
108109 for i := 0 ; i < 11 ; i ++ {
109110 item := bh .ExtractMin ()
@@ -124,7 +125,7 @@ func TestNewPriorityQueue(t *testing.T) {
124125 insertsPerSec := uint64 (0 )
125126 getPerSec := uint64 (0 )
126127 stopCh := make (chan struct {}, 1 )
127- pq := NewBinHeap [Item ](1000 )
128+ pq := priorityqueue. NewBinHeap [priorityqueue. Item ](1000 )
128129
129130 go func () {
130131 tt3 := time .NewTicker (time .Millisecond * 10 )
@@ -187,7 +188,7 @@ func TestNewPriorityQueue(t *testing.T) {
187188}
188189
189190func TestNewItemWithTimeout (t * testing.T ) {
190- a := []Item {
191+ a := []priorityqueue. Item {
191192 NewTest (5 , uuid .NewString (), uuid .NewString ()),
192193 NewTest (23 , uuid .NewString (), uuid .NewString ()),
193194 NewTest (33 , uuid .NewString (), uuid .NewString ()),
@@ -205,7 +206,7 @@ func TestNewItemWithTimeout(t *testing.T) {
205206 first item should be extracted not less than 5 seconds after we call ExtractMin
206207 5 seconds is a minimum timeout for our items
207208 */
208- bh := NewBinHeap [Item ](100 )
209+ bh := priorityqueue. NewBinHeap [priorityqueue. Item ](100 )
209210
210211 for i := 0 ; i < len (a ); i ++ {
211212 bh .Insert (a [i ])
@@ -218,7 +219,7 @@ func TestNewItemWithTimeout(t *testing.T) {
218219}
219220
220221func TestItemPeek (t * testing.T ) {
221- a := []Item {
222+ a := []priorityqueue. Item {
222223 NewTest (5 , uuid .NewString (), uuid .NewString ()),
223224 NewTest (23 , uuid .NewString (), uuid .NewString ()),
224225 NewTest (33 , uuid .NewString (), uuid .NewString ()),
@@ -236,7 +237,7 @@ func TestItemPeek(t *testing.T) {
236237 first item should be extracted not less than 5 seconds after we call ExtractMin
237238 5 seconds is a minimum timeout for our items
238239 */
239- bh := NewBinHeap [Item ](100 )
240+ bh := priorityqueue. NewBinHeap [priorityqueue. Item ](100 )
240241
241242 for i := 0 ; i < len (a ); i ++ {
242243 bh .Insert (a [i ])
@@ -252,7 +253,7 @@ func TestItemPeek(t *testing.T) {
252253}
253254
254255func TestItemPeekConcurrent (t * testing.T ) {
255- a := []Item {
256+ a := []priorityqueue. Item {
256257 NewTest (5 , uuid .NewString (), uuid .NewString ()),
257258 NewTest (23 , uuid .NewString (), uuid .NewString ()),
258259 NewTest (33 , uuid .NewString (), uuid .NewString ()),
@@ -270,7 +271,7 @@ func TestItemPeekConcurrent(t *testing.T) {
270271 first item should be extracted not less than 5 seconds after we call ExtractMin
271272 5 seconds is a minimum timeout for our items
272273 */
273- bh := NewBinHeap [Item ](100 )
274+ bh := priorityqueue. NewBinHeap [priorityqueue. Item ](100 )
274275
275276 for i := 0 ; i < len (a ); i ++ {
276277 bh .Insert (a [i ])
@@ -298,7 +299,7 @@ func TestItemPeekConcurrent(t *testing.T) {
298299}
299300
300301func TestBinHeap_Remove (t * testing.T ) {
301- a := []Item {
302+ a := []priorityqueue. Item {
302303 NewTest (2 , "1" , "101" ),
303304 NewTest (5 , "1" , "102" ),
304305 NewTest (99 , "1" , "103" ),
@@ -312,13 +313,13 @@ func TestBinHeap_Remove(t *testing.T) {
312313 NewTest (2 , "1" , "111" ),
313314 }
314315
315- bh := NewBinHeap [Item ](12 )
316+ bh := priorityqueue. NewBinHeap [priorityqueue. Item ](12 )
316317
317318 for i := 0 ; i < len (a ); i ++ {
318319 bh .Insert (a [i ])
319320 }
320321
321- expected := []Item {
322+ expected := []priorityqueue. Item {
322323 NewTest (4 , "6" , "104" ),
323324 NewTest (6 , "7" , "105" ),
324325 NewTest (23 , "2" , "106" ),
@@ -337,7 +338,7 @@ func TestBinHeap_Remove(t *testing.T) {
337338 }
338339 }
339340
340- res := make ([]Item , 0 , 12 )
341+ res := make ([]priorityqueue. Item , 0 , 12 )
341342
342343 for i := 0 ; i < 5 ; i ++ {
343344 item := bh .ExtractMin ()
@@ -349,7 +350,7 @@ func TestBinHeap_Remove(t *testing.T) {
349350
350351func TestExists (t * testing.T ) {
351352 const id = "11111111111"
352- a := []Item {
353+ a := []priorityqueue. Item {
353354 NewTest (2 , "1" , id ),
354355 NewTest (5 , "1" , uuid .NewString ()),
355356 NewTest (99 , "1" , uuid .NewString ()),
@@ -363,7 +364,7 @@ func TestExists(t *testing.T) {
363364 NewTest (2 , "1" , uuid .NewString ()),
364365 }
365366
366- bh := NewBinHeap [Item ](12 )
367+ bh := priorityqueue. NewBinHeap [priorityqueue. Item ](12 )
367368
368369 for i := 0 ; i < len (a ); i ++ {
369370 bh .Insert (a [i ])
@@ -378,7 +379,7 @@ func TestExists(t *testing.T) {
378379}
379380
380381func BenchmarkGeneral (b * testing.B ) {
381- bh := NewBinHeap [Item ](100 )
382+ bh := priorityqueue. NewBinHeap [priorityqueue. Item ](100 )
382383 id := uuid .NewString ()
383384 id2 := uuid .NewString ()
384385
0 commit comments