-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelay_queue_test.go
87 lines (74 loc) · 1.67 KB
/
delay_queue_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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package delay_queue
import (
"context"
"encoding/json"
"fmt"
"github.com/go-redis/redis/v9"
my_redis "myProject/delay-queue/redis"
"testing"
)
func TestDelayQueue_EnQueue(t *testing.T) {
config := DelayQueueConfig{
Logger: nil,
ZsetName: "my_zset",
HashName: "my_hash",
WorkerNum: 3,
WorkerTicker: 0,
Fn: func(ctx context.Context, value interface{}) error {
return nil
},
BatchSize: 0,
Rdb: my_redis.RDB,
}
q := NewDelayQueue(config)
for i := 0; i < 100; i++ {
type Person struct {
Name string `json:"name"`
ExecSeconds int64 `json:"exec_seconds"`
}
p := Person{Name: fmt.Sprintf("%v", i), ExecSeconds: int64(i)}
bytelist, _ := json.Marshal(p)
err := q.EnQueue(Item{
ID: fmt.Sprintf("%v", i),
ExecTmp: p.ExecSeconds,
Content: string(bytelist),
})
if err != redis.Nil {
fmt.Println(err)
}
}
}
func TestDelayQueue_DeQueue(t *testing.T) {
config := DelayQueueConfig{
Logger: nil,
ZsetName: "my_zset",
HashName: "my_hash",
WorkerNum: 3,
WorkerTicker: 0,
Fn: func(ctx context.Context, value interface{}) error {
return nil
},
BatchSize: 0,
Rdb: my_redis.RDB,
}
q := NewDelayQueue(config)
res, err := q.DeQueue(221111112, 10)
fmt.Printf("res-----%+v\n", res)
fmt.Printf("err -----%+v\n", err)
}
func TestDelayQueue_Run(t *testing.T) {
config := DelayQueueConfig{
Logger: nil,
ZsetName: "my_zset",
HashName: "my_hash",
WorkerNum: 3,
WorkerTicker: 0,
Fn: func(ctx context.Context, value interface{}) error {
return nil
},
BatchSize: 0,
Rdb: my_redis.RDB,
}
q := NewDelayQueue(config)
q.Run(context.TODO())
}