-
Notifications
You must be signed in to change notification settings - Fork 29
/
db_test.go
68 lines (54 loc) · 916 Bytes
/
db_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 catena
import (
"os"
"runtime"
"strconv"
"sync"
"testing"
)
func TestDB(t *testing.T) {
os.RemoveAll("/tmp/catena")
db, err := NewDB("/tmp/catena", 500, 20)
if err != nil {
t.Fatal(err)
}
ts := int64(0)
parallelism := 4
runtime.GOMAXPROCS(parallelism)
wg := sync.WaitGroup{}
wg.Add(parallelism)
work := make(chan []Row, parallelism)
for i := 0; i < parallelism; i++ {
go func() {
for rows := range work {
err := db.InsertRows(rows)
if err != nil {
wg.Done()
t.Fatal(err)
}
}
wg.Done()
}()
}
for n := 0; n < 500; n++ {
rows := []Row{}
for i := 0; i < 10000; i++ {
rows = append(rows, Row{
Source: "src",
Metric: "met_" + strconv.Itoa(i),
Point: Point{
Timestamp: ts,
Value: float64(i),
},
})
}
ts++
work <- rows
}
close(work)
wg.Wait()
err = db.Close()
if err != nil {
t.Fatal(err)
}
}