-
Notifications
You must be signed in to change notification settings - Fork 48
/
functional_cluster_test.go
98 lines (79 loc) · 1.89 KB
/
functional_cluster_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
package kazoo
import (
"fmt"
"net"
"os"
"strings"
"testing"
"time"
)
var (
// By default, assume we're using Sarama's vagrant cluster when running tests
zookeeperPeers []string = []string{"192.168.100.67:2181", "192.168.100.67:2182", "192.168.100.67:2183", "192.168.100.67:2184", "192.168.100.67:2185"}
)
func init() {
if zookeeperPeersEnv := os.Getenv("ZOOKEEPER_PEERS"); zookeeperPeersEnv != "" {
zookeeperPeers = strings.Split(zookeeperPeersEnv, ",")
}
fmt.Printf("Using Zookeeper cluster at %v\n", zookeeperPeers)
}
func TestBrokers(t *testing.T) {
kz, err := NewKazoo(zookeeperPeers, nil)
if err != nil {
t.Fatal(err)
}
brokers, err := kz.Brokers()
if err != nil {
t.Fatal(err)
}
if len(brokers) == 0 {
t.Error("Expected at least one broker")
}
for id, addr := range brokers {
if conn, err := net.DialTimeout("tcp", addr, 100*time.Millisecond); err != nil {
t.Errorf("Failed to connect to Kafka broker %d at %s", id, addr)
} else {
_ = conn.Close()
}
}
assertSuccessfulClose(t, kz)
}
func TestBrokerList(t *testing.T) {
kz, err := NewKazoo(zookeeperPeers, nil)
if err != nil {
t.Fatal(err)
}
brokers, err := kz.BrokerList()
if err != nil {
t.Fatal(err)
}
if len(brokers) == 0 {
t.Error("Expected at least one broker")
}
for _, addr := range brokers {
if conn, err := net.DialTimeout("tcp", addr, 100*time.Millisecond); err != nil {
t.Errorf("Failed to connect to Kafka broker at %s", addr)
} else {
_ = conn.Close()
}
}
assertSuccessfulClose(t, kz)
}
func TestController(t *testing.T) {
kz, err := NewKazoo(zookeeperPeers, nil)
if err != nil {
t.Fatal(err)
}
brokers, err := kz.Brokers()
if err != nil {
t.Fatal(err)
}
controller, err := kz.Controller()
if err != nil {
t.Fatal(err)
}
if _, ok := brokers[controller]; !ok {
t.Error("Expected the controller's BrokerID to be an existing one")
}
assertSuccessfulClose(t, kz)
}