This repository has been archived by the owner on Jun 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnanocube_node_test.go
141 lines (131 loc) · 3.19 KB
/
nanocube_node_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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package distnano
import (
"reflect"
"testing"
)
var absToRel = []struct {
query string
result string
outsideRange bool
spt *SpecialTimeQuery
relativeBin int
}{
// Tests a query that falls fully into a NanocubeNode's range.
{
"/count.r(\"time\",mt_interval_sequence(480,24,10))",
"/count.r(\"time\",mt_interval_sequence(36,24,10))",
false,
nil,
444,
},
// Tests an interval query (simpler of the two time queries).
{
"/count.r(\"time\",interval(480,720))",
"/count.r(\"time\",interval(36,276))",
false,
nil,
444,
},
// Tests a query that falls only partially into a NanocubeNode's range and
// would need to be readjusted according to bucketOffset.
{
"/count.r(\"time\",mt_interval_sequence(408,24,13))",
"",
false,
&SpecialTimeQuery{
queryOne: "/count.r(\"time\",mt_interval_sequence(0,12,1))",
queryTwo: "/count.r(\"time\",mt_interval_sequence(12,24,11))",
bucketOffset: 1,
node: nil,
},
444,
},
// Tests a time query over the whole dataset for a variety of relativeBins.
{
"/count.r(\"time\",mt_interval_sequence(0,524289,8192))",
"/count.r(\"time\",mt_interval_sequence(0,524289,8192))",
false,
nil,
0,
},
{
"/count.r(\"time\",mt_interval_sequence(0,524289,8192))",
"",
false,
&SpecialTimeQuery{
queryOne: "/count.r(\"time\",mt_interval_sequence(0,523545,1))",
queryTwo: "/count.r(\"time\",mt_interval_sequence(523545,524289,8191))",
bucketOffset: 0,
node: nil,
},
744,
},
{
"/count.r(\"time\",mt_interval_sequence(480,24,10))",
"/count.r(\"time\",mt_interval_sequence(0,24,-32))",
true,
nil,
1488,
},
}
// TestNanocubeNodeCrimeConstruction only runs if there are 5 NanocubeNodes
// running on http://localhost:900x where x \in {0, 1, 2, 3, 4}
func TestNanocubeNodeCrimeConstruction(t *testing.T) {
var addrs = []string{
"http://localhost:9000",
"http://localhost:9001",
"http://localhost:9002",
"http://localhost:9003",
"http://localhost:9004",
}
// Do a count request to check that the servers are up and responding.
for _, addr := range addrs {
_, err := (&NanocubeNode{addr: addr}).Query("/schema")
if err != nil {
return
}
}
// No error, let's construct them.
nodes, err := nanocubeNodesFromAddrs(addrs)
if err != nil {
t.Fatalf("%v %v", err, nodes)
}
// Check that the binSize is 3600s
for _, node := range nodes {
if node.tBin.binSize.Seconds() != 3600 {
t.Fatalf("Unexpected bin size")
}
}
// TODO(asubiotto): Add a check for the relativeBin
}
func TestAbsoluteToRelativeTimeQuery(t *testing.T) {
for _, e := range absToRel {
node := &NanocubeNode{relativeBin: e.relativeBin}
result, outsideRange, spTimeQuery := node.mustAbsToRelTimeQuery(e.query)
if spTimeQuery != nil {
spTimeQuery.node = nil
}
if result != e.result {
t.Fatalf(
"Expected %v, got %v for query %v\n",
e.result,
result,
e,
)
} else if outsideRange != e.outsideRange {
t.Fatalf(
"Expected %v, got %v for query %v\n",
e.outsideRange,
outsideRange,
e,
)
} else if !reflect.DeepEqual(spTimeQuery, e.spt) {
t.Fatalf(
"Expected %v, got %v for query %v\n",
e.spt,
spTimeQuery,
e,
)
}
}
}