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

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

Issue 1892343002: Add __namespace__ metadata query support to impl/memory. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/gae@master
Patch Set: Created 4 years, 8 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 "strings"
10 "testing" 10 "testing"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 "Extra", "hello", "waffle", 78 "Extra", "hello", "waffle",
79 ), 79 ),
80 pmap("$key", key("Kind", 3, "Kind", 2), Next, 80 pmap("$key", key("Kind", 3, "Kind", 2), Next,
81 "Val", 3, 4, Next, 81 "Val", 3, 4, Next,
82 "Extra", "hello", "waffle", 82 "Extra", "hello", "waffle",
83 ), 83 ),
84 pmap("$key", key("Kind", 3, "Kind", 3), Next, 84 pmap("$key", key("Kind", 3, "Kind", 3), Next,
85 "Val", 3, 4, 2, 1, Next, 85 "Val", 3, 4, 2, 1, Next,
86 "Extra", "nuts", 86 "Extra", "nuts",
87 ), 87 ),
88 pmap("$key", ds.MakeKey("dev~app", "", "Kind", "id")),
89 pmap("$key", ds.MakeKey("dev~app", "bob", "Kind", "id")),
88 } 90 }
89 91
90 var collapsedData = []ds.PropertyMap{ 92 var collapsedData = []ds.PropertyMap{
91 // PTTime 93 // PTTime
92 pmap("$key", key("Kind", 1), Next, 94 pmap("$key", key("Kind", 1), Next,
93 "Date", time.Date(2000, time.January, 1, 1, 1, 1, 1, time.UTC), Next, 95 "Date", time.Date(2000, time.January, 1, 1, 1, 1, 1, time.UTC), Next,
94 ), 96 ),
95 pmap("$key", key("Kind", 2), Next, 97 pmap("$key", key("Kind", 2), Next,
96 "Date", time.Date(2000, time.March, 1, 1, 1, 1, 1, time.UTC), Ne xt, 98 "Date", time.Date(2000, time.March, 1, 1, 1, 1, 1, time.UTC), Ne xt,
97 ), 99 ),
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 {q: nq("Child").Ancestor(key("Kind", 3)), keys: []*ds.Key{ 141 {q: nq("Child").Ancestor(key("Kind", 3)), keys: []*ds.Key{
140 key("Kind", 3, "Child", "seven"), 142 key("Kind", 3, "Child", "seven"),
141 }}, 143 }},
142 {q: nq("Child").Ancestor(key("Kind", 3)).Eventua lConsistency(true), keys: []*ds.Key{}}, 144 {q: nq("Child").Ancestor(key("Kind", 3)).Eventua lConsistency(true), keys: []*ds.Key{}},
143 {q: nq("Child").Ancestor(key("Kind", 3)).Eventua lConsistency(true), keys: []*ds.Key{ 145 {q: nq("Child").Ancestor(key("Kind", 3)).Eventua lConsistency(true), keys: []*ds.Key{
144 key("Kind", 3, "Child", "seven"), 146 key("Kind", 3, "Child", "seven"),
145 }, inTxn: true}, 147 }, inTxn: true},
146 {q: nq("Child").Ancestor(key("Kind", 3)), keys: []*ds.Key{ 148 {q: nq("Child").Ancestor(key("Kind", 3)), keys: []*ds.Key{
147 key("Kind", 3, "Child", "seven"), 149 key("Kind", 3, "Child", "seven"),
148 }, inTxn: true}, 150 }, inTxn: true},
151 {q: nq("__namespace__"), get: []ds.PropertyMap{
152 pmap("$key", ds.MakeKey("dev~app", "", " __namespace__", "ns")),
153 }},
154 {q: nq("__namespace__").Offset(1), get: []ds.Pro pertyMap{}},
155 {q: nq("__namespace__").Offset(1).Limit(1), get: []ds.PropertyMap{}},
149 }, 156 },
150 }, 157 },
151 158
152 { 159 {
153 putEnts: stage2Data, 160 putEnts: stage2Data,
154 delEnts: []*ds.Key{key("Unique", 1)}, 161 delEnts: []*ds.Key{key("Unique", 1)},
155 addIdxs: []*ds.IndexDefinition{ 162 addIdxs: []*ds.IndexDefinition{
156 indx("Kind!", "-Extra", "-Val"), 163 indx("Kind!", "-Extra", "-Val"),
157 indx("Kind!", "-Extra", "-Val", "-__key__"), 164 indx("Kind!", "-Extra", "-Val", "-__key__"),
158 indx("Kind!", "Bogus", "Extra", "-Val"), 165 indx("Kind!", "Bogus", "Extra", "-Val"),
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 pmap("$key", key("Kind", 3), Next, 343 pmap("$key", key("Kind", 3), Next,
337 "When", 996688461000000), 344 "When", 996688461000000),
338 }}, 345 }},
339 346
340 // Original (complex) types are retained when ge tting the full value. 347 // Original (complex) types are retained when ge tting the full value.
341 {q: nq("Kind").Order("When"), get: []ds.Property Map{ 348 {q: nq("Kind").Order("When"), get: []ds.Property Map{
342 stage1Data[1], 349 stage1Data[1],
343 stage1Data[3], 350 stage1Data[3],
344 stage1Data[2], 351 stage1Data[2],
345 }}, 352 }},
353 {q: nq("__namespace__"), get: []ds.PropertyMap{
354 pmap("$key", ds.MakeKey("dev~app", "", " __namespace__", 1)),
355 pmap("$key", ds.MakeKey("dev~app", "", " __namespace__", "bob")),
356 pmap("$key", ds.MakeKey("dev~app", "", " __namespace__", "ns")),
357 }},
358 {q: nq("__namespace__").Offset(1), get: []ds.Pro pertyMap{
359 pmap("$key", ds.MakeKey("dev~app", "", " __namespace__", "bob")),
360 pmap("$key", ds.MakeKey("dev~app", "", " __namespace__", "ns")),
361 }},
362 {q: nq("__namespace__").Offset(1).Limit(1), get: []ds.PropertyMap{
363 pmap("$key", ds.MakeKey("dev~app", "", " __namespace__", "bob")),
364 }},
346 }, 365 },
347 366
348 extraFns: []func(context.Context){ 367 extraFns: []func(context.Context){
349 func(c context.Context) { 368 func(c context.Context) {
350 data := ds.Get(c) 369 data := ds.Get(c)
351 curs := ds.Cursor(nil) 370 curs := ds.Cursor(nil)
352 371
353 q := nq("").Gt("__key__", key("Kind", 2) ) 372 q := nq("").Gt("__key__", key("Kind", 2) )
354 373
355 err := data.Run(q, func(pm ds.PropertyMa p, gc ds.CursorCB) error { 374 err := data.Run(q, func(pm ds.PropertyMa p, gc ds.CursorCB) error {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 data := ds.Get(c) 499 data := ds.Get(c)
481 testing := data.Testable() 500 testing := data.Testable()
482 501
483 for _, tc := range queryExecutionTests { 502 for _, tc := range queryExecutionTests {
484 Convey(tc.name, func() { 503 Convey(tc.name, func() {
485 for i, stage := range tc.test { 504 for i, stage := range tc.test {
486 // outside of Convey, since these must a lways happen 505 // outside of Convey, since these must a lways happen
487 testing.CatchupIndexes() 506 testing.CatchupIndexes()
488 507
489 testing.AddIndexes(stage.addIdxs...) 508 testing.AddIndexes(stage.addIdxs...)
490 » » » » » if err := data.PutMulti(stage.putEnts); err != nil { 509 » » » » » byNs := map[string][]ds.PropertyMap{}
491 » » » » » » // prevent Convey from thinking this assertion should show up in 510 » » » » » for _, ent := range stage.putEnts {
492 » » » » » » // every test loop. 511 » » » » » » k := ds.GetMetaDefault(ent, "key ", nil).(*ds.Key)
493 » » » » » » panic(err) 512 » » » » » » byNs[k.Namespace()] = append(byN s[k.Namespace()], ent)
513 » » » » » }
514 » » » » » for ns, ents := range byNs {
515 » » » » » » c := info.Get(c).MustNamespace(n s)
516 » » » » » » data := ds.Get(c)
517 » » » » » » if err := data.PutMulti(ents); e rr != nil {
518 » » » » » » » // prevent Convey from t hinking this assertion should show up in
519 » » » » » » » // every test loop.
520 » » » » » » » panic(err)
521 » » » » » » }
494 } 522 }
495 523
496 if err := data.DeleteMulti(stage.delEnts ); err != nil { 524 if err := data.DeleteMulti(stage.delEnts ); err != nil {
497 panic(err) 525 panic(err)
498 } 526 }
499 527
500 Convey(fmt.Sprintf("stage %d", i), func( ) { 528 Convey(fmt.Sprintf("stage %d", i), func( ) {
501 for j, expect := range stage.exp ect { 529 for j, expect := range stage.exp ect {
502 runner := func(f func(ic context.Context) error, _ *ds.TransactionOptions) error { 530 runner := func(f func(ic context.Context) error, _ *ds.TransactionOptions) error {
503 return f(c) 531 return f(c)
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 637
610 v, ok := actual.(error) 638 v, ok := actual.(error)
611 if !ok { 639 if !ok {
612 return fmt.Sprintf("type of 'actual' must be error, not %T", act ual) 640 return fmt.Sprintf("type of 'actual' must be error, not %T", act ual)
613 } 641 }
614 if v == nil || v == ds.Stop { 642 if v == nil || v == ds.Stop {
615 return "" 643 return ""
616 } 644 }
617 return fmt.Sprintf("expected success value, not %v", v) 645 return fmt.Sprintf("expected success value, not %v", v)
618 } 646 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698