-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsumer_group_test.go
106 lines (95 loc) · 2.27 KB
/
consumer_group_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
104
105
106
package diskq
import (
"testing"
"time"
)
func Test_ConsumerGroup_readToEnd(t *testing.T) {
testPath, done := tempDir()
t.Cleanup(done)
dq, err := New(testPath, Options{
PartitionCount: 3,
SegmentSizeBytes: 1024,
})
assert_noerror(t, err)
defer func() { _ = dq.Close() }()
for x := 0; x < 64; x++ {
_, _, err = dq.Push(testMessage(int(x), 128))
assert_noerror(t, err)
}
cg, err := OpenConsumerGroup(testPath, ConsumerGroupOptions{
OptionsForConsumer: func(_ uint32) (ConsumerOptions, error) {
return ConsumerOptions{
StartBehavior: ConsumerStartBehaviorOldest,
EndBehavior: ConsumerEndBehaviorClose,
}, nil
},
})
assert_noerror(t, err)
defer func() { _ = cg.Close() }()
var messages []MessageWithOffset
for {
msg, ok := <-cg.Messages()
if !ok {
break
}
messages = append(messages, msg)
}
assert_equal(t, 64, len(messages))
}
func Test_ConsumerGroup_addsPartitions(t *testing.T) {
testPath, done := tempDir()
t.Cleanup(done)
dq, err := New(testPath, Options{
PartitionCount: 1,
SegmentSizeBytes: 1024,
})
assert_noerror(t, err)
for x := 0; x < 8; x++ {
_, _, err = dq.Push(testMessage(int(x), 128))
assert_noerror(t, err)
}
cg, err := OpenConsumerGroup(testPath, ConsumerGroupOptions{
OptionsForConsumer: func(_ uint32) (ConsumerOptions, error) {
return ConsumerOptions{
StartBehavior: ConsumerStartBehaviorOldest,
EndBehavior: ConsumerEndBehaviorWait,
}, nil
},
PartitionScanInterval: 100 * time.Millisecond,
})
assert_noerror(t, err)
defer func() { _ = cg.Close() }()
var messages []MessageWithOffset
for x := 0; x < 8; x++ {
msg, ok := <-cg.Messages()
if !ok {
break
}
messages = append(messages, msg)
}
assert_equal(t, 8, len(messages))
_ = dq.Close()
dq, err = New(testPath, Options{
PartitionCount: 3,
SegmentSizeBytes: 1024,
})
assert_noerror(t, err)
var partition uint32
partitions := make(map[uint32]int)
for x := 0; x < 24; x++ {
partition, _, err = dq.Push(testMessage(int(x), 128))
assert_noerror(t, err)
partitions[partition]++
}
for x := 0; x < 24; x++ {
msg, ok := <-cg.Messages()
if !ok {
break
}
messages = append(messages, msg)
}
assert_equal(t, 32, len(messages))
for x := 0; x < 3; x++ {
assert_notequal(t, 0, partitions[uint32(x)])
}
}