123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- package runtime
- import (
- "fmt"
- "reflect"
- "testing"
- "time"
- "github.com/go-redis/redis/v7"
- "github.com/robinjoseph08/redisqueue/v2"
- "gogs.baozhida.cn/zoie/OAuth-core/storage"
- "gogs.baozhida.cn/zoie/OAuth-core/storage/queue"
- )
- func TestNewMemoryQueue(t *testing.T) {
- type args struct {
- prefix string
- queue storage.AdapterQueue
- }
- tests := []struct {
- name string
- args args
- want storage.AdapterQueue
- }{
- {
- "test0",
- args{
- prefix: "",
- queue: nil,
- },
- queue.NewMemory(100),
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- if got := NewQueue(tt.args.prefix, tt.args.queue); !reflect.DeepEqual(got, tt.want) {
- t.Errorf("NewQueue() = %v, want %v", got, tt.want)
- }
- })
- }
- }
- func TestQueue_Register(t *testing.T) {
- type fields struct {
- prefix string
- queue storage.AdapterQueue
- }
- type args struct {
- name string
- f storage.ConsumerFunc
- }
- client := redis.NewClient(&redis.Options{})
- q, err := queue.NewRedis(&redisqueue.ProducerOptions{
- StreamMaxLength: 100,
- ApproximateMaxLength: true,
- RedisClient: client,
- }, &redisqueue.ConsumerOptions{
- VisibilityTimeout: 60 * time.Second,
- BlockingTimeout: 5 * time.Second,
- ReclaimInterval: 1 * time.Second,
- BufferSize: 100,
- Concurrency: 10,
- RedisClient: client,
- })
- if err != nil {
- t.Error(err)
- return
- }
- tests := []struct {
- name string
- fields fields
- args args
- }{
- {
- "test0",
- fields{
- prefix: "",
- queue: q,
- },
- args{
- name: "operate_log_queue",
- f: func(m storage.Messager) error {
- fmt.Println(m.GetValues())
- return nil
- },
- },
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- //var e storage.AdapterQueue
- e := &Queue{
- prefix: tt.fields.prefix,
- queue: tt.fields.queue,
- }
- e.Register(tt.args.name, tt.args.f)
- e.Run()
- })
- }
- }
|