-
Notifications
You must be signed in to change notification settings - Fork 48
/
functional_topic_metadata_test.go
111 lines (90 loc) · 2.18 KB
/
functional_topic_metadata_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
107
108
109
110
111
package kazoo
import (
"testing"
)
func TestTopics(t *testing.T) {
kz, err := NewKazoo(zookeeperPeers, nil)
if err != nil {
t.Fatal(err)
}
topics, err := kz.Topics()
if err != nil {
t.Error(err)
}
existingTopic := topics.Find("test.4")
if existingTopic == nil {
t.Error("Expected topic test.4 to be returned")
} else if existingTopic.Name != "test.4" {
t.Error("Expected topic test.4 to have its name set")
}
nonexistingTopic := topics.Find("__nonexistent__")
if nonexistingTopic != nil {
t.Error("Expected __nonexistent__ topic to not be defined")
}
assertSuccessfulClose(t, kz)
}
func TestTopicPartitions(t *testing.T) {
kz, err := NewKazoo(zookeeperPeers, nil)
if err != nil {
t.Fatal(err)
}
partitions, err := kz.Topic("test.4").Partitions()
if err != nil {
t.Fatal(err)
}
if len(partitions) != 4 {
t.Errorf("Expected test.4 to have 4 partitions")
}
brokers, err := kz.Brokers()
if err != nil {
t.Fatal(err)
}
for index, partition := range partitions {
if partition.ID != int32(index) {
t.Error("partition.ID is not set properly")
}
leader, err := partition.Leader()
if err != nil {
t.Fatal(err)
}
if _, ok := brokers[leader]; !ok {
t.Errorf("Expected the leader of test.4/%d to be an existing broker.", partition.ID)
}
isr, err := partition.ISR()
if err != nil {
t.Fatal(err)
}
for _, brokerID := range isr {
if _, ok := brokers[brokerID]; !ok {
t.Errorf("Expected all ISRs of test.4/%d to be existing brokers.", partition.ID)
}
}
}
assertSuccessfulClose(t, kz)
}
func TestTopicConfig(t *testing.T) {
kz, err := NewKazoo(zookeeperPeers, nil)
if err != nil {
t.Fatal(err)
}
topicConfig, err := kz.Topic("test.4").Config()
if err != nil {
t.Error(err)
}
if topicConfig["retention.ms"] != "604800000" {
t.Error("Expected retention.ms config for test.4 to be set to 604800000")
}
topicConfig, err = kz.Topic("test.1").Config()
if err != nil {
t.Error(err)
}
if len(topicConfig) > 0 {
t.Error("Expected no topic level configuration to be set for test.1")
}
assertSuccessfulClose(t, kz)
}
func assertSuccessfulClose(t *testing.T, kz *Kazoo) {
if err := kz.Close(); err != nil {
t.Error(err)
}
}