-
Notifications
You must be signed in to change notification settings - Fork 792
/
deletegroups_test.go
80 lines (64 loc) · 1.58 KB
/
deletegroups_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
package kafka
import (
"context"
"errors"
"testing"
"time"
ktesting "github.com/segmentio/kafka-go/testing"
)
func TestClientDeleteGroups(t *testing.T) {
if !ktesting.KafkaIsAtLeast("1.1.0") {
t.Skip("Skipping test because kafka version is not high enough.")
}
client, shutdown := newLocalClient()
defer shutdown()
topic := makeTopic()
createTopic(t, topic, 1)
groupID := makeGroupID()
group, err := NewConsumerGroup(ConsumerGroupConfig{
ID: groupID,
Topics: []string{topic},
Brokers: []string{"localhost:9092"},
HeartbeatInterval: 2 * time.Second,
RebalanceTimeout: 2 * time.Second,
RetentionTime: time.Hour,
Logger: &testKafkaLogger{T: t},
})
if err != nil {
t.Fatal(err)
}
defer group.Close()
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
gen, err := group.Next(ctx)
if gen == nil {
t.Fatalf("expected generation 1 not to be nil")
}
if err != nil {
t.Fatalf("expected no error, but got %+v", err)
}
// delete not empty group
res, err := client.DeleteGroups(ctx, &DeleteGroupsRequest{
GroupIDs: []string{groupID},
})
if err != nil {
t.Fatal(err)
}
if !errors.Is(res.Errors[groupID], NonEmptyGroup) {
t.Fatalf("expected NonEmptyGroup error, but got %+v", res.Errors[groupID])
}
err = group.Close()
if err != nil {
t.Fatal(err)
}
// delete empty group
res, err = client.DeleteGroups(ctx, &DeleteGroupsRequest{
GroupIDs: []string{groupID},
})
if err != nil {
t.Fatal(err)
}
if err = res.Errors[groupID]; err != nil {
t.Error(err)
}
}