forked from nikepan/clickhouse-bulk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clickhouse_test.go
68 lines (62 loc) · 1.46 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
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"github.com/stretchr/testify/assert"
"io/ioutil"
"net/http"
"os"
"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)
}
func TestClickhouse_Dump(t *testing.T) {
const dumpName = "dump1.dmp"
c := NewClickhouse(-1)
c.Dumper = new(FileDumper)
c.AddServer("")
c.Dump("eee", "eee")
assert.True(t, c.Empty())
buf, err := ioutil.ReadFile(dumpName)
assert.Nil(t, err)
assert.Equal(t, "eee\neee", string(buf))
os.Remove(dumpName)
}