forked from nikepan/clickhouse-bulk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclickhouse_test.go
53 lines (48 loc) · 1.14 KB
/
clickhouse_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
package main
import (
"github.com/stretchr/testify/assert"
"net/http"
"testing"
"time"
)
func TestClickhouse_GetNextServer(t *testing.T) {
c := NewClickhouse(300)
c.AddServer("")
c.AddServer("http://127.0.0.1:8124")
c.AddServer("http://127.0.0.1:8125")
c.AddServer("http://127.0.0.1:8123")
s := c.GetNextServer()
assert.Equal(t, "", s.URL)
s.SendQuery("", "")
s = c.GetNextServer()
assert.Equal(t, "http://127.0.0.1:8124", s.URL)
resp, status := s.SendQuery("", "")
assert.NotEqual(t, "", resp)
assert.Equal(t, http.StatusBadGateway, status)
assert.Equal(t, true, s.Bad)
c.SendQuery("", "")
}
func TestClickhouse_Send(t *testing.T) {
c := NewClickhouse(300)
c.AddServer("")
c.Send("", "")
for !c.Queue.Empty() {
time.Sleep(10)
}
}
func TestClickhouse_SendQuery(t *testing.T) {
c := NewClickhouse(300)
c.AddServer("")
c.GetNextServer()
c.Servers[0].Bad = true
_, status := c.SendQuery("", "")
assert.Equal(t, http.StatusBadGateway, status)
}
func TestClickhouse_SendQuery1(t *testing.T) {
c := NewClickhouse(-1)
c.AddServer("")
c.GetNextServer()
c.Servers[0].Bad = true
s := c.GetNextServer()
assert.Equal(t, false, s.Bad)
}