-
Notifications
You must be signed in to change notification settings - Fork 1
/
pq_test.go
39 lines (36 loc) · 1.31 KB
/
pq_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
package queue
import (
"testing"
"github.com/koykov/queue/qos"
)
func TestPQ(t *testing.T) {
t.Run("priority table", func(t *testing.T) {
expectIPT := [100]uint32{
0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
}
expectEPT := [100]uint32{
0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 1,
}
conf := Config{
QoS: qos.New(qos.RR, qos.DummyPriorityEvaluator{}).
AddQueue(qos.Queue{Name: "high", Capacity: 200, Weight: 120}).
AddQueue(qos.Queue{Name: "medium", Capacity: 50, Weight: 400}).
AddQueue(qos.Queue{Name: "low", Capacity: 750, Weight: 1200}),
}
_ = conf.QoS.Validate()
q := pq{}
err := q.init(&conf)
if err != nil {
t.Error(err)
}
if i, ok := q.assertPT(expectIPT, expectEPT); !ok {
t.Errorf("PT mismatch at position %d", i)
}
_ = q.close(false)
})
}