OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 package dsQueryBatch | |
6 | |
7 import ( | |
8 "fmt" | |
9 "testing" | |
10 | |
11 "github.com/luci/gae/filter/count" | |
12 "github.com/luci/gae/impl/memory" | |
13 ds "github.com/luci/gae/service/datastore" | |
14 "golang.org/x/net/context" | |
15 | |
16 . "github.com/smartystreets/goconvey/convey" | |
17 ) | |
18 | |
19 type Item struct { | |
20 ID int64 `gae:"$id"` | |
21 } | |
22 | |
23 func TestRun(t *testing.T) { | |
24 t.Parallel() | |
25 | |
26 Convey("A memory with a counting filter and data set installed", t, func () { | |
27 c, cf := count.FilterRDS(memory.Use(context.Background())) | |
28 | |
29 items := make([]*Item, 1024) | |
30 for i := range items { | |
31 items[i] = &Item{int64(i + 1)} | |
32 } | |
33 if err := ds.Get(c).PutMulti(items); err != nil { | |
34 panic(err) | |
35 } | |
36 ds.Get(c).Testable().CatchupIndexes() | |
37 | |
38 for _, size := range []int{ | |
39 1, | |
40 16, | |
41 1024, | |
42 2048, | |
43 4096, | |
44 } { | |
45 Convey(fmt.Sprintf(`With a batch filter size %d installe d`, size), func() { | |
46 c = BatchQueries(c, int32(size)) | |
47 q := ds.NewQuery("Item") | |
48 | |
49 Convey(`Can retrieve all of the items.`, func() { | |
50 var got []*Item | |
51 So(ds.Get(c).GetAll(q, &got), ShouldBeNi l) | |
52 So(got, ShouldResemble, items) | |
53 | |
54 // One call for every sub-query, plus on e to hit Stop. | |
55 runCalls := (len(items) / size) + 1 | |
56 So(cf.Run.Successes(), ShouldEqual, runC alls) | |
57 }) | |
58 | |
59 Convey(`With a limit of 128, will retrieve 128 i tems.`, func() { | |
iannucci
2016/03/31 22:40:31
other tests?
batch 128 limit 127/129
non-even batc
dnj
2016/03/31 23:54:06
Done.
| |
60 const limit = 128 | |
61 q = q.Limit(int32(limit)) | |
62 | |
63 var got []*Item | |
64 So(ds.Get(c).GetAll(q, &got), ShouldBeNi l) | |
65 So(got, ShouldResemble, items[:limit]) | |
66 | |
67 // One call for every sub-query, plus on e to hit Stop. | |
68 runCalls := (limit / size) | |
69 if size > limit { | |
70 runCalls++ | |
71 } | |
72 So(cf.Run.Successes(), ShouldEqual, runC alls) | |
73 }) | |
74 }) | |
75 } | |
76 }) | |
77 } | |
OLD | NEW |