OLD | NEW |
---|---|
1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
4 | 4 |
5 package memory | 5 package memory |
6 | 6 |
7 import ( | 7 import ( |
8 "sort" | 8 "sort" |
9 "testing" | 9 "testing" |
10 "time" | 10 "time" |
(...skipping 20 matching lines...) Expand all Loading... | |
31 idxs []*ds.IndexDefinition | 31 idxs []*ds.IndexDefinition |
32 | 32 |
33 // These are checked in TestIndexRowGen. nil to skip test case. | 33 // These are checked in TestIndexRowGen. nil to skip test case. |
34 expected []serialize.SerializedPslice | 34 expected []serialize.SerializedPslice |
35 | 35 |
36 // just the collections you want to assert. These are checked in | 36 // just the collections you want to assert. These are checked in |
37 // TestIndexEntries. nil to skip test case. | 37 // TestIndexEntries. nil to skip test case. |
38 collections map[string][][]byte | 38 collections map[string][][]byte |
39 }{ | 39 }{ |
40 | 40 |
41 { | 41 { |
iannucci
2016/09/16 07:11:03
question: now that we know that the datastore reta
dnj
2016/09/16 19:07:22
Discussed, probably can't matter for queries.
| |
42 name: "simple including builtins", | 42 name: "simple including builtins", |
43 pmap: ds.PropertyMap{ | 43 pmap: ds.PropertyMap{ |
44 » » » "wat": {propNI("thing"), prop("hat"), prop(100)}, | 44 » » » "wat": ds.PropertySlice{propNI("thing"), prop("hat"), p rop(100)}, |
45 » » » "nerd": {prop(103.7)}, | 45 » » » "nerd": prop(103.7), |
46 » » » "spaz": {propNI(false)}, | 46 » » » "spaz": propNI(false), |
47 }, | 47 }, |
48 withBuiltin: true, | 48 withBuiltin: true, |
49 idxs: []*ds.IndexDefinition{ | 49 idxs: []*ds.IndexDefinition{ |
50 indx("knd", "-wat", "nerd"), | 50 indx("knd", "-wat", "nerd"), |
51 }, | 51 }, |
52 expected: []serialize.SerializedPslice{ | 52 expected: []serialize.SerializedPslice{ |
53 {cat(prop(fakeKey))}, // B:knd | 53 {cat(prop(fakeKey))}, // B:knd |
54 {cat(prop(103.7), prop(fakeKey))}, // B:knd/nerd | 54 {cat(prop(103.7), prop(fakeKey))}, // B:knd/nerd |
55 { // B:knd/wat | 55 { // B:knd/wat |
56 cat(prop(100), prop(fakeKey)), | 56 cat(prop(100), prop(fakeKey)), |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 "idx:ns:" + sat(indx("knd", "-wat").PrepForIdxTable()): { | 88 "idx:ns:" + sat(indx("knd", "-wat").PrepForIdxTable()): { |
89 cat(icat(prop("hat")), prop(fakeKey)), | 89 cat(icat(prop("hat")), prop(fakeKey)), |
90 cat(icat(prop(100)), prop(fakeKey)), | 90 cat(icat(prop(100)), prop(fakeKey)), |
91 }, | 91 }, |
92 }, | 92 }, |
93 }, | 93 }, |
94 | 94 |
95 { | 95 { |
96 name: "complex", | 96 name: "complex", |
97 pmap: ds.PropertyMap{ | 97 pmap: ds.PropertyMap{ |
98 » » » "yerp": {prop("hat"), prop(73.9)}, | 98 » » » "yerp": ds.PropertySlice{prop("hat"), prop(73.9)}, |
99 » » » "wat": { | 99 » » » "wat": ds.PropertySlice{ |
100 prop(rgenComplexTime), | 100 prop(rgenComplexTime), |
101 prop([]byte("value")), | 101 prop([]byte("value")), |
102 prop(rgenComplexKey)}, | 102 prop(rgenComplexKey)}, |
103 » » » "spaz": {prop(nil), prop(false), prop(true)}, | 103 » » » "spaz": ds.PropertySlice{prop(nil), prop(false), prop(tr ue)}, |
104 }, | 104 }, |
105 idxs: []*ds.IndexDefinition{ | 105 idxs: []*ds.IndexDefinition{ |
106 indx("knd", "-wat", "nerd", "spaz"), // doesn't match, s o empty | 106 indx("knd", "-wat", "nerd", "spaz"), // doesn't match, s o empty |
107 indx("knd", "yerp", "-wat", "spaz"), | 107 indx("knd", "yerp", "-wat", "spaz"), |
108 }, | 108 }, |
109 expected: []serialize.SerializedPslice{ | 109 expected: []serialize.SerializedPslice{ |
110 {}, // C:knd/-wat/nerd/spaz, no match | 110 {}, // C:knd/-wat/nerd/spaz, no match |
111 { // C:knd/yerp/-wat/spaz | 111 { // C:knd/yerp/-wat/spaz |
112 // thank goodness the binary serialization only happens 1/val in the | 112 // thank goodness the binary serialization only happens 1/val in the |
113 // real code :). | 113 // real code :). |
(...skipping 16 matching lines...) Expand all Loading... | |
130 cat(prop(73.9), icat(rgenComplexTimeIdx), prop(n il), prop(fakeKey)), | 130 cat(prop(73.9), icat(rgenComplexTimeIdx), prop(n il), prop(fakeKey)), |
131 cat(prop(73.9), icat(rgenComplexTimeIdx), prop(f alse), prop(fakeKey)), | 131 cat(prop(73.9), icat(rgenComplexTimeIdx), prop(f alse), prop(fakeKey)), |
132 cat(prop(73.9), icat(rgenComplexTimeIdx), prop(t rue), prop(fakeKey)), | 132 cat(prop(73.9), icat(rgenComplexTimeIdx), prop(t rue), prop(fakeKey)), |
133 }, | 133 }, |
134 }, | 134 }, |
135 }, | 135 }, |
136 | 136 |
137 { | 137 { |
138 name: "ancestor", | 138 name: "ancestor", |
139 pmap: ds.PropertyMap{ | 139 pmap: ds.PropertyMap{ |
140 » » » "wat": {prop("sup")}, | 140 » » » "wat": prop("sup"), |
141 }, | 141 }, |
142 idxs: []*ds.IndexDefinition{ | 142 idxs: []*ds.IndexDefinition{ |
143 indx("knd!", "wat"), | 143 indx("knd!", "wat"), |
144 }, | 144 }, |
145 collections: map[string][][]byte{ | 145 collections: map[string][][]byte{ |
146 "idx:ns:" + sat(indx("knd!", "wat").PrepForIdxTable()): { | 146 "idx:ns:" + sat(indx("knd!", "wat").PrepForIdxTable()): { |
147 cat(prop(fakeKey.Parent()), prop("sup"), prop(fa keKey)), | 147 cat(prop(fakeKey.Parent()), prop("sup"), prop(fa keKey)), |
148 cat(prop(fakeKey), prop("sup"), prop(fakeKey)), | 148 cat(prop(fakeKey), prop("sup"), prop(fakeKey)), |
149 }, | 149 }, |
150 }, | 150 }, |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
208 numItems, _ := s.GetCollection("idx").GetTotals( ) | 208 numItems, _ := s.GetCollection("idx").GetTotals( ) |
209 So(numItems, ShouldEqual, 1) | 209 So(numItems, ShouldEqual, 1) |
210 itm := s.GetCollection("idx").MinItem(false) | 210 itm := s.GetCollection("idx").MinItem(false) |
211 So(itm.Key, ShouldResemble, cat(indx("knd").Prep ForIdxTable())) | 211 So(itm.Key, ShouldResemble, cat(indx("knd").Prep ForIdxTable())) |
212 numItems, _ = s.GetCollection("idx:ns:" + string (itm.Key)).GetTotals() | 212 numItems, _ = s.GetCollection("idx:ns:" + string (itm.Key)).GetTotals() |
213 So(numItems, ShouldEqual, 1) | 213 So(numItems, ShouldEqual, 1) |
214 }) | 214 }) |
215 | 215 |
216 Convey("defaultIndexes", func() { | 216 Convey("defaultIndexes", func() { |
217 pm := ds.PropertyMap{ | 217 pm := ds.PropertyMap{ |
218 » » » » » "wat": {propNI("thing"), prop("hat"), p rop(100)}, | 218 » » » » » "wat": ds.PropertySlice{propNI("thing") , prop("hat"), prop(100)}, |
219 » » » » » "nerd": {prop(103.7)}, | 219 » » » » » "nerd": prop(103.7), |
220 » » » » » "spaz": {propNI(false)}, | 220 » » » » » "spaz": propNI(false), |
221 } | 221 } |
222 idxs := defaultIndexes("knd", pm) | 222 idxs := defaultIndexes("knd", pm) |
223 So(len(idxs), ShouldEqual, 5) | 223 So(len(idxs), ShouldEqual, 5) |
224 So(idxs[0].String(), ShouldEqual, "B:knd") | 224 So(idxs[0].String(), ShouldEqual, "B:knd") |
225 So(idxs[1].String(), ShouldEqual, "B:knd/nerd") | 225 So(idxs[1].String(), ShouldEqual, "B:knd/nerd") |
226 So(idxs[2].String(), ShouldEqual, "B:knd/wat") | 226 So(idxs[2].String(), ShouldEqual, "B:knd/wat") |
227 So(idxs[3].String(), ShouldEqual, "B:knd/-nerd") | 227 So(idxs[3].String(), ShouldEqual, "B:knd/-nerd") |
228 So(idxs[4].String(), ShouldEqual, "B:knd/-wat") | 228 So(idxs[4].String(), ShouldEqual, "B:knd/-wat") |
229 }) | 229 }) |
230 | 230 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
276 name string | 276 name string |
277 idxs []*ds.IndexDefinition | 277 idxs []*ds.IndexDefinition |
278 data []dumbItem | 278 data []dumbItem |
279 expected map[string][][]byte | 279 expected map[string][][]byte |
280 }{ | 280 }{ |
281 | 281 |
282 { | 282 { |
283 name: "basic", | 283 name: "basic", |
284 data: []dumbItem{ | 284 data: []dumbItem{ |
285 {key("knd", 1), ds.PropertyMap{ | 285 {key("knd", 1), ds.PropertyMap{ |
286 » » » » "wat": {prop(10)}, | 286 » » » » "wat": prop(10), |
287 » » » » "yerp": {prop(10)}}, | 287 » » » » "yerp": prop(10)}, |
288 }, | 288 }, |
289 {key("knd", 10), ds.PropertyMap{ | 289 {key("knd", 10), ds.PropertyMap{ |
290 » » » » "wat": {prop(1)}, | 290 » » » » "wat": prop(1), |
291 » » » » "yerp": {prop(200)}}, | 291 » » » » "yerp": prop(200)}, |
292 }, | 292 }, |
293 {key("knd", 1), ds.PropertyMap{ | 293 {key("knd", 1), ds.PropertyMap{ |
294 » » » » "wat": {prop(10)}, | 294 » » » » "wat": prop(10), |
295 » » » » "yerp": {prop(202)}}, | 295 » » » » "yerp": prop(202)}, |
296 }, | 296 }, |
297 }, | 297 }, |
298 expected: map[string][][]byte{ | 298 expected: map[string][][]byte{ |
299 "idx:ns:" + sat(indx("knd", "wat").PrepForIdxTable()): { | 299 "idx:ns:" + sat(indx("knd", "wat").PrepForIdxTable()): { |
300 cat(prop(1), prop(key("knd", 10))), | 300 cat(prop(1), prop(key("knd", 10))), |
301 cat(prop(10), prop(key("knd", 1))), | 301 cat(prop(10), prop(key("knd", 1))), |
302 }, | 302 }, |
303 "idx:ns:" + sat(indx("knd", "-wat").PrepForIdxTable()): { | 303 "idx:ns:" + sat(indx("knd", "-wat").PrepForIdxTable()): { |
304 cat(icat(prop(10)), prop(key("knd", 1))), | 304 cat(icat(prop(10)), prop(key("knd", 1))), |
305 cat(icat(prop(1)), prop(key("knd", 10))), | 305 cat(icat(prop(1)), prop(key("knd", 10))), |
306 }, | 306 }, |
307 "idx:ns:" + sat(indx("knd", "yerp").PrepForIdxTable()): { | 307 "idx:ns:" + sat(indx("knd", "yerp").PrepForIdxTable()): { |
308 cat(prop(200), prop(key("knd", 10))), | 308 cat(prop(200), prop(key("knd", 10))), |
309 cat(prop(202), prop(key("knd", 1))), | 309 cat(prop(202), prop(key("knd", 1))), |
310 }, | 310 }, |
311 }, | 311 }, |
312 }, | 312 }, |
313 | 313 |
314 { | 314 { |
315 name: "compound", | 315 name: "compound", |
316 idxs: []*ds.IndexDefinition{indx("knd", "yerp", "-wat")}, | 316 idxs: []*ds.IndexDefinition{indx("knd", "yerp", "-wat")}, |
317 data: []dumbItem{ | 317 data: []dumbItem{ |
318 {key("knd", 1), ds.PropertyMap{ | 318 {key("knd", 1), ds.PropertyMap{ |
319 » » » » "wat": {prop(10)}, | 319 » » » » "wat": prop(10), |
320 » » » » "yerp": {prop(100)}}, | 320 » » » » "yerp": prop(100)}, |
321 }, | 321 }, |
322 {key("knd", 10), ds.PropertyMap{ | 322 {key("knd", 10), ds.PropertyMap{ |
323 » » » » "wat": {prop(1)}, | 323 » » » » "wat": prop(1), |
324 » » » » "yerp": {prop(200)}}, | 324 » » » » "yerp": prop(200)}, |
325 }, | 325 }, |
326 {key("knd", 11), ds.PropertyMap{ | 326 {key("knd", 11), ds.PropertyMap{ |
327 » » » » "wat": {prop(20)}, | 327 » » » » "wat": prop(20), |
328 » » » » "yerp": {prop(200)}}, | 328 » » » » "yerp": prop(200)}, |
329 }, | 329 }, |
330 {key("knd", 14), ds.PropertyMap{ | 330 {key("knd", 14), ds.PropertyMap{ |
331 » » » » "wat": {prop(20)}, | 331 » » » » "wat": prop(20), |
332 » » » » "yerp": {prop(200)}}, | 332 » » » » "yerp": prop(200)}, |
333 }, | 333 }, |
334 {key("knd", 1), ds.PropertyMap{ | 334 {key("knd", 1), ds.PropertyMap{ |
335 » » » » "wat": {prop(10)}, | 335 » » » » "wat": prop(10), |
336 » » » » "yerp": {prop(202)}}, | 336 » » » » "yerp": prop(202)}, |
337 }, | 337 }, |
338 }, | 338 }, |
339 expected: map[string][][]byte{ | 339 expected: map[string][][]byte{ |
340 "idx:ns:" + sat(indx("knd", "yerp", "-wat").PrepForIdxTa ble()): { | 340 "idx:ns:" + sat(indx("knd", "yerp", "-wat").PrepForIdxTa ble()): { |
341 cat(prop(200), icat(prop(20)), prop(key("knd", 1 1))), | 341 cat(prop(200), icat(prop(20)), prop(key("knd", 1 1))), |
342 cat(prop(200), icat(prop(20)), prop(key("knd", 1 4))), | 342 cat(prop(200), icat(prop(20)), prop(key("knd", 1 4))), |
343 cat(prop(200), icat(prop(1)), prop(key("knd", 10 ))), | 343 cat(prop(200), icat(prop(1)), prop(key("knd", 10 ))), |
344 cat(prop(202), icat(prop(10)), prop(key("knd", 1 ))), | 344 cat(prop(202), icat(prop(10)), prop(key("knd", 1 ))), |
345 }, | 345 }, |
346 }, | 346 }, |
(...skipping 29 matching lines...) Expand all Loading... | |
376 So(data[i], ShouldResemble, itm. Key) | 376 So(data[i], ShouldResemble, itm. Key) |
377 i++ | 377 i++ |
378 return true | 378 return true |
379 }) | 379 }) |
380 So(i, ShouldEqual, len(data)) | 380 So(i, ShouldEqual, len(data)) |
381 } | 381 } |
382 }) | 382 }) |
383 } | 383 } |
384 }) | 384 }) |
385 } | 385 } |
OLD | NEW |