Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Side by Side Diff: impl/memory/plist_test.go

Issue 1259593005: Add 'user friendly' datastore API. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: 100% coverage of new code Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package memory 5 package memory
6 6
7 import ( 7 import (
8 "testing" 8 "testing"
9 "time" 9 "time"
10 10
11 » rds "github.com/luci/gae/service/rawdatastore" 11 » ds "github.com/luci/gae/service/datastore"
12 "github.com/luci/gkvlite" 12 "github.com/luci/gkvlite"
13 . "github.com/smartystreets/goconvey/convey" 13 . "github.com/smartystreets/goconvey/convey"
14 ) 14 )
15 15
16 func init() { 16 func init() {
17 indexCreationDeterministic = true 17 indexCreationDeterministic = true
18 } 18 }
19 19
20 var fakeKey = key("knd", 10, key("parentKind", "sid")) 20 var fakeKey = key("knd", 10, key("parentKind", "sid"))
21 21
22 func TestCollated(t *testing.T) { 22 func TestCollated(t *testing.T) {
23 t.Parallel() 23 t.Parallel()
24 24
25 Convey("TestCollated", t, func() { 25 Convey("TestCollated", t, func() {
26 Convey("nil list", func() { 26 Convey("nil list", func() {
27 » » » pm := (rds.PropertyMap)(nil) 27 » » » pm := (ds.PropertyMap)(nil)
28 sip := partiallySerialize(pm) 28 sip := partiallySerialize(pm)
29 So(sip, ShouldBeNil) 29 So(sip, ShouldBeNil)
30 30
31 Convey("nil collated", func() { 31 Convey("nil collated", func() {
32 Convey("defaultIndicies", func() { 32 Convey("defaultIndicies", func() {
33 idxs := defaultIndicies("knd", pm) 33 idxs := defaultIndicies("knd", pm)
34 So(len(idxs), ShouldEqual, 1) 34 So(len(idxs), ShouldEqual, 1)
35 So(idxs[0].String(), ShouldEqual, "B:knd ") 35 So(idxs[0].String(), ShouldEqual, "B:knd ")
36 }) 36 })
37 Convey("indexEntries", func() { 37 Convey("indexEntries", func() {
38 s := sip.indexEntries(fakeKey, defaultIn dicies("knd", pm)) 38 s := sip.indexEntries(fakeKey, defaultIn dicies("knd", pm))
39 numItems, _ := s.GetCollection("idx").Ge tTotals() 39 numItems, _ := s.GetCollection("idx").Ge tTotals()
40 So(numItems, ShouldEqual, 1) 40 So(numItems, ShouldEqual, 1)
41 itm := s.GetCollection("idx").MinItem(fa lse) 41 itm := s.GetCollection("idx").MinItem(fa lse)
42 So(itm.Key, ShouldResemble, cat(indx("kn d"))) 42 So(itm.Key, ShouldResemble, cat(indx("kn d")))
43 numItems, _ = s.GetCollection("idx:ns:" + string(itm.Key)).GetTotals() 43 numItems, _ = s.GetCollection("idx:ns:" + string(itm.Key)).GetTotals()
44 So(numItems, ShouldEqual, 1) 44 So(numItems, ShouldEqual, 1)
45 }) 45 })
46 }) 46 })
47 }) 47 })
48 48
49 Convey("list", func() { 49 Convey("list", func() {
50 » » » pm := rds.PropertyMap{ 50 » » » pm := ds.PropertyMap{
51 "wat": {propNI("thing"), prop("hat"), prop(100) }, 51 "wat": {propNI("thing"), prop("hat"), prop(100) },
52 "nerd": {prop(103.7)}, 52 "nerd": {prop(103.7)},
53 "spaz": {propNI(false)}, 53 "spaz": {propNI(false)},
54 } 54 }
55 sip := partiallySerialize(pm) 55 sip := partiallySerialize(pm)
56 So(len(sip), ShouldEqual, 2) 56 So(len(sip), ShouldEqual, 2)
57 57
58 Convey("single collated", func() { 58 Convey("single collated", func() {
59 Convey("indexableMap", func() { 59 Convey("indexableMap", func() {
60 So(sip, ShouldResemble, serializedIndexa blePmap{ 60 So(sip, ShouldResemble, serializedIndexa blePmap{
61 "wat": { 61 "wat": {
62 » » » » » » » cat(rds.PTInt, 100), 62 » » » » » » » cat(ds.PTInt, 100),
63 » » » » » » » cat(rds.PTString, "hat") , 63 » » » » » » » cat(ds.PTString, "hat"),
64 // 'thing' is skipped, b ecause it's not NoIndex 64 // 'thing' is skipped, b ecause it's not NoIndex
65 }, 65 },
66 "nerd": { 66 "nerd": {
67 » » » » » » » cat(rds.PTFloat, 103.7), 67 » » » » » » » cat(ds.PTFloat, 103.7),
68 }, 68 },
69 }) 69 })
70 }) 70 })
71 Convey("defaultIndicies", func() { 71 Convey("defaultIndicies", func() {
72 idxs := defaultIndicies("knd", pm) 72 idxs := defaultIndicies("knd", pm)
73 So(len(idxs), ShouldEqual, 5) 73 So(len(idxs), ShouldEqual, 5)
74 So(idxs[0].String(), ShouldEqual, "B:knd ") 74 So(idxs[0].String(), ShouldEqual, "B:knd ")
75 So(idxs[1].String(), ShouldEqual, "B:knd /-nerd") 75 So(idxs[1].String(), ShouldEqual, "B:knd /-nerd")
76 So(idxs[2].String(), ShouldEqual, "B:knd /-wat") 76 So(idxs[2].String(), ShouldEqual, "B:knd /-wat")
77 So(idxs[3].String(), ShouldEqual, "B:knd /nerd") 77 So(idxs[3].String(), ShouldEqual, "B:knd /nerd")
78 So(idxs[4].String(), ShouldEqual, "B:knd /wat") 78 So(idxs[4].String(), ShouldEqual, "B:knd /wat")
79 }) 79 })
80 }) 80 })
81 }) 81 })
82 }) 82 })
83 } 83 }
84 84
85 var rgenComplexTime = time.Date( 85 var rgenComplexTime = time.Date(
86 1986, time.October, 26, 1, 20, 00, 00, time.UTC) 86 1986, time.October, 26, 1, 20, 00, 00, time.UTC)
87 var rgenComplexKey = key("kind", "id") 87 var rgenComplexKey = key("kind", "id")
88 88
89 var rowGenTestCases = []struct { 89 var rowGenTestCases = []struct {
90 name string 90 name string
91 » pmap rds.PropertyMap 91 » pmap ds.PropertyMap
92 withBuiltin bool 92 withBuiltin bool
93 idxs []*qIndex 93 idxs []*qIndex
94 94
95 // These are checked in TestIndexRowGen. nil to skip test case. 95 // These are checked in TestIndexRowGen. nil to skip test case.
96 expected []serializedPvals 96 expected []serializedPvals
97 97
98 // just the collections you want to assert. These are checked in 98 // just the collections you want to assert. These are checked in
99 // TestIndexEntries. nil to skip test case. 99 // TestIndexEntries. nil to skip test case.
100 collections map[string][]kv 100 collections map[string][]kv
101 }{ 101 }{
102 { 102 {
103 name: "simple including builtins", 103 name: "simple including builtins",
104 » » pmap: rds.PropertyMap{ 104 » » pmap: ds.PropertyMap{
105 "wat": {propNI("thing"), prop("hat"), prop(100)}, 105 "wat": {propNI("thing"), prop("hat"), prop(100)},
106 "nerd": {prop(103.7)}, 106 "nerd": {prop(103.7)},
107 "spaz": {propNI(false)}, 107 "spaz": {propNI(false)},
108 }, 108 },
109 withBuiltin: true, 109 withBuiltin: true,
110 idxs: []*qIndex{ 110 idxs: []*qIndex{
111 indx("knd", "-wat", "nerd"), 111 indx("knd", "-wat", "nerd"),
112 }, 112 },
113 expected: []serializedPvals{ 113 expected: []serializedPvals{
114 {{}}, // B:knd 114 {{}}, // B:knd
115 » » » {icat(rds.PTFloat, 103.7)}, // B: knd/-nerd 115 » » » {icat(ds.PTFloat, 103.7)}, // B:kn d/-nerd
116 » » » {icat(rds.PTString, "hat"), icat(rds.PTInt, 100)}, // B: knd/-wat 116 » » » {icat(ds.PTString, "hat"), icat(ds.PTInt, 100)}, // B:kn d/-wat
117 » » » {cat(rds.PTFloat, 103.7)}, // B: knd/nerd 117 » » » {cat(ds.PTFloat, 103.7)}, // B:kn d/nerd
118 » » » {cat(rds.PTInt, 100), cat(rds.PTString, "hat")}, // B: knd/wat 118 » » » {cat(ds.PTInt, 100), cat(ds.PTString, "hat")}, // B:kn d/wat
119 { // B:knd/-wat/nerd 119 { // B:knd/-wat/nerd
120 » » » » cat(icat(rds.PTString, "hat"), cat(rds.PTFloat, 103.7)), 120 » » » » cat(icat(ds.PTString, "hat"), cat(ds.PTFloat, 10 3.7)),
121 » » » » cat(icat(rds.PTInt, 100), cat(rds.PTFloat, 103.7 )), 121 » » » » cat(icat(ds.PTInt, 100), cat(ds.PTFloat, 103.7)) ,
122 }, 122 },
123 }, 123 },
124 collections: map[string][]kv{ 124 collections: map[string][]kv{
125 "idx": { 125 "idx": {
126 // 0 == builtin, 1 == complex 126 // 0 == builtin, 1 == complex
127 {cat(byte(0), "knd", byte(1), 0), []byte{}}, 127 {cat(byte(0), "knd", byte(1), 0), []byte{}},
128 {cat(byte(0), "knd", byte(1), 1, byte(0), "nerd" ), []byte{}}, 128 {cat(byte(0), "knd", byte(1), 1, byte(0), "nerd" ), []byte{}},
129 {cat(byte(0), "knd", byte(1), 1, byte(0), "wat") , []byte{}}, 129 {cat(byte(0), "knd", byte(1), 1, byte(0), "wat") , []byte{}},
130 {cat(byte(0), "knd", byte(1), 1, byte(1), "nerd" ), []byte{}}, 130 {cat(byte(0), "knd", byte(1), 1, byte(1), "nerd" ), []byte{}},
131 {cat(byte(0), "knd", byte(1), 1, byte(1), "wat") , []byte{}}, 131 {cat(byte(0), "knd", byte(1), 1, byte(1), "wat") , []byte{}},
132 {cat(byte(1), "knd", byte(1), 2, byte(1), "wat", byte(0), "nerd"), []byte{}}, 132 {cat(byte(1), "knd", byte(1), 2, byte(1), "wat", byte(0), "nerd"), []byte{}},
133 }, 133 },
134 "idx:ns:" + sat(indx("knd")): { 134 "idx:ns:" + sat(indx("knd")): {
135 {cat(fakeKey), []byte{}}, 135 {cat(fakeKey), []byte{}},
136 }, 136 },
137 "idx:ns:" + sat(indx("knd", "wat")): { 137 "idx:ns:" + sat(indx("knd", "wat")): {
138 » » » » {cat(rds.PTInt, 100, fakeKey), []byte{}}, 138 » » » » {cat(ds.PTInt, 100, fakeKey), []byte{}},
139 » » » » {cat(rds.PTString, "hat", fakeKey), cat(rds.PTIn t, 100)}, 139 » » » » {cat(ds.PTString, "hat", fakeKey), cat(ds.PTInt, 100)},
140 }, 140 },
141 "idx:ns:" + sat(indx("knd", "-wat")): { 141 "idx:ns:" + sat(indx("knd", "-wat")): {
142 » » » » {cat(icat(rds.PTString, "hat"), fakeKey), []byte {}}, 142 » » » » {cat(icat(ds.PTString, "hat"), fakeKey), []byte{ }},
143 » » » » {cat(icat(rds.PTInt, 100), fakeKey), icat(rds.PT String, "hat")}, 143 » » » » {cat(icat(ds.PTInt, 100), fakeKey), icat(ds.PTSt ring, "hat")},
144 }, 144 },
145 }, 145 },
146 }, 146 },
147 { 147 {
148 name: "complex", 148 name: "complex",
149 » » pmap: rds.PropertyMap{ 149 » » pmap: ds.PropertyMap{
150 "yerp": {prop("hat"), prop(73.9)}, 150 "yerp": {prop("hat"), prop(73.9)},
151 "wat": { 151 "wat": {
152 prop(rgenComplexTime), 152 prop(rgenComplexTime),
153 » » » » prop(rds.ByteString("value")), 153 » » » » prop(ds.ByteString("value")),
154 prop(rgenComplexKey)}, 154 prop(rgenComplexKey)},
155 "spaz": {prop(nil), prop(false), prop(true)}, 155 "spaz": {prop(nil), prop(false), prop(true)},
156 }, 156 },
157 idxs: []*qIndex{ 157 idxs: []*qIndex{
158 indx("knd", "-wat", "nerd", "spaz"), // doesn't match, s o empty 158 indx("knd", "-wat", "nerd", "spaz"), // doesn't match, s o empty
159 indx("knd", "yerp", "-wat", "spaz"), 159 indx("knd", "yerp", "-wat", "spaz"),
160 }, 160 },
161 expected: []serializedPvals{ 161 expected: []serializedPvals{
162 {}, // C:knd/-wat/nerd/spaz, no match 162 {}, // C:knd/-wat/nerd/spaz, no match
163 { // C:knd/yerp/-wat/spaz 163 { // C:knd/yerp/-wat/spaz
164 // thank goodness the binary serialization only happens 1/val in the 164 // thank goodness the binary serialization only happens 1/val in the
165 // real code :). 165 // real code :).
166 » » » » cat(cat(rds.PTString, "hat"), icat(rds.PTKey, rg enComplexKey), cat(rds.PTNull)), 166 » » » » cat(cat(ds.PTString, "hat"), icat(ds.PTKey, rgen ComplexKey), cat(ds.PTNull)),
167 » » » » cat(cat(rds.PTString, "hat"), icat(rds.PTKey, rg enComplexKey), cat(rds.PTBoolFalse)), 167 » » » » cat(cat(ds.PTString, "hat"), icat(ds.PTKey, rgen ComplexKey), cat(ds.PTBoolFalse)),
168 » » » » cat(cat(rds.PTString, "hat"), icat(rds.PTKey, rg enComplexKey), cat(rds.PTBoolTrue)), 168 » » » » cat(cat(ds.PTString, "hat"), icat(ds.PTKey, rgen ComplexKey), cat(ds.PTBoolTrue)),
169 » » » » cat(cat(rds.PTString, "hat"), icat(rds.PTBytes, "value"), cat(rds.PTNull)), 169 » » » » cat(cat(ds.PTString, "hat"), icat(ds.PTBytes, "v alue"), cat(ds.PTNull)),
170 » » » » cat(cat(rds.PTString, "hat"), icat(rds.PTBytes, "value"), cat(rds.PTBoolFalse)), 170 » » » » cat(cat(ds.PTString, "hat"), icat(ds.PTBytes, "v alue"), cat(ds.PTBoolFalse)),
171 » » » » cat(cat(rds.PTString, "hat"), icat(rds.PTBytes, "value"), cat(rds.PTBoolTrue)), 171 » » » » cat(cat(ds.PTString, "hat"), icat(ds.PTBytes, "v alue"), cat(ds.PTBoolTrue)),
172 » » » » cat(cat(rds.PTString, "hat"), icat(rds.PTTime, r genComplexTime), cat(rds.PTNull)), 172 » » » » cat(cat(ds.PTString, "hat"), icat(ds.PTTime, rge nComplexTime), cat(ds.PTNull)),
173 » » » » cat(cat(rds.PTString, "hat"), icat(rds.PTTime, r genComplexTime), cat(rds.PTBoolFalse)), 173 » » » » cat(cat(ds.PTString, "hat"), icat(ds.PTTime, rge nComplexTime), cat(ds.PTBoolFalse)),
174 » » » » cat(cat(rds.PTString, "hat"), icat(rds.PTTime, r genComplexTime), cat(rds.PTBoolTrue)), 174 » » » » cat(cat(ds.PTString, "hat"), icat(ds.PTTime, rge nComplexTime), cat(ds.PTBoolTrue)),
175 175
176 » » » » cat(cat(rds.PTFloat, 73.9), icat(rds.PTKey, rgen ComplexKey), cat(rds.PTNull)), 176 » » » » cat(cat(ds.PTFloat, 73.9), icat(ds.PTKey, rgenCo mplexKey), cat(ds.PTNull)),
177 » » » » cat(cat(rds.PTFloat, 73.9), icat(rds.PTKey, rgen ComplexKey), cat(rds.PTBoolFalse)), 177 » » » » cat(cat(ds.PTFloat, 73.9), icat(ds.PTKey, rgenCo mplexKey), cat(ds.PTBoolFalse)),
178 » » » » cat(cat(rds.PTFloat, 73.9), icat(rds.PTKey, rgen ComplexKey), cat(rds.PTBoolTrue)), 178 » » » » cat(cat(ds.PTFloat, 73.9), icat(ds.PTKey, rgenCo mplexKey), cat(ds.PTBoolTrue)),
179 » » » » cat(cat(rds.PTFloat, 73.9), icat(rds.PTBytes, "v alue"), cat(rds.PTNull)), 179 » » » » cat(cat(ds.PTFloat, 73.9), icat(ds.PTBytes, "val ue"), cat(ds.PTNull)),
180 » » » » cat(cat(rds.PTFloat, 73.9), icat(rds.PTBytes, "v alue"), cat(rds.PTBoolFalse)), 180 » » » » cat(cat(ds.PTFloat, 73.9), icat(ds.PTBytes, "val ue"), cat(ds.PTBoolFalse)),
181 » » » » cat(cat(rds.PTFloat, 73.9), icat(rds.PTBytes, "v alue"), cat(rds.PTBoolTrue)), 181 » » » » cat(cat(ds.PTFloat, 73.9), icat(ds.PTBytes, "val ue"), cat(ds.PTBoolTrue)),
182 » » » » cat(cat(rds.PTFloat, 73.9), icat(rds.PTTime, rge nComplexTime), cat(rds.PTNull)), 182 » » » » cat(cat(ds.PTFloat, 73.9), icat(ds.PTTime, rgenC omplexTime), cat(ds.PTNull)),
183 » » » » cat(cat(rds.PTFloat, 73.9), icat(rds.PTTime, rge nComplexTime), cat(rds.PTBoolFalse)), 183 » » » » cat(cat(ds.PTFloat, 73.9), icat(ds.PTTime, rgenC omplexTime), cat(ds.PTBoolFalse)),
184 » » » » cat(cat(rds.PTFloat, 73.9), icat(rds.PTTime, rge nComplexTime), cat(rds.PTBoolTrue)), 184 » » » » cat(cat(ds.PTFloat, 73.9), icat(ds.PTTime, rgenC omplexTime), cat(ds.PTBoolTrue)),
185 }, 185 },
186 }, 186 },
187 }, 187 },
188 { 188 {
189 name: "ancestor", 189 name: "ancestor",
190 » » pmap: rds.PropertyMap{ 190 » » pmap: ds.PropertyMap{
191 "wat": {prop("sup")}, 191 "wat": {prop("sup")},
192 }, 192 },
193 idxs: []*qIndex{ 193 idxs: []*qIndex{
194 indx("knd!", "wat"), 194 indx("knd!", "wat"),
195 }, 195 },
196 collections: map[string][]kv{ 196 collections: map[string][]kv{
197 "idx:ns:" + sat(indx("knd!", "wat")): { 197 "idx:ns:" + sat(indx("knd!", "wat")): {
198 » » » » {cat(fakeKey.Parent(), rds.PTString, "sup", fake Key), []byte{}}, 198 » » » » {cat(fakeKey.Parent(), ds.PTString, "sup", fakeK ey), []byte{}},
199 » » » » {cat(fakeKey, rds.PTString, "sup", fakeKey), []b yte{}}, 199 » » » » {cat(fakeKey, ds.PTString, "sup", fakeKey), []by te{}},
200 }, 200 },
201 }, 201 },
202 }, 202 },
203 } 203 }
204 204
205 func TestIndexRowGen(t *testing.T) { 205 func TestIndexRowGen(t *testing.T) {
206 t.Parallel() 206 t.Parallel()
207 207
208 Convey("Test Index Row Generation", t, func() { 208 Convey("Test Index Row Generation", t, func() {
209 for _, tc := range rowGenTestCases { 209 for _, tc := range rowGenTestCases {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 return true 269 return true
270 }) 270 })
271 So(i, ShouldEqual, len(vals)) 271 So(i, ShouldEqual, len(vals))
272 } 272 }
273 }) 273 })
274 } 274 }
275 }) 275 })
276 } 276 }
277 277
278 type dumbItem struct { 278 type dumbItem struct {
279 » key rds.Key 279 » key ds.Key
280 » props rds.PropertyMap 280 » props ds.PropertyMap
281 } 281 }
282 282
283 var updateIndiciesTests = []struct { 283 var updateIndiciesTests = []struct {
284 name string 284 name string
285 idxs []*qIndex 285 idxs []*qIndex
286 data []dumbItem 286 data []dumbItem
287 expected map[string][][]byte 287 expected map[string][][]byte
288 }{ 288 }{
289 { 289 {
290 name: "basic", 290 name: "basic",
291 data: []dumbItem{ 291 data: []dumbItem{
292 » » » {key("knd", 1), rds.PropertyMap{ 292 » » » {key("knd", 1), ds.PropertyMap{
293 "wat": {prop(10)}, 293 "wat": {prop(10)},
294 "yerp": {prop(10)}}, 294 "yerp": {prop(10)}},
295 }, 295 },
296 » » » {key("knd", 10), rds.PropertyMap{ 296 » » » {key("knd", 10), ds.PropertyMap{
297 "wat": {prop(1)}, 297 "wat": {prop(1)},
298 "yerp": {prop(200)}}, 298 "yerp": {prop(200)}},
299 }, 299 },
300 » » » {key("knd", 1), rds.PropertyMap{ 300 » » » {key("knd", 1), ds.PropertyMap{
301 "wat": {prop(10)}, 301 "wat": {prop(10)},
302 "yerp": {prop(202)}}, 302 "yerp": {prop(202)}},
303 }, 303 },
304 }, 304 },
305 expected: map[string][][]byte{ 305 expected: map[string][][]byte{
306 "idx:ns:" + sat(indx("knd", "wat")): { 306 "idx:ns:" + sat(indx("knd", "wat")): {
307 » » » » cat(rds.PTInt, 1, key("knd", 10)), 307 » » » » cat(ds.PTInt, 1, key("knd", 10)),
308 » » » » cat(rds.PTInt, 10, key("knd", 1)), 308 » » » » cat(ds.PTInt, 10, key("knd", 1)),
309 }, 309 },
310 "idx:ns:" + sat(indx("knd", "-wat")): { 310 "idx:ns:" + sat(indx("knd", "-wat")): {
311 » » » » cat(icat(rds.PTInt, 10), key("knd", 1)), 311 » » » » cat(icat(ds.PTInt, 10), key("knd", 1)),
312 » » » » cat(icat(rds.PTInt, 1), key("knd", 10)), 312 » » » » cat(icat(ds.PTInt, 1), key("knd", 10)),
313 }, 313 },
314 "idx:ns:" + sat(indx("knd", "yerp")): { 314 "idx:ns:" + sat(indx("knd", "yerp")): {
315 » » » » cat(rds.PTInt, 200, key("knd", 10)), 315 » » » » cat(ds.PTInt, 200, key("knd", 10)),
316 » » » » cat(rds.PTInt, 202, key("knd", 1)), 316 » » » » cat(ds.PTInt, 202, key("knd", 1)),
317 }, 317 },
318 }, 318 },
319 }, 319 },
320 { 320 {
321 name: "compound", 321 name: "compound",
322 idxs: []*qIndex{indx("knd", "yerp", "-wat")}, 322 idxs: []*qIndex{indx("knd", "yerp", "-wat")},
323 data: []dumbItem{ 323 data: []dumbItem{
324 » » » {key("knd", 1), rds.PropertyMap{ 324 » » » {key("knd", 1), ds.PropertyMap{
325 "wat": {prop(10)}, 325 "wat": {prop(10)},
326 "yerp": {prop(100)}}, 326 "yerp": {prop(100)}},
327 }, 327 },
328 » » » {key("knd", 10), rds.PropertyMap{ 328 » » » {key("knd", 10), ds.PropertyMap{
329 "wat": {prop(1)}, 329 "wat": {prop(1)},
330 "yerp": {prop(200)}}, 330 "yerp": {prop(200)}},
331 }, 331 },
332 » » » {key("knd", 11), rds.PropertyMap{ 332 » » » {key("knd", 11), ds.PropertyMap{
333 "wat": {prop(20)}, 333 "wat": {prop(20)},
334 "yerp": {prop(200)}}, 334 "yerp": {prop(200)}},
335 }, 335 },
336 » » » {key("knd", 14), rds.PropertyMap{ 336 » » » {key("knd", 14), ds.PropertyMap{
337 "wat": {prop(20)}, 337 "wat": {prop(20)},
338 "yerp": {prop(200)}}, 338 "yerp": {prop(200)}},
339 }, 339 },
340 » » » {key("knd", 1), rds.PropertyMap{ 340 » » » {key("knd", 1), ds.PropertyMap{
341 "wat": {prop(10)}, 341 "wat": {prop(10)},
342 "yerp": {prop(202)}}, 342 "yerp": {prop(202)}},
343 }, 343 },
344 }, 344 },
345 expected: map[string][][]byte{ 345 expected: map[string][][]byte{
346 "idx:ns:" + sat(indx("knd", "yerp", "-wat")): { 346 "idx:ns:" + sat(indx("knd", "yerp", "-wat")): {
347 » » » » cat(rds.PTInt, 200, icat(rds.PTInt, 20), key("kn d", 11)), 347 » » » » cat(ds.PTInt, 200, icat(ds.PTInt, 20), key("knd" , 11)),
348 » » » » cat(rds.PTInt, 200, icat(rds.PTInt, 20), key("kn d", 14)), 348 » » » » cat(ds.PTInt, 200, icat(ds.PTInt, 20), key("knd" , 14)),
349 » » » » cat(rds.PTInt, 200, icat(rds.PTInt, 1), key("knd ", 10)), 349 » » » » cat(ds.PTInt, 200, icat(ds.PTInt, 1), key("knd", 10)),
350 » » » » cat(rds.PTInt, 202, icat(rds.PTInt, 10), key("kn d", 1)), 350 » » » » cat(ds.PTInt, 202, icat(ds.PTInt, 10), key("knd" , 1)),
351 }, 351 },
352 }, 352 },
353 }, 353 },
354 } 354 }
355 355
356 func TestUpdateIndicies(t *testing.T) { 356 func TestUpdateIndicies(t *testing.T) {
357 t.Parallel() 357 t.Parallel()
358 358
359 Convey("Test updateIndicies", t, func() { 359 Convey("Test updateIndicies", t, func() {
360 for _, tc := range updateIndiciesTests { 360 for _, tc := range updateIndiciesTests {
361 Convey(tc.name, func() { 361 Convey(tc.name, func() {
362 store := newMemStore() 362 store := newMemStore()
363 idxColl := store.SetCollection("idx", nil) 363 idxColl := store.SetCollection("idx", nil)
364 for _, i := range tc.idxs { 364 for _, i := range tc.idxs {
365 idxColl.Set(cat(i), []byte{}) 365 idxColl.Set(cat(i), []byte{})
366 } 366 }
367 367
368 » » » » tmpLoader := map[string]rds.PropertyMap{} 368 » » » » tmpLoader := map[string]ds.PropertyMap{}
369 for _, itm := range tc.data { 369 for _, itm := range tc.data {
370 ks := itm.key.String() 370 ks := itm.key.String()
371 prev := tmpLoader[ks] 371 prev := tmpLoader[ks]
372 updateIndicies(store, itm.key, prev, itm .props) 372 updateIndicies(store, itm.key, prev, itm .props)
373 tmpLoader[ks] = itm.props 373 tmpLoader[ks] = itm.props
374 } 374 }
375 tmpLoader = nil 375 tmpLoader = nil
376 376
377 for colName, data := range tc.expected { 377 for colName, data := range tc.expected {
378 coll := store.GetCollection(colName) 378 coll := store.GetCollection(colName)
379 So(coll, ShouldNotBeNil) 379 So(coll, ShouldNotBeNil)
380 i := 0 380 i := 0
381 coll.VisitItemsAscend(nil, false, func(i tm *gkvlite.Item) bool { 381 coll.VisitItemsAscend(nil, false, func(i tm *gkvlite.Item) bool {
382 So(data[i], ShouldResemble, itm. Key) 382 So(data[i], ShouldResemble, itm. Key)
383 i++ 383 i++
384 return true 384 return true
385 }) 385 })
386 So(i, ShouldEqual, len(data)) 386 So(i, ShouldEqual, len(data))
387 } 387 }
388 }) 388 })
389 } 389 }
390 }) 390 })
391 } 391 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698