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

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

Issue 1285703002: Add testable interface for datastore. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: fixes after Raw change 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
« no previous file with comments | « impl/memory/datastore_index.go ('k') | impl/memory/datastore_query.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 }, 65 },
66 "nerd": { 66 "nerd": {
67 cat(ds.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 ds.PropertyMap 91 pmap ds.PropertyMap
92 withBuiltin bool 92 withBuiltin bool
93 » idxs []*qIndex 93 » idxs []*ds.IndexDefinition
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: ds.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: []*ds.IndexDefinition{
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 {cat(ds.PTFloat, 103.7)}, // B:kn d/nerd
116 {cat(ds.PTInt, 100), cat(ds.PTString, "hat")}, // B:kn d/wat
115 {icat(ds.PTFloat, 103.7)}, // B:kn d/-nerd 117 {icat(ds.PTFloat, 103.7)}, // B:kn d/-nerd
116 {icat(ds.PTString, "hat"), icat(ds.PTInt, 100)}, // B:kn d/-wat 118 {icat(ds.PTString, "hat"), icat(ds.PTInt, 100)}, // B:kn d/-wat
117 » » » {cat(ds.PTFloat, 103.7)}, // B:kn d/nerd 119 » » » { // C:knd/-wat/nerd
118 » » » {cat(ds.PTInt, 100), cat(ds.PTString, "hat")}, // B:kn d/wat
119 » » » { // B:knd/-wat/nerd
120 cat(icat(ds.PTString, "hat"), cat(ds.PTFloat, 10 3.7)), 120 cat(icat(ds.PTString, "hat"), cat(ds.PTFloat, 10 3.7)),
121 cat(icat(ds.PTInt, 100), cat(ds.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(0), 0), []byte{}},
128 » » » » {cat(byte(0), "knd", byte(1), 1, byte(0), "nerd" ), []byte{}}, 128 » » » » {cat(byte(0), "knd", byte(0), 1, byte(0), "nerd" ), []byte{}},
129 » » » » {cat(byte(0), "knd", byte(1), 1, byte(0), "wat") , []byte{}}, 129 » » » » {cat(byte(0), "knd", byte(0), 1, byte(0), "wat") , []byte{}},
130 » » » » {cat(byte(0), "knd", byte(1), 1, byte(1), "nerd" ), []byte{}}, 130 » » » » {cat(byte(0), "knd", byte(0), 1, byte(1), "nerd" ), []byte{}},
131 » » » » {cat(byte(0), "knd", byte(1), 1, byte(1), "wat") , []byte{}}, 131 » » » » {cat(byte(0), "knd", byte(0), 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(0), 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(ds.PTInt, 100, fakeKey), []byte{}}, 138 {cat(ds.PTInt, 100, fakeKey), []byte{}},
139 {cat(ds.PTString, "hat", fakeKey), cat(ds.PTInt, 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(ds.PTString, "hat"), fakeKey), []byte{ }}, 142 {cat(icat(ds.PTString, "hat"), fakeKey), []byte{ }},
143 {cat(icat(ds.PTInt, 100), fakeKey), icat(ds.PTSt ring, "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: ds.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(ds.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: []*ds.IndexDefinition{
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(ds.PTString, "hat"), icat(ds.PTKey, rgen ComplexKey), cat(ds.PTNull)), 166 cat(cat(ds.PTString, "hat"), icat(ds.PTKey, rgen ComplexKey), cat(ds.PTNull)),
167 cat(cat(ds.PTString, "hat"), icat(ds.PTKey, rgen ComplexKey), cat(ds.PTBoolFalse)), 167 cat(cat(ds.PTString, "hat"), icat(ds.PTKey, rgen ComplexKey), cat(ds.PTBoolFalse)),
(...skipping 15 matching lines...) Expand all
183 cat(cat(ds.PTFloat, 73.9), icat(ds.PTTime, rgenC omplexTime), cat(ds.PTBoolFalse)), 183 cat(cat(ds.PTFloat, 73.9), icat(ds.PTTime, rgenC omplexTime), cat(ds.PTBoolFalse)),
184 cat(cat(ds.PTFloat, 73.9), icat(ds.PTTime, rgenC omplexTime), cat(ds.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: ds.PropertyMap{ 190 pmap: ds.PropertyMap{
191 "wat": {prop("sup")}, 191 "wat": {prop("sup")},
192 }, 192 },
193 » » idxs: []*qIndex{ 193 » » idxs: []*ds.IndexDefinition{
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(), ds.PTString, "sup", fakeK ey), []byte{}}, 198 {cat(fakeKey.Parent(), ds.PTString, "sup", fakeK ey), []byte{}},
199 {cat(fakeKey, ds.PTString, "sup", fakeKey), []by te{}}, 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 {
210 if tc.expected == nil { 210 if tc.expected == nil {
211 Convey(tc.name, nil) // shows up as 'skipped' 211 Convey(tc.name, nil) // shows up as 'skipped'
212 continue 212 continue
213 } 213 }
214 214
215 Convey(tc.name, func() { 215 Convey(tc.name, func() {
216 mvals := partiallySerialize(tc.pmap) 216 mvals := partiallySerialize(tc.pmap)
217 » » » » idxs := []*qIndex(nil) 217 » » » » idxs := []*ds.IndexDefinition(nil)
218 if tc.withBuiltin { 218 if tc.withBuiltin {
219 idxs = append(defaultIndicies("coolKind" , tc.pmap), tc.idxs...) 219 idxs = append(defaultIndicies("coolKind" , tc.pmap), tc.idxs...)
220 } else { 220 } else {
221 idxs = tc.idxs 221 idxs = tc.idxs
222 } 222 }
223 223
224 m := matcher{} 224 m := matcher{}
225 for i, idx := range idxs { 225 for i, idx := range idxs {
226 Convey(idx.String(), func() { 226 Convey(idx.String(), func() {
227 iGen, ok := m.match(idx, mvals) 227 iGen, ok := m.match(idx, mvals)
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 }) 275 })
276 } 276 }
277 277
278 type dumbItem struct { 278 type dumbItem struct {
279 key ds.Key 279 key ds.Key
280 props ds.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 []*ds.IndexDefinition
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), ds.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 },
(...skipping 16 matching lines...) Expand all
312 cat(icat(ds.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(ds.PTInt, 200, key("knd", 10)), 315 cat(ds.PTInt, 200, key("knd", 10)),
316 cat(ds.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: []*ds.IndexDefinition{indx("knd", "yerp", "-wat")},
323 data: []dumbItem{ 323 data: []dumbItem{
324 {key("knd", 1), ds.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), ds.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), ds.PropertyMap{ 332 {key("knd", 11), ds.PropertyMap{
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
« no previous file with comments | « impl/memory/datastore_index.go ('k') | impl/memory/datastore_query.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698