-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from nikepan/prometheus
Prometheus & dump sender & fixes & refactoring
- Loading branch information
Showing
20 changed files
with
788 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,11 @@ _testmain.go | |
*.exe | ||
*.test | ||
*.prof | ||
dumptest | ||
dumps | ||
|
||
.vscode | ||
.idea/ | ||
clickhouse-bulk | ||
debug | ||
check.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,57 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"io/ioutil" | ||
"errors" | ||
"net/http" | ||
"os" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestClickhouse_GetNextServer(t *testing.T) { | ||
c := NewClickhouse(300) | ||
c := NewClickhouse(300, 10) | ||
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.SendQuery(&ClickhouseRequest{}) | ||
s = c.GetNextServer() | ||
assert.Equal(t, "http://127.0.0.1:8124", s.URL) | ||
resp, status := s.SendQuery("", "") | ||
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("", "") | ||
c.SendQuery(&ClickhouseRequest{}) | ||
} | ||
|
||
func TestClickhouse_Send(t *testing.T) { | ||
c := NewClickhouse(300) | ||
c := NewClickhouse(300, 10) | ||
c.AddServer("") | ||
c.Send("", "") | ||
c.Send(&ClickhouseRequest{}) | ||
for !c.Queue.Empty() { | ||
time.Sleep(10) | ||
} | ||
} | ||
|
||
func TestClickhouse_SendQuery(t *testing.T) { | ||
c := NewClickhouse(300) | ||
c := NewClickhouse(300, 10) | ||
c.AddServer("") | ||
c.GetNextServer() | ||
c.Servers[0].Bad = true | ||
_, status := c.SendQuery("", "") | ||
assert.Equal(t, http.StatusBadGateway, status) | ||
_, status, err := c.SendQuery(&ClickhouseRequest{}) | ||
assert.Equal(t, 0, status) | ||
assert.True(t, errors.Is(err, ErrNoServers)) | ||
} | ||
|
||
func TestClickhouse_SendQuery1(t *testing.T) { | ||
c := NewClickhouse(-1) | ||
c := NewClickhouse(-1, 10) | ||
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) | ||
} |
Oops, something went wrong.