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

Unified Diff: impl/memory/datastore_query_execution_test.go

Issue 1355783002: Refactor keys and queries in datastore service and implementation. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: impl/memory/datastore_query_execution_test.go
diff --git a/impl/memory/datastore_query_execution_test.go b/impl/memory/datastore_query_execution_test.go
index 28bed9f63d3efa56e86afadf8e4c08b67cdf9f6e..0ade3bc4a7a3388a48711c91ffe70ae7555e79aa 100644
--- a/impl/memory/datastore_query_execution_test.go
+++ b/impl/memory/datastore_query_execution_test.go
@@ -17,17 +17,17 @@ import (
)
type qExpect struct {
- q ds.Query
+ q *ds.Query
inTxn bool
get []ds.PropertyMap
- keys []ds.Key
+ keys []*ds.Key
}
type qExStage struct {
addIdxs []*ds.IndexDefinition
putEnts []ds.PropertyMap
- delEnts []ds.Key
+ delEnts []*ds.Key
expect []qExpect
@@ -59,7 +59,7 @@ var stage1Data = []ds.PropertyMap{
"When", time.Date(2000, time.January, 1, 1, 1, 1, 1, time.UTC), NEXT,
"Extra", "waffle",
),
- pmap("$key", key("Child", "seven", key("Kind", 3)), NEXT,
+ pmap("$key", key("Kind", 3, "Child", "seven"), NEXT,
"Interesting", 28, NEXT,
"Extra", "hello",
),
@@ -69,15 +69,15 @@ var stage1Data = []ds.PropertyMap{
}
var stage2Data = []ds.PropertyMap{
- pmap("$key", key("Kind", 1, key("Kind", 3)), NEXT,
+ pmap("$key", key("Kind", 3, "Kind", 1), NEXT,
"Val", 2, 4, 28, NEXT,
"Extra", "hello", "waffle",
),
- pmap("$key", key("Kind", 2, key("Kind", 3)), NEXT,
+ pmap("$key", key("Kind", 3, "Kind", 2), NEXT,
"Val", 3, 4, NEXT,
"Extra", "hello", "waffle",
),
- pmap("$key", key("Kind", 3, key("Kind", 3)), NEXT,
+ pmap("$key", key("Kind", 3, "Kind", 3), NEXT,
"Val", 3, 4, 2, 1, NEXT,
"Extra", "nuts",
),
@@ -97,7 +97,7 @@ var queryExecutionTests = []qExTest{
expect: []qExpect{
// tests the case where the query has indexes to fulfill it, but there
// are no actual entities in the datastore.
- {q: nq("Wat").Filter("meep =", 1).Filter("deep =", 2).Order("opt").Order("other"),
+ {q: nq("Wat").Eq("meep", 1).Eq("deep", 2).Order("opt", "other"),
get: []ds.PropertyMap{}},
},
},
@@ -106,15 +106,15 @@ var queryExecutionTests = []qExTest{
putEnts: stage1Data,
expect: []qExpect{
{q: nq("Kind"), get: []ds.PropertyMap{}},
- {q: nq("Child").Ancestor(key("Kind", 3)), keys: []ds.Key{
- key("Child", "seven", key("Kind", 3)),
+ {q: nq("Child").Ancestor(key("Kind", 3)), keys: []*ds.Key{
+ key("Kind", 3, "Child", "seven"),
}},
},
},
{
putEnts: stage2Data,
- delEnts: []ds.Key{key("Unique", 1)},
+ delEnts: []*ds.Key{key("Unique", 1)},
addIdxs: []*ds.IndexDefinition{
indx("Kind!", "-Extra", "-Val"),
indx("Kind!", "-Extra", "-Val", "-__key__"),
@@ -129,56 +129,57 @@ var queryExecutionTests = []qExTest{
{q: nq("Missing"), get: []ds.PropertyMap{}},
- {q: nq("Missing").Filter("Id <", 2).Filter("Id >", 2), get: []ds.PropertyMap{}},
+ {q: nq("Missing").Lt("Id", 2).Gt("Id", 2), get: []ds.PropertyMap{}},
- {q: nq("Missing").Filter("Bogus =", 3), get: []ds.PropertyMap{}},
+ {q: nq("Missing").Eq("Bogus", 3), get: []ds.PropertyMap{}},
- {q: nq("Kind").Filter("Extra =", "waffle"), get: []ds.PropertyMap{
+ {q: nq("Kind").Eq("Extra", "waffle"), get: []ds.PropertyMap{
stage1Data[2], stage1Data[3],
}},
// get ziggy with it
- {q: nq("Kind").Filter("Extra =", "waffle").Filter("Val =", 100), get: []ds.PropertyMap{
+ {q: nq("Kind").Eq("Extra", "waffle").Eq("Val", 100), get: []ds.PropertyMap{
stage1Data[2],
}},
- {q: nq("Child").Filter("Interesting =", 28).Filter("Extra =", "hello"), get: []ds.PropertyMap{
+
+ {q: nq("Child").Eq("Interesting", 28).Eq("Extra", "hello"), get: []ds.PropertyMap{
stage1Data[4],
}},
{q: (nq("Kind").Ancestor(key("Kind", 3)).Order("Val").
Start(curs("Val", 1, "__key__", key("Kind", 3))).
- End(curs("Val", 90, "__key__", key("Zeta", "woot", key("Kind", 3))))), keys: []ds.Key{},
+ End(curs("Val", 90, "__key__", key("Kind", 3, "Zeta", "woot")))), keys: []*ds.Key{},
},
- {q: nq("Kind").Filter("Val >", 2).Filter("Val <=", 5), get: []ds.PropertyMap{
+ {q: nq("Kind").Gt("Val", 2).Lte("Val", 5), get: []ds.PropertyMap{
stage1Data[0], stage1Data[3],
}},
- {q: nq("Kind").Filter("Val >", 2).Filter("Val <=", 5).Order("-Val"), get: []ds.PropertyMap{
+ {q: nq("Kind").Gt("Val", 2).Lte("Val", 5).Order("-Val"), get: []ds.PropertyMap{
stage1Data[3], stage1Data[0],
}},
- {q: nq("").Filter("__key__ >", key("Kind", 2)), get: []ds.PropertyMap{
+ {q: nq("").Gt("__key__", key("Kind", 2)), get: []ds.PropertyMap{
// TODO(riannucci): determine if the real datastore shows metadata
// during kindless queries. The documentation seems to imply so, but
// I'd like to be sure.
- pmap("$key", key("__entity_group__", 1, key("Kind", 2)), NEXT,
+ pmap("$key", key("Kind", 2, "__entity_group__", 1), NEXT,
"__version__", 1),
stage1Data[2],
stage1Data[4],
// this is 5 because the value is retrieved from HEAD and not from
// the index snapshot!
- pmap("$key", key("__entity_group__", 1, key("Kind", 3)), NEXT,
+ pmap("$key", key("Kind", 3, "__entity_group__", 1), NEXT,
"__version__", 5),
stage1Data[3],
- pmap("$key", key("__entity_group__", 1, key("Kind", 6)), NEXT,
+ pmap("$key", key("Kind", 6, "__entity_group__", 1), NEXT,
"__version__", 1),
- pmap("$key", key("__entity_group__", 1, key("Unique", 1)), NEXT,
+ pmap("$key", key("Unique", 1, "__entity_group__", 1), NEXT,
"__version__", 2),
}},
{q: (nq("Kind").
- Filter("Val >", 2).Filter("Extra =", "waffle").
+ Gt("Val", 2).Eq("Extra", "waffle").
Order("-Val").
Ancestor(key("Kind", 3))),
get: []ds.PropertyMap{
@@ -188,8 +189,8 @@ var queryExecutionTests = []qExTest{
}},
{q: (nq("Kind").
- Filter("Val >", 2).Filter("Extra =", "waffle").
- Order("-Val").Order("-__key__").
+ Gt("Val", 2).Eq("Extra", "waffle").
+ Order("-Val", "-__key__").
Ancestor(key("Kind", 3))),
get: []ds.PropertyMap{
stage1Data[2],
@@ -198,34 +199,34 @@ var queryExecutionTests = []qExTest{
}},
{q: (nq("Kind").
- Filter("Val >", 2).Filter("Extra =", "waffle").
+ Gt("Val", 2).Eq("Extra", "waffle").
Order("-Val").
Ancestor(key("Kind", 3)).Project("Val")),
get: []ds.PropertyMap{
pmap("$key", key("Kind", 3), NEXT,
"Val", 100),
- pmap("$key", key("Kind", 1, key("Kind", 3)), NEXT,
+ pmap("$key", key("Kind", 3, "Kind", 1), NEXT,
"Val", 28),
- pmap("$key", key("Kind", 1, key("Kind", 3)), NEXT,
+ pmap("$key", key("Kind", 3, "Kind", 1), NEXT,
"Val", 4),
- pmap("$key", key("Kind", 2, key("Kind", 3)), NEXT,
+ pmap("$key", key("Kind", 3, "Kind", 2), NEXT,
"Val", 4),
- pmap("$key", key("Kind", 2, key("Kind", 3)), NEXT,
+ pmap("$key", key("Kind", 3, "Kind", 2), NEXT,
"Val", 3),
}},
{q: (nq("Kind").
- Filter("Val >", 2).Filter("Extra =", "waffle").
+ Gt("Val", 2).Eq("Extra", "waffle").
Order("-Val").
- Ancestor(key("Kind", 3)).Project("Val").Distinct()),
+ Ancestor(key("Kind", 3)).Project("Val").Distinct(true)),
get: []ds.PropertyMap{
pmap("$key", key("Kind", 3), NEXT,
"Val", 100),
- pmap("$key", key("Kind", 1, key("Kind", 3)), NEXT,
+ pmap("$key", key("Kind", 3, "Kind", 1), NEXT,
"Val", 28),
- pmap("$key", key("Kind", 1, key("Kind", 3)), NEXT,
+ pmap("$key", key("Kind", 3, "Kind", 1), NEXT,
"Val", 4),
- pmap("$key", key("Kind", 2, key("Kind", 3)), NEXT,
+ pmap("$key", key("Kind", 3, "Kind", 2), NEXT,
"Val", 3),
}},
@@ -254,11 +255,11 @@ var queryExecutionTests = []qExTest{
data := ds.Get(c)
curs := ds.Cursor(nil)
- q := nq("").Filter("__key__ >", key("Kind", 2))
+ q := nq("").Gt("__key__", key("Kind", 2))
err := data.Run(q, func(pm ds.PropertyMap, gc ds.CursorCB) bool {
So(pm, ShouldResemble, pmap(
- "$key", key("__entity_group__", 1, key("Kind", 2)), NEXT,
+ "$key", key("Kind", 2, "__entity_group__", 1), NEXT,
iannucci 2015/09/18 04:31:52 key (which is an alias for datastore.MakeKey above
"__version__", 1))
err := error(nil)
@@ -277,7 +278,7 @@ var queryExecutionTests = []qExTest{
func(c context.Context) {
data := ds.Get(c)
- q := nq("Something").Filter("Does =", 2).Order("Not").Order("Work")
+ q := nq("Something").Eq("Does", 2).Order("Not", "Work")
iannucci 2015/09/18 04:31:52 I made Order accept multiples, just like Project.
So(data.Run(q, func(ds.Key, ds.CursorCB) bool {
return true
}), ShouldErrLike, "Try adding:\n C:Something/Does/Not/Work")
@@ -289,11 +290,11 @@ var queryExecutionTests = []qExTest{
expect: []qExpect{
// eventual consistency; Unique/1 is deleted at HEAD. Keysonly finds it,
// but 'normal' doesn't.
- {q: nq("Unique").Filter("__key__ >", key("AKind", 5)).Filter("__key__ <=", key("Zeta", "prime")),
- keys: []ds.Key{key("Unique", 1)},
+ {q: nq("Unique").Gt("__key__", key("AKind", 5)).Lte("__key__", key("Zeta", "prime")),
+ keys: []*ds.Key{key("Unique", 1)},
get: []ds.PropertyMap{}},
- {q: nq("Kind").Filter("Val =", 1).Filter("Val =", 3), get: []ds.PropertyMap{
+ {q: nq("Kind").Eq("Val", 1, 3), get: []ds.PropertyMap{
iannucci 2015/09/18 04:31:52 Eq can accept multiples too.
stage1Data[0], stage2Data[2],
}},
},
@@ -310,6 +311,9 @@ func TestQueryExecution(t *testing.T) {
panic(err)
}
+ So(info.Get(c).FullyQualifiedAppID(), ShouldEqual, "dev~app")
+ So(info.Get(c).GetNamespace(), ShouldEqual, "ns")
+
data := ds.Get(c)
testing := data.Testable()
@@ -343,7 +347,7 @@ func TestQueryExecution(t *testing.T) {
runner(func(c context.Context) error {
data := ds.Get(c)
Convey(fmt.Sprintf("expect %d (keys)", j), func() {
- rslt := []ds.Key(nil)
+ rslt := []*ds.Key(nil)
So(data.GetAll(expect.q, &rslt), ShouldBeNil)
So(len(rslt), ShouldEqual, len(expect.keys))
for i, r := range rslt {

Powered by Google App Engine
This is Rietveld 408576698