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

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

Issue 1521823003: Clean up callback interfaces. (Closed) Base URL: https://github.com/luci/gae.git@extra
Patch Set: fixins Created 5 years 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/gkvlite_iter.go ('k') | impl/prod/everything_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 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 "bytes" 8 "bytes"
9 "testing" 9 "testing"
10 10
11 "github.com/luci/gae/service/datastore"
11 "github.com/luci/gae/service/datastore/serialize" 12 "github.com/luci/gae/service/datastore/serialize"
12 "github.com/luci/gkvlite" 13 "github.com/luci/gkvlite"
13 "github.com/luci/luci-go/common/cmpbin" 14 "github.com/luci/luci-go/common/cmpbin"
14 . "github.com/smartystreets/goconvey/convey" 15 . "github.com/smartystreets/goconvey/convey"
15 ) 16 )
16 17
17 func mkNum(n int64) []byte { 18 func mkNum(n int64) []byte {
18 buf := &bytes.Buffer{} 19 buf := &bytes.Buffer{}
19 _, err := cmpbin.WriteInt(buf, n) 20 _, err := cmpbin.WriteInt(buf, n)
20 memoryCorruption(err) 21 memoryCorruption(err)
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 Convey("can join the same collection twice", func() { 203 Convey("can join the same collection twice", func() {
203 // get just the (1, *) 204 // get just the (1, *)
204 // starting at (1, 2) (i.e. >= 2) 205 // starting at (1, 2) (i.e. >= 2)
205 // ending at (1, 4) (i.e. < 7) 206 // ending at (1, 4) (i.e. < 7)
206 defs := []*iterDefinition{ 207 defs := []*iterDefinition{
207 {c: c, prefix: mkNum(1), prefixLen: len(mkNum(1) ), start: mkNum(2), end: mkNum(7)}, 208 {c: c, prefix: mkNum(1), prefixLen: len(mkNum(1) ), start: mkNum(2), end: mkNum(7)},
208 {c: c, prefix: mkNum(1), prefixLen: len(mkNum(1) ), start: mkNum(2), end: mkNum(7)}, 209 {c: c, prefix: mkNum(1), prefixLen: len(mkNum(1) ), start: mkNum(2), end: mkNum(7)},
209 } 210 }
210 211
211 i := 1 212 i := 1
212 » » » multiIterate(defs, func(suffix []byte) bool { 213 » » » So(multiIterate(defs, func(suffix []byte) error {
213 So(readNum(suffix), ShouldEqual, vals[i][1]) 214 So(readNum(suffix), ShouldEqual, vals[i][1])
214 i++ 215 i++
215 » » » » return true 216 » » » » return nil
216 » » » }) 217 » » » }), ShouldBeNil)
217 218
218 So(i, ShouldEqual, 3) 219 So(i, ShouldEqual, 3)
219 }) 220 })
220 221
221 Convey("can make empty iteration", func() { 222 Convey("can make empty iteration", func() {
222 // get just the (20, *) (doesn't exist) 223 // get just the (20, *) (doesn't exist)
223 defs := []*iterDefinition{ 224 defs := []*iterDefinition{
224 {c: c, prefix: mkNum(20)}, 225 {c: c, prefix: mkNum(20)},
225 {c: c, prefix: mkNum(20)}, 226 {c: c, prefix: mkNum(20)},
226 } 227 }
227 228
228 i := 0 229 i := 0
229 » » » multiIterate(defs, func(suffix []byte) bool { 230 » » » So(multiIterate(defs, func(suffix []byte) error {
230 panic("never") 231 panic("never")
231 » » » }) 232 » » » }), ShouldBeNil)
232 233
233 So(i, ShouldEqual, 0) 234 So(i, ShouldEqual, 0)
234 }) 235 })
235 236
236 Convey("can join (other, val, val)", func() { 237 Convey("can join (other, val, val)", func() {
237 // 'other' must start with 20, 'vals' must start with 1 238 // 'other' must start with 20, 'vals' must start with 1
238 // no range constraints 239 // no range constraints
239 defs := []*iterDefinition{ 240 defs := []*iterDefinition{
240 {c: c2, prefix: mkNum(20)}, 241 {c: c2, prefix: mkNum(20)},
241 {c: c, prefix: mkNum(1)}, 242 {c: c, prefix: mkNum(1)},
242 {c: c, prefix: mkNum(1)}, 243 {c: c, prefix: mkNum(1)},
243 } 244 }
244 245
245 expect := []int64{2, 4} 246 expect := []int64{2, 4}
246 i := 0 247 i := 0
247 » » » multiIterate(defs, func(suffix []byte) bool { 248 » » » So(multiIterate(defs, func(suffix []byte) error {
248 So(readNum(suffix), ShouldEqual, expect[i]) 249 So(readNum(suffix), ShouldEqual, expect[i])
249 i++ 250 i++
250 » » » » return true 251 » » » » return nil
251 » » » }) 252 » » » }), ShouldBeNil)
252 }) 253 })
253 254
254 Convey("Can stop early", func() { 255 Convey("Can stop early", func() {
255 defs := []*iterDefinition{ 256 defs := []*iterDefinition{
256 {c: c, prefix: mkNum(1), prefixLen: len(mkNum(1) )}, 257 {c: c, prefix: mkNum(1), prefixLen: len(mkNum(1) )},
257 {c: c, prefix: mkNum(1), prefixLen: len(mkNum(1) )}, 258 {c: c, prefix: mkNum(1), prefixLen: len(mkNum(1) )},
258 } 259 }
259 260
260 i := 0 261 i := 0
261 » » » multiIterate(defs, func(suffix []byte) bool { 262 » » » So(multiIterate(defs, func(suffix []byte) error {
262 So(readNum(suffix), ShouldEqual, vals[i][1]) 263 So(readNum(suffix), ShouldEqual, vals[i][1])
263 i++ 264 i++
264 » » » » return true 265 » » » » return nil
265 » » » }) 266 » » » }), ShouldBeNil)
266 So(i, ShouldEqual, 5) 267 So(i, ShouldEqual, 5)
267 268
268 i = 0 269 i = 0
269 » » » multiIterate(defs, func(suffix []byte) bool { 270 » » » So(multiIterate(defs, func(suffix []byte) error {
270 So(readNum(suffix), ShouldEqual, vals[i][1]) 271 So(readNum(suffix), ShouldEqual, vals[i][1])
271 i++ 272 i++
272 » » » » return false 273 » » » » return datastore.Stop
273 » » » }) 274 » » » }), ShouldBeNil)
274 So(i, ShouldEqual, 1) 275 So(i, ShouldEqual, 1)
275 }) 276 })
276 277
277 }) 278 })
278 279
279 } 280 }
OLDNEW
« no previous file with comments | « impl/memory/gkvlite_iter.go ('k') | impl/prod/everything_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698