forked from nikepan/clickhouse-bulk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dump_test.go
40 lines (34 loc) · 920 Bytes
/
dump_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
package main
import (
"errors"
"os"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestDump_Dump(t *testing.T) {
c := NewClickhouse(-1, 10, "", false)
dumpDir := "dumptest"
dumper := NewDumper(dumpDir)
c.Dumper = dumper
c.AddServer("")
c.Dump("eee", "eee", "error", "", 502)
assert.True(t, c.Empty())
buf, _, err := dumper.GetDumpData(dumper.dumpName(1, "", 502))
assert.Nil(t, err)
assert.Equal(t, "eee\neee", string(buf))
sender := &fakeSender{}
err = dumper.ProcessNextDump(sender)
assert.Nil(t, err)
assert.Len(t, sender.sendQueryHistory, 1)
err = dumper.ProcessNextDump(sender)
assert.True(t, errors.Is(err, ErrNoDumps))
assert.Len(t, sender.sendQueryHistory, 1)
dumper.Listen(sender, 1)
c.Dump("eee", "eee", "", "", 502)
time.Sleep(time.Second * 2)
err = dumper.ProcessNextDump(sender)
assert.Equal(t, ErrNoDumps, err)
err = os.Remove(dumpDir)
assert.Nil(t, err)
}