-
Notifications
You must be signed in to change notification settings - Fork 0
/
consumergroup_test.go
103 lines (100 loc) · 2.44 KB
/
consumergroup_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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package angora
import (
"sync"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_newConsumerGroup(t *testing.T) {
type args struct {
name string
queue string
handler DeliveryHandler
concurrencyDegree int
config ConsumerConfig
opts []ConsumerGroupOption
}
tests := []struct {
name string
args args
want *ConsumerGroup
wantErr bool
}{
{
name: "creates with invalid prefetch params",
args: args{
queue: "test-queue",
handler: nil,
concurrencyDegree: 3,
config: ConsumerConfig{},
opts: []ConsumerGroupOption{WithPrefetch(0, true)},
},
want: nil,
wantErr: true,
},
{
name: "creates with prefetch params",
args: args{
queue: "test-queue",
handler: nil,
concurrencyDegree: 3,
config: ConsumerConfig{
AutoAck: false,
Exclusive: false,
NoLocal: false,
NoWait: false,
Args: nil,
},
opts: []ConsumerGroupOption{WithPrefetch(50, true)},
},
want: &ConsumerGroup{
queue: "test-queue",
handler: nil,
concurrencyDegree: 3,
consumersM: new(sync.Mutex),
consumers: make([]consumer, 0),
prefetchCount: 50,
prefetchSize: 0,
prefetchGlobal: true,
consumerCfg: ConsumerConfig{},
},
wantErr: false,
},
{
name: "creates default",
args: args{
name: "test-cg",
queue: "test-queue",
handler: nil,
concurrencyDegree: 3,
config: ConsumerConfig{
AutoAck: false,
Exclusive: false,
NoLocal: false,
NoWait: false,
Args: nil,
},
opts: nil,
},
want: &ConsumerGroup{
name: "test-cg",
queue: "test-queue",
handler: nil,
concurrencyDegree: 3,
consumersM: new(sync.Mutex),
consumers: make([]consumer, 0),
prefetchCount: 0,
prefetchSize: 0,
prefetchGlobal: false,
consumerCfg: ConsumerConfig{},
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := newConsumerGroup(tt.args.name, tt.args.queue, tt.args.handler, tt.args.concurrencyDegree, tt.args.config, tt.args.opts...)
assert.Equal(t, tt.wantErr, err != nil)
assert.EqualValues(t, tt.want, got)
})
}
}