1
0

queue_test.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package runtime
  2. import (
  3. "fmt"
  4. "reflect"
  5. "testing"
  6. "time"
  7. "github.com/go-redis/redis/v7"
  8. "github.com/robinjoseph08/redisqueue/v2"
  9. "gogs.baozhida.cn/zoie/OAuth-core/storage"
  10. "gogs.baozhida.cn/zoie/OAuth-core/storage/queue"
  11. )
  12. func TestNewMemoryQueue(t *testing.T) {
  13. type args struct {
  14. prefix string
  15. queue storage.AdapterQueue
  16. }
  17. tests := []struct {
  18. name string
  19. args args
  20. want storage.AdapterQueue
  21. }{
  22. {
  23. "test0",
  24. args{
  25. prefix: "",
  26. queue: nil,
  27. },
  28. queue.NewMemory(100),
  29. },
  30. }
  31. for _, tt := range tests {
  32. t.Run(tt.name, func(t *testing.T) {
  33. if got := NewQueue(tt.args.prefix, tt.args.queue); !reflect.DeepEqual(got, tt.want) {
  34. t.Errorf("NewQueue() = %v, want %v", got, tt.want)
  35. }
  36. })
  37. }
  38. }
  39. func TestQueue_Register(t *testing.T) {
  40. type fields struct {
  41. prefix string
  42. queue storage.AdapterQueue
  43. }
  44. type args struct {
  45. name string
  46. f storage.ConsumerFunc
  47. }
  48. client := redis.NewClient(&redis.Options{})
  49. q, err := queue.NewRedis(&redisqueue.ProducerOptions{
  50. StreamMaxLength: 100,
  51. ApproximateMaxLength: true,
  52. RedisClient: client,
  53. }, &redisqueue.ConsumerOptions{
  54. VisibilityTimeout: 60 * time.Second,
  55. BlockingTimeout: 5 * time.Second,
  56. ReclaimInterval: 1 * time.Second,
  57. BufferSize: 100,
  58. Concurrency: 10,
  59. RedisClient: client,
  60. })
  61. if err != nil {
  62. t.Error(err)
  63. return
  64. }
  65. tests := []struct {
  66. name string
  67. fields fields
  68. args args
  69. }{
  70. {
  71. "test0",
  72. fields{
  73. prefix: "",
  74. queue: q,
  75. },
  76. args{
  77. name: "operate_log_queue",
  78. f: func(m storage.Messager) error {
  79. fmt.Println(m.GetValues())
  80. return nil
  81. },
  82. },
  83. },
  84. }
  85. for _, tt := range tests {
  86. t.Run(tt.name, func(t *testing.T) {
  87. //var e storage.AdapterQueue
  88. e := &Queue{
  89. prefix: tt.fields.prefix,
  90. queue: tt.fields.queue,
  91. }
  92. e.Register(tt.args.name, tt.args.f)
  93. e.Run()
  94. })
  95. }
  96. }