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

Unified 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, 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 b56a380499461a82c20ecacf7edc12c8d2c024e7..551b43e5095e1d11dbbba92507a9809dbc80e167 100644
--- a/impl/memory/datastore_query_execution_test.go
+++ b/impl/memory/datastore_query_execution_test.go
@@ -6,6 +6,7 @@ package memory
import (
"fmt"
+ "strings"
"testing"
"time"
@@ -109,6 +110,13 @@ var queryExecutionTests = []qExTest{
{q: nq("Child").Ancestor(key("Kind", 3)), keys: []*ds.Key{
key("Kind", 3, "Child", "seven"),
}},
+ {q: nq("Child").Ancestor(key("Kind", 3)).EventualConsistency(true), keys: []*ds.Key{}},
+ {q: nq("Child").Ancestor(key("Kind", 3)).EventualConsistency(true), keys: []*ds.Key{
+ key("Kind", 3, "Child", "seven"),
+ }, inTxn: true},
+ {q: nq("Child").Ancestor(key("Kind", 3)), keys: []*ds.Key{
+ key("Kind", 3, "Child", "seven"),
+ }, inTxn: true},
},
},
@@ -151,6 +159,12 @@ var queryExecutionTests = []qExTest{
End(curs("Val", 90, "__key__", key("Kind", 3, "Zeta", "woot")))), keys: []*ds.Key{},
},
+ {q: (nq("Kind").Ancestor(key("Kind", 3)).Order("Val").
+ Start(curs("Val", 1, "__key__", key("Kind", 3))).
+ End(curs("Val", 90, "__key__", key("Kind", 3, "Zeta", "woot")))),
+ keys: []*ds.Key{},
+ inTxn: true},
+
{q: nq("Kind").Gt("Val", 2).Lte("Val", 5), get: []ds.PropertyMap{
stage1Data[0], stage1Data[3],
}},
@@ -190,6 +204,16 @@ var queryExecutionTests = []qExTest{
{q: (nq("Kind").
Gt("Val", 2).Eq("Extra", "waffle").
+ Order("-Val").
+ Ancestor(key("Kind", 3))),
+ get: []ds.PropertyMap{
+ stage1Data[2],
+ stage2Data[0],
+ stage2Data[1],
+ }, inTxn: true},
+
+ {q: (nq("Kind").
+ Gt("Val", 2).Eq("Extra", "waffle").
Order("-Val", "-__key__").
Ancestor(key("Kind", 3))),
get: []ds.PropertyMap{
@@ -278,10 +302,18 @@ var queryExecutionTests = []qExTest{
func(c context.Context) {
data := ds.Get(c)
- q := nq("Something").Eq("Does", 2).Order("Not", "Work")
+ q := nq("Something").Eq("Does", 2).Order("Not", "-Work")
So(data.Run(q, func(ds.Key, ds.CursorCB) bool {
return true
- }), ShouldErrLike, "Try adding:\n C:Something/Does/Not/Work")
+ }), ShouldErrLike, strings.Join([]string{
+ "Consider adding:",
+ "- kind: Something",
+ " properties:",
+ " - name: Does",
+ " - name: Not",
+ " - name: Work",
+ " direction: desc",
+ }, "\n"))
},
},
},
@@ -385,4 +417,36 @@ func TestQueryExecution(t *testing.T) {
})
}
})
+
+ Convey("Test AutoIndex", t, func() {
+ c, err := info.Get(Use(context.Background())).Namespace("ns")
+ if err != nil {
+ panic(err)
+ }
+
+ data := ds.Get(c)
+ testing := data.Testable()
+ testing.Consistent(true)
+
+ So(data.Put(pmap("$key", key("Kind", 1), Next,
+ "Val", 1, 2, 3, Next,
+ "Extra", "hello",
+ )), ShouldBeNil)
+
+ So(data.Put(pmap("$key", key("Kind", 2), Next,
+ "Val", 2, 3, 9, Next,
+ "Extra", "ace", "hello", "there",
+ )), ShouldBeNil)
+
+ q := nq("Kind").Gt("Val", 2).Order("Val", "Extra")
+
+ count, err := data.Count(q)
+ So(err, ShouldErrLike, "Insufficient indexes")
+
+ testing.AutoIndex(true)
+
+ count, err = data.Count(q)
+ So(err, ShouldBeNil)
+ So(count, ShouldEqual, 2)
+ })
}

Powered by Google App Engine
This is Rietveld 408576698