forked from roistat/go-clickhouse
-
Notifications
You must be signed in to change notification settings - Fork 4
/
cluster_test.go
51 lines (34 loc) · 975 Bytes
/
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
package clickhouse
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestPing(t *testing.T) {
goodTr := getMockTransport("Ok.")
badTr := getMockTransport("Code: 9999, Error: ...")
conn1 := NewConn("host1", badTr)
conn2 := NewConn("host2", goodTr)
cl := NewCluster(conn1, conn2)
assert.Equal(t, conn1, cl.conn[0])
assert.Equal(t, conn2, cl.conn[1])
assert.True(t, cl.IsDown())
cl.OnCheckError(func(c *Conn) {
assert.Equal(t, conn1, c)
})
cl.Check()
assert.Equal(t, conn2.Host, cl.ActiveConn().Host)
assert.False(t, cl.IsDown())
cl.conn[0] = NewConn("host1", goodTr)
cl.conn[1] = NewConn("host2", badTr)
cl.OnCheckError(func(c *Conn) {
assert.Equal(t, conn2.Host, c.Host)
})
cl.Check()
assert.Equal(t, conn1.Host, cl.ActiveConn().Host)
cl.conn[0] = NewConn("host1", badTr)
cl.conn[1] = NewConn("host2", badTr)
cl.OnCheckError(func(c *Conn) {})
cl.Check()
assert.Nil(t, cl.ActiveConn())
assert.True(t, cl.IsDown())
}