This repository has been archived by the owner on Sep 9, 2024. It is now read-only.
forked from gocassa/gocassa
-
Notifications
You must be signed in to change notification settings - Fork 13
/
multikey_timeseries_table_test.go
112 lines (108 loc) · 2.03 KB
/
multikey_timeseries_table_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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package gocassa
import (
"testing"
"time"
)
type TripC struct {
Id string
Time time.Time
TagA string
TagB string
}
func TestMultiKeyTimeSeriesTable(t *testing.T) {
tbl := ns.MultiKeyTimeSeriesTable(
"tripTime6",
[]string{"TagA", "TagB"},
"Time",
[]string{"Id"},
time.Minute,
TripC{},
)
createIf(tbl.(TableChanger), t)
err := tbl.WithOptions(Options{TTL: 30 * time.Second}).Set(TripC{
Id: "1",
Time: parse("2006 Jan 2 15:03:59"),
TagA: "A",
TagB: "A",
}).Add(tbl.Set(TripC{
Id: "2",
Time: parse("2006 Jan 2 15:04:00"),
TagA: "B",
TagB: "B",
})).Add(tbl.Set(TripC{
Id: "3",
Time: parse("2006 Jan 2 15:04:01"),
TagA: "A",
TagB: "B",
})).Add(tbl.Set(TripC{
Id: "4",
Time: parse("2006 Jan 2 15:05:01"),
TagA: "B",
TagB: "B",
})).Run()
if err != nil {
t.Fatal(err)
}
ts := &[]TripC{}
err = tbl.List(map[string]interface{}{
"TagA": "A",
"TagB": "A",
}, parse("2006 Jan 2 15:03:58"), parse("2006 Jan 2 15:04:02"), ts).Run()
if err != nil {
t.Fatal(err)
}
if len(*ts) != 1 {
t.Fatal(ts)
}
ts1 := *ts
if ts1[0].Id != "1" {
t.Fatal(ts1[0])
}
err = tbl.List(map[string]interface{}{
"TagA": "B",
"TagB": "B",
}, parse("2006 Jan 2 15:03:58"), parse("2006 Jan 2 15:04:02"), ts).Run()
if err != nil {
t.Fatal(err)
}
if len(*ts) != 1 {
t.Fatal(ts)
}
ts1 = *ts
if ts1[0].Id != "2" {
t.Fatal(ts1[0])
}
err = tbl.List(map[string]interface{}{
"TagA": "B",
"TagB": "B",
}, parse("2006 Jan 2 15:03:58"), parse("2006 Jan 2 15:05:02"), ts).Run()
if err != nil {
t.Fatal(err)
}
if len(*ts) != 2 {
t.Fatal(ts)
}
err = tbl.List(map[string]interface{}{
"TagA": "B",
"TagB": "B",
}, parse("2006 Jan 2 15:03:58"), parse("2006 Jan 2 15:05:00"), ts).Run()
if err != nil {
t.Fatal(err)
}
if len(*ts) != 1 {
t.Fatal(ts)
}
trip := &TripC{}
err = tbl.Read(map[string]interface{}{
"TagA": "A",
"TagB": "B",
}, parse("2006 Jan 2 15:04:01"), map[string]interface{}{
"Id": "3",
}, trip).Run()
if err != nil {
t.Fatal(err)
}
if trip.Id != "3" {
t.Fatal(ts)
}
}