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

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

Issue 1550903002: impl/memory: Fix time serialization encoding. (Closed) Base URL: https://github.com/luci/gae@master
Patch Set: Move logic to serialize, add blobstore.Key support. Created 4 years, 11 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"
11 "time" 11 "time"
12 12
13 "github.com/luci/gae/service/blobstore"
13 ds "github.com/luci/gae/service/datastore" 14 ds "github.com/luci/gae/service/datastore"
14 "github.com/luci/gae/service/info" 15 "github.com/luci/gae/service/info"
16 "golang.org/x/net/context"
17
15 . "github.com/luci/luci-go/common/testing/assertions" 18 . "github.com/luci/luci-go/common/testing/assertions"
16 . "github.com/smartystreets/goconvey/convey" 19 . "github.com/smartystreets/goconvey/convey"
17 "golang.org/x/net/context"
18 ) 20 )
19 21
20 type qExpect struct { 22 type qExpect struct {
21 q *ds.Query 23 q *ds.Query
22 inTxn bool 24 inTxn bool
23 25
24 get []ds.PropertyMap 26 get []ds.PropertyMap
25 keys []*ds.Key 27 keys []*ds.Key
26 count int 28 count int
27 } 29 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 pmap("$key", key("Kind", 3, "Kind", 2), Next, 80 pmap("$key", key("Kind", 3, "Kind", 2), Next,
79 "Val", 3, 4, Next, 81 "Val", 3, 4, Next,
80 "Extra", "hello", "waffle", 82 "Extra", "hello", "waffle",
81 ), 83 ),
82 pmap("$key", key("Kind", 3, "Kind", 3), Next, 84 pmap("$key", key("Kind", 3, "Kind", 3), Next,
83 "Val", 3, 4, 2, 1, Next, 85 "Val", 3, 4, 2, 1, Next,
84 "Extra", "nuts", 86 "Extra", "nuts",
85 ), 87 ),
86 } 88 }
87 89
90 var collapsedData = []ds.PropertyMap{
91 // PTTime
92 pmap("$key", key("Kind", 1), Next,
93 "Date", time.Date(2000, time.January, 1, 1, 1, 1, 1, time.UTC), Next,
94 ),
95 pmap("$key", key("Kind", 2), Next,
96 "Date", time.Date(2000, time.March, 1, 1, 1, 1, 1, time.UTC), Ne xt,
97 ),
98
99 // PTBlobKey
100 pmap("$key", key("Kind", 3), Next,
101 "Key", blobstore.Key("foo"), Next,
102 ),
103 pmap("$key", key("Kind", 4), Next,
104 "Key", blobstore.Key("qux"), Next,
105 ),
106 }
107
88 var queryExecutionTests = []qExTest{ 108 var queryExecutionTests = []qExTest{
89 {"basic", []qExStage{ 109 {"basic", []qExStage{
90 { 110 {
91 addIdxs: []*ds.IndexDefinition{ 111 addIdxs: []*ds.IndexDefinition{
92 indx("Unrelated", "-thing", "bob", "-__key__"), 112 indx("Unrelated", "-thing", "bob", "-__key__"),
93 indx("Wat", "deep", "opt", "other"), 113 indx("Wat", "deep", "opt", "other"),
94 indx("Wat", "meep", "opt", "other"), 114 indx("Wat", "meep", "opt", "other"),
95 }, 115 },
96 }, 116 },
97 117
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 {q: nq("Unique").Gt("__key__", key("AKind", 5)). Lte("__key__", key("Zeta", "prime")), 398 {q: nq("Unique").Gt("__key__", key("AKind", 5)). Lte("__key__", key("Zeta", "prime")),
379 keys: []*ds.Key{key("Unique", 1)}, 399 keys: []*ds.Key{key("Unique", 1)},
380 get: []ds.PropertyMap{}}, 400 get: []ds.PropertyMap{}},
381 401
382 {q: nq("Kind").Eq("Val", 1, 3), get: []ds.Proper tyMap{ 402 {q: nq("Kind").Eq("Val", 1, 3), get: []ds.Proper tyMap{
383 stage1Data[0], stage2Data[2], 403 stage1Data[0], stage2Data[2],
384 }}, 404 }},
385 }, 405 },
386 }, 406 },
387 }}, 407 }},
408 {"collapsed types", []qExStage{
409 {
410 putEnts: collapsedData,
411 },
412 {
413 expect: []qExpect{
414 // PTTime
415 {
416 q: nq("Kind").Lte("Date", time.Date(2000 , time.February, 1, 1, 1, 1, 1, time.UTC)),
417 get: []ds.PropertyMap{
418 collapsedData[0],
419 },
420 },
421 {
422 q: nq("Kind").Eq("Date", time.Date(2000, time.March, 1, 1, 1, 1, 1, time.UTC)),
423 get: []ds.PropertyMap{
424 collapsedData[1],
425 },
426 },
427
428 // PTBlobKey
429 {
430 q: nq("Kind").Lte("Key", blobstore.Key(" foo")),
431 get: []ds.PropertyMap{
432 collapsedData[2],
433 },
434 },
435 {
436 q: nq("Kind").Eq("Key", blobstore.Key("q ux")),
437 get: []ds.PropertyMap{
438 collapsedData[3],
439 },
440 },
441 },
442 },
443 }},
388 } 444 }
389 445
390 func TestQueryExecution(t *testing.T) { 446 func TestQueryExecution(t *testing.T) {
391 t.Parallel() 447 t.Parallel()
392 448
393 Convey("Test query execution", t, func() { 449 Convey("Test query execution", t, func() {
394 c, err := info.Get(Use(context.Background())).Namespace("ns") 450 c, err := info.Get(Use(context.Background())).Namespace("ns")
395 if err != nil { 451 if err != nil {
396 panic(err) 452 panic(err)
397 } 453 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 err := r unner(func(c context.Context) error { 517 err := r unner(func(c context.Context) error {
462 data := ds.Get(c) 518 data := ds.Get(c)
463 count, err := data.Count(expect.q) 519 count, err := data.Count(expect.q)
464 So(err, ShouldBeNil) 520 So(err, ShouldBeNil)
465 So(count, ShouldEqual, expect.count) 521 So(count, ShouldEqual, expect.count)
466 522
467 rslt := []ds.PropertyMap(nil) 523 rslt := []ds.PropertyMap(nil)
468 So(data.GetAll(expect.q, &rslt), ShouldBeNil) 524 So(data.GetAll(expect.q, &rslt), ShouldBeNil)
469 So(len(rslt), ShouldEqual, len(expect.get)) 525 So(len(rslt), ShouldEqual, len(expect.get))
470 for i, r := range rslt { 526 for i, r := range rslt {
471 » » » » » » » » » » » So(r, ShouldResemble, expect.get[i]) 527 » » » » » » » » » » » So(r, ShouldResembleV, expect.get[i])
472 } 528 }
473 return nil 529 return nil
474 }, &ds.T ransactionOptions{XG: true}) 530 }, &ds.T ransactionOptions{XG: true})
475 So(err, ShouldBeNil) 531 So(err, ShouldBeNil)
476 }) 532 })
477 } 533 }
478 } 534 }
479 535
480 for j, fn := range stage.extraFn s { 536 for j, fn := range stage.extraFn s {
481 Convey(fmt.Sprintf("extr aFn %d", j), func() { 537 Convey(fmt.Sprintf("extr aFn %d", j), func() {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 count, err := data.Count(q) 569 count, err := data.Count(q)
514 So(err, ShouldErrLike, "Insufficient indexes") 570 So(err, ShouldErrLike, "Insufficient indexes")
515 571
516 testing.AutoIndex(true) 572 testing.AutoIndex(true)
517 573
518 count, err = data.Count(q) 574 count, err = data.Count(q)
519 So(err, ShouldBeNil) 575 So(err, ShouldBeNil)
520 So(count, ShouldEqual, 2) 576 So(count, ShouldEqual, 2)
521 }) 577 })
522 } 578 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698