-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtsdb_test.go
59 lines (48 loc) · 1.1 KB
/
tsdb_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
package arrowdb
import (
"encoding/json"
"fmt"
"testing"
"time"
)
func prepareInsertRows() []Row {
ts := time.Now().Unix()
rows := []Row{
{Metric: "sys.cpu", Tags: map[string]string{"ip": "127.0.0.1"}, Timestamp: ts, Value: 10},
{Metric: "sys.load", Tags: map[string]string{"ip": "127.0.0.1"}, Timestamp: ts, Value: 2},
}
return rows
}
func TestDB_InsertJsonRows(t *testing.T) {
rows := prepareInsertRows()
rowsData, err := json.Marshal(rows)
if err != nil {
fmt.Printf("json encode failed: %v\n", err)
return
}
db, err := OpenTSDB(nil)
if err != nil {
fmt.Printf("open tsdb failed: %v\n", err)
return
}
err = db.InsertJsonRows(rowsData)
if err != nil {
fmt.Printf("tsdb insert json rows failed: %v\n", err)
return
}
fmt.Printf("tsdb insert json rows success\n")
}
func TestDB_InsertRows(t *testing.T) {
rows := prepareInsertRows()
db, err := OpenTSDB(nil)
if err != nil {
fmt.Printf("open tsdb failed: %v\n", err)
return
}
err = db.InsertRows(rows)
if err != nil {
fmt.Printf("tsdb insert rows failed: %v\n", err)
return
}
fmt.Printf("tsdb insert rows success\n")
}