forked from nikepan/clickhouse-bulk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clickhouse_test.go
57 lines (51 loc) · 1.36 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
54
55
56
57
package main
import (
"errors"
"net/http"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestClickhouse_GetNextServer(t *testing.T) {
c := NewClickhouse(300, 10, "", false)
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(&ClickhouseRequest{})
s = c.GetNextServer()
assert.Equal(t, "http://127.0.0.1:8124", s.URL)
resp, status, err := s.SendQuery(&ClickhouseRequest{})
assert.NotEqual(t, "", resp)
assert.Equal(t, http.StatusBadGateway, status)
assert.True(t, errors.Is(err, ErrServerIsDown))
assert.Equal(t, true, s.Bad)
c.SendQuery(&ClickhouseRequest{})
}
func TestClickhouse_Send(t *testing.T) {
c := NewClickhouse(300, 10, "", false)
c.AddServer("")
c.Send(&ClickhouseRequest{})
for !c.Queue.Empty() {
time.Sleep(10)
}
}
func TestClickhouse_SendQuery(t *testing.T) {
c := NewClickhouse(300, 10, "", false)
c.AddServer("")
c.GetNextServer()
c.Servers[0].Bad = true
_, status, err := c.SendQuery(&ClickhouseRequest{})
assert.Equal(t, 503, status)
assert.True(t, errors.Is(err, ErrNoServers))
}
func TestClickhouse_SendQuery1(t *testing.T) {
c := NewClickhouse(-1, 10, "", false)
c.AddServer("")
c.GetNextServer()
c.Servers[0].Bad = true
s := c.GetNextServer()
assert.Equal(t, false, s.Bad)
}