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

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

Issue 2604943002: impl/memory: Replace gkvlite with "treapstore". (Closed)
Patch Set: Comments. Created 3 years, 11 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_test.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 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"
11 11
12 ds "github.com/luci/gae/service/datastore" 12 ds "github.com/luci/gae/service/datastore"
13 "github.com/luci/gae/service/datastore/serialize" 13 "github.com/luci/gae/service/datastore/serialize"
14 » "github.com/luci/gkvlite" 14
15 . "github.com/smartystreets/goconvey/convey" 15 . "github.com/smartystreets/goconvey/convey"
16 ) 16 )
17 17
18 var fakeKey = key("parentKind", "sid", "knd", 10) 18 var fakeKey = key("parentKind", "sid", "knd", 10)
19 19
20 var rgenComplexTime = time.Date( 20 var rgenComplexTime = time.Date(
21 1986, time.October, 26, 1, 20, 00, 00, time.UTC) 21 1986, time.October, 26, 1, 20, 00, 00, time.UTC)
22 var rgenComplexKey = key("kind", "id") 22 var rgenComplexKey = key("kind", "id")
23 23
24 var _, rgenComplexTimeInt = prop(rgenComplexTime).IndexTypeAndValue() 24 var _, rgenComplexTimeInt = prop(rgenComplexTime).IndexTypeAndValue()
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 Convey("nil collated", func() { 198 Convey("nil collated", func() {
199 Convey("defaultIndexes (nil)", func() { 199 Convey("defaultIndexes (nil)", func() {
200 idxs := defaultIndexes("knd", ds.PropertyMap(nil )) 200 idxs := defaultIndexes("knd", ds.PropertyMap(nil ))
201 So(len(idxs), ShouldEqual, 1) 201 So(len(idxs), ShouldEqual, 1)
202 So(idxs[0].String(), ShouldEqual, "B:knd") 202 So(idxs[0].String(), ShouldEqual, "B:knd")
203 }) 203 })
204 204
205 Convey("indexEntries", func() { 205 Convey("indexEntries", func() {
206 sip := serialize.PropertyMapPartially(fakeKey, n il) 206 sip := serialize.PropertyMapPartially(fakeKey, n il)
207 s := indexEntries(fakeKey, sip, defaultIndexes(" knd", ds.PropertyMap(nil))) 207 s := indexEntries(fakeKey, sip, defaultIndexes(" knd", ds.PropertyMap(nil)))
208 » » » » numItems, _ := s.GetCollection("idx").GetTotals( ) 208 » » » » So(countItems(s.Snapshot().GetCollection("idx")) , ShouldEqual, 1)
209 » » » » So(numItems, ShouldEqual, 1) 209 » » » » itm := s.GetCollection("idx").MinItem()
210 » » » » itm := s.GetCollection("idx").MinItem(false) 210 » » » » So(itm.key, ShouldResemble, cat(indx("knd").Prep ForIdxTable()))
211 » » » » So(itm.Key, ShouldResemble, cat(indx("knd").Prep ForIdxTable())) 211 » » » » So(countItems(s.Snapshot().GetCollection("idx:ns :"+string(itm.key))), ShouldEqual, 1)
212 » » » » numItems, _ = s.GetCollection("idx:ns:" + string (itm.Key)).GetTotals()
213 » » » » So(numItems, ShouldEqual, 1)
214 }) 212 })
215 213
216 Convey("defaultIndexes", func() { 214 Convey("defaultIndexes", func() {
217 pm := ds.PropertyMap{ 215 pm := ds.PropertyMap{
218 "wat": ds.PropertySlice{propNI("thing") , prop("hat"), prop(100)}, 216 "wat": ds.PropertySlice{propNI("thing") , prop("hat"), prop(100)},
219 "nerd": prop(103.7), 217 "nerd": prop(103.7),
220 "spaz": propNI(false), 218 "spaz": propNI(false),
221 } 219 }
222 idxs := defaultIndexes("knd", pm) 220 idxs := defaultIndexes("knd", pm)
223 So(len(idxs), ShouldEqual, 5) 221 So(len(idxs), ShouldEqual, 5)
(...skipping 22 matching lines...) Expand all
246 store := (memStore)(nil) 244 store := (memStore)(nil)
247 if tc.withBuiltin { 245 if tc.withBuiltin {
248 store = indexEntriesWithBuiltins(fakeKey , tc.pmap, tc.idxs) 246 store = indexEntriesWithBuiltins(fakeKey , tc.pmap, tc.idxs)
249 } else { 247 } else {
250 sip := serialize.PropertyMapPartially(fa keKey, tc.pmap) 248 sip := serialize.PropertyMapPartially(fa keKey, tc.pmap)
251 store = indexEntries(fakeKey, sip, tc.id xs) 249 store = indexEntries(fakeKey, sip, tc.id xs)
252 } 250 }
253 for colName, vals := range tc.collections { 251 for colName, vals := range tc.collections {
254 i := 0 252 i := 0
255 coll := store.Snapshot().GetCollection(c olName) 253 coll := store.Snapshot().GetCollection(c olName)
256 » » » » » numItems, _ := coll.GetTotals() 254 » » » » » So(countItems(coll), ShouldEqual, len(tc .collections[colName]))
257 » » » » » So(numItems, ShouldEqual, len(tc.collect ions[colName])) 255
258 » » » » » coll.VisitItemsAscend(nil, true, func(it m *gkvlite.Item) bool { 256 » » » » » coll.ForEachItem(func(k, _ []byte) bool {
259 » » » » » » So(itm.Key, ShouldResemble, vals [i]) 257 » » » » » » So(k, ShouldResemble, vals[i])
260 i++ 258 i++
261 return true 259 return true
262 }) 260 })
263 So(i, ShouldEqual, len(vals)) 261 So(i, ShouldEqual, len(vals))
264 } 262 }
265 }) 263 })
266 } 264 }
267 }) 265 })
268 } 266 }
269 267
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 prev := tmpLoader[ks] 363 prev := tmpLoader[ks]
366 updateIndexes(store, itm.key, prev, itm. props) 364 updateIndexes(store, itm.key, prev, itm. props)
367 tmpLoader[ks] = itm.props 365 tmpLoader[ks] = itm.props
368 } 366 }
369 tmpLoader = nil 367 tmpLoader = nil
370 368
371 for colName, data := range tc.expected { 369 for colName, data := range tc.expected {
372 coll := store.Snapshot().GetCollection(c olName) 370 coll := store.Snapshot().GetCollection(c olName)
373 So(coll, ShouldNotBeNil) 371 So(coll, ShouldNotBeNil)
374 i := 0 372 i := 0
375 » » » » » coll.VisitItemsAscend(nil, false, func(i tm *gkvlite.Item) bool { 373 » » » » » coll.ForEachItem(func(k, _ []byte) bool {
376 » » » » » » So(data[i], ShouldResemble, itm. Key) 374 » » » » » » So(data[i], ShouldResemble, k)
377 i++ 375 i++
378 return true 376 return true
379 }) 377 })
380 So(i, ShouldEqual, len(data)) 378 So(i, ShouldEqual, len(data))
381 } 379 }
382 }) 380 })
383 } 381 }
384 }) 382 })
385 } 383 }
OLDNEW
« no previous file with comments | « impl/memory/datastore_index.go ('k') | impl/memory/datastore_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698