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

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

Issue 1364333002: Add AutoIndex (Closed) Base URL: https://github.com/luci/gae.git@add_full_consistency
Patch Set: Created 5 years, 2 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 "fmt" 8 "fmt"
9 "strings"
9 "testing" 10 "testing"
10 "time" 11 "time"
11 12
12 ds "github.com/luci/gae/service/datastore" 13 ds "github.com/luci/gae/service/datastore"
13 "github.com/luci/gae/service/info" 14 "github.com/luci/gae/service/info"
14 . "github.com/luci/luci-go/common/testing/assertions" 15 . "github.com/luci/luci-go/common/testing/assertions"
15 . "github.com/smartystreets/goconvey/convey" 16 . "github.com/smartystreets/goconvey/convey"
16 "golang.org/x/net/context" 17 "golang.org/x/net/context"
17 ) 18 )
18 19
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 }, 103 },
103 }, 104 },
104 105
105 { 106 {
106 putEnts: stage1Data, 107 putEnts: stage1Data,
107 expect: []qExpect{ 108 expect: []qExpect{
108 {q: nq("Kind"), get: []ds.PropertyMap{}}, 109 {q: nq("Kind"), get: []ds.PropertyMap{}},
109 {q: nq("Child").Ancestor(key("Kind", 3)), keys: []*ds.Key{ 110 {q: nq("Child").Ancestor(key("Kind", 3)), keys: []*ds.Key{
110 key("Kind", 3, "Child", "seven"), 111 key("Kind", 3, "Child", "seven"),
111 }}, 112 }},
113 {q: nq("Child").Ancestor(key("Kind", 3)).Eventua lConsistency(true), keys: []*ds.Key{}},
114 {q: nq("Child").Ancestor(key("Kind", 3)).Eventua lConsistency(true), keys: []*ds.Key{
115 key("Kind", 3, "Child", "seven"),
116 }, inTxn: true},
117 {q: nq("Child").Ancestor(key("Kind", 3)), keys: []*ds.Key{
118 key("Kind", 3, "Child", "seven"),
119 }, inTxn: true},
112 }, 120 },
113 }, 121 },
114 122
115 { 123 {
116 putEnts: stage2Data, 124 putEnts: stage2Data,
117 delEnts: []*ds.Key{key("Unique", 1)}, 125 delEnts: []*ds.Key{key("Unique", 1)},
118 addIdxs: []*ds.IndexDefinition{ 126 addIdxs: []*ds.IndexDefinition{
119 indx("Kind!", "-Extra", "-Val"), 127 indx("Kind!", "-Extra", "-Val"),
120 indx("Kind!", "-Extra", "-Val", "-__key__"), 128 indx("Kind!", "-Extra", "-Val", "-__key__"),
121 indx("Kind!", "Bogus", "Extra", "-Val"), 129 indx("Kind!", "Bogus", "Extra", "-Val"),
(...skipping 22 matching lines...) Expand all
144 152
145 {q: nq("Child").Eq("Interesting", 28).Eq("Extra" , "hello"), get: []ds.PropertyMap{ 153 {q: nq("Child").Eq("Interesting", 28).Eq("Extra" , "hello"), get: []ds.PropertyMap{
146 stage1Data[4], 154 stage1Data[4],
147 }}, 155 }},
148 156
149 {q: (nq("Kind").Ancestor(key("Kind", 3)).Order(" Val"). 157 {q: (nq("Kind").Ancestor(key("Kind", 3)).Order(" Val").
150 Start(curs("Val", 1, "__key__", key("Kin d", 3))). 158 Start(curs("Val", 1, "__key__", key("Kin d", 3))).
151 End(curs("Val", 90, "__key__", key("Kind ", 3, "Zeta", "woot")))), keys: []*ds.Key{}, 159 End(curs("Val", 90, "__key__", key("Kind ", 3, "Zeta", "woot")))), keys: []*ds.Key{},
152 }, 160 },
153 161
162 {q: (nq("Kind").Ancestor(key("Kind", 3)).Order(" Val").
163 Start(curs("Val", 1, "__key__", key("Kin d", 3))).
164 End(curs("Val", 90, "__key__", key("Kind ", 3, "Zeta", "woot")))),
165 keys: []*ds.Key{},
166 inTxn: true},
167
154 {q: nq("Kind").Gt("Val", 2).Lte("Val", 5), get: []ds.PropertyMap{ 168 {q: nq("Kind").Gt("Val", 2).Lte("Val", 5), get: []ds.PropertyMap{
155 stage1Data[0], stage1Data[3], 169 stage1Data[0], stage1Data[3],
156 }}, 170 }},
157 171
158 {q: nq("Kind").Gt("Val", 2).Lte("Val", 5).Order( "-Val"), get: []ds.PropertyMap{ 172 {q: nq("Kind").Gt("Val", 2).Lte("Val", 5).Order( "-Val"), get: []ds.PropertyMap{
159 stage1Data[3], stage1Data[0], 173 stage1Data[3], stage1Data[0],
160 }}, 174 }},
161 175
162 {q: nq("").Gt("__key__", key("Kind", 2)), get: [ ]ds.PropertyMap{ 176 {q: nq("").Gt("__key__", key("Kind", 2)), get: [ ]ds.PropertyMap{
163 // TODO(riannucci): determine if the rea l datastore shows metadata 177 // TODO(riannucci): determine if the rea l datastore shows metadata
(...skipping 19 matching lines...) Expand all
183 Order("-Val"). 197 Order("-Val").
184 Ancestor(key("Kind", 3))), 198 Ancestor(key("Kind", 3))),
185 get: []ds.PropertyMap{ 199 get: []ds.PropertyMap{
186 stage1Data[2], 200 stage1Data[2],
187 stage2Data[0], 201 stage2Data[0],
188 stage2Data[1], 202 stage2Data[1],
189 }}, 203 }},
190 204
191 {q: (nq("Kind"). 205 {q: (nq("Kind").
192 Gt("Val", 2).Eq("Extra", "waffle"). 206 Gt("Val", 2).Eq("Extra", "waffle").
207 Order("-Val").
208 Ancestor(key("Kind", 3))),
209 get: []ds.PropertyMap{
210 stage1Data[2],
211 stage2Data[0],
212 stage2Data[1],
213 }, inTxn: true},
214
215 {q: (nq("Kind").
216 Gt("Val", 2).Eq("Extra", "waffle").
193 Order("-Val", "-__key__"). 217 Order("-Val", "-__key__").
194 Ancestor(key("Kind", 3))), 218 Ancestor(key("Kind", 3))),
195 get: []ds.PropertyMap{ 219 get: []ds.PropertyMap{
196 stage1Data[2], 220 stage1Data[2],
197 stage2Data[0], 221 stage2Data[0],
198 stage2Data[1], 222 stage2Data[1],
199 }}, 223 }},
200 224
201 {q: (nq("Kind"). 225 {q: (nq("Kind").
202 Gt("Val", 2).Eq("Extra", "waffle"). 226 Gt("Val", 2).Eq("Extra", "waffle").
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 295
272 err = data.Run(q.Start(curs), func(pm ds .PropertyMap, gc ds.CursorCB) bool { 296 err = data.Run(q.Start(curs), func(pm ds .PropertyMap, gc ds.CursorCB) bool {
273 So(pm, ShouldResemble, stage1Dat a[2]) 297 So(pm, ShouldResemble, stage1Dat a[2])
274 return false 298 return false
275 }) 299 })
276 So(err, ShouldBeNil) 300 So(err, ShouldBeNil)
277 }, 301 },
278 302
279 func(c context.Context) { 303 func(c context.Context) {
280 data := ds.Get(c) 304 data := ds.Get(c)
281 » » » » » q := nq("Something").Eq("Does", 2).Order ("Not", "Work") 305 » » » » » q := nq("Something").Eq("Does", 2).Order ("Not", "-Work")
282 So(data.Run(q, func(ds.Key, ds.CursorCB) bool { 306 So(data.Run(q, func(ds.Key, ds.CursorCB) bool {
283 return true 307 return true
284 » » » » » }), ShouldErrLike, "Try adding:\n C:Som ething/Does/Not/Work") 308 » » » » » }), ShouldErrLike, strings.Join([]string {
309 » » » » » » "Consider adding:",
310 » » » » » » "- kind: Something",
311 » » » » » » " properties:",
312 » » » » » » " - name: Does",
313 » » » » » » " - name: Not",
314 » » » » » » " - name: Work",
315 » » » » » » " direction: desc",
316 » » » » » }, "\n"))
285 }, 317 },
286 }, 318 },
287 }, 319 },
288 320
289 { 321 {
290 expect: []qExpect{ 322 expect: []qExpect{
291 // eventual consistency; Unique/1 is deleted at HEAD. Keysonly finds it, 323 // eventual consistency; Unique/1 is deleted at HEAD. Keysonly finds it,
292 // but 'normal' doesn't. 324 // but 'normal' doesn't.
293 {q: nq("Unique").Gt("__key__", key("AKind", 5)). Lte("__key__", key("Zeta", "prime")), 325 {q: nq("Unique").Gt("__key__", key("AKind", 5)). Lte("__key__", key("Zeta", "prime")),
294 keys: []*ds.Key{key("Unique", 1)}, 326 keys: []*ds.Key{key("Unique", 1)},
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 for j, fn := range stage.extraFn s { 410 for j, fn := range stage.extraFn s {
379 Convey(fmt.Sprintf("extr aFn %d", j), func() { 411 Convey(fmt.Sprintf("extr aFn %d", j), func() {
380 fn(c) 412 fn(c)
381 }) 413 })
382 } 414 }
383 }) 415 })
384 } 416 }
385 }) 417 })
386 } 418 }
387 }) 419 })
420
421 Convey("Test AutoIndex", t, func() {
422 c, err := info.Get(Use(context.Background())).Namespace("ns")
423 if err != nil {
424 panic(err)
425 }
426
427 data := ds.Get(c)
428 testing := data.Testable()
429 testing.Consistent(true)
430
431 So(data.Put(pmap("$key", key("Kind", 1), Next,
432 "Val", 1, 2, 3, Next,
433 "Extra", "hello",
434 )), ShouldBeNil)
435
436 So(data.Put(pmap("$key", key("Kind", 2), Next,
437 "Val", 2, 3, 9, Next,
438 "Extra", "ace", "hello", "there",
439 )), ShouldBeNil)
440
441 q := nq("Kind").Gt("Val", 2).Order("Val", "Extra")
442
443 count, err := data.Count(q)
444 So(err, ShouldErrLike, "Insufficient indexes")
445
446 testing.AutoIndex(true)
447
448 count, err = data.Count(q)
449 So(err, ShouldBeNil)
450 So(count, ShouldEqual, 2)
451 })
388 } 452 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698