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

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

Issue 2604943002: impl/memory: Replace gkvlite with "treapstore". (Closed)
Patch Set: Comments. Created 3 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
« no previous file with comments | « impl/memory/datastore_index_test.go ('k') | impl/memory/doc.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package memory 5 package memory
6 6
7 import ( 7 import (
8 "errors" 8 "errors"
9 "fmt" 9 "fmt"
10 "testing" 10 "testing"
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 } 658 }
659 659
660 func TestCompoundIndexes(t *testing.T) { 660 func TestCompoundIndexes(t *testing.T) {
661 t.Parallel() 661 t.Parallel()
662 662
663 idxKey := func(def ds.IndexDefinition) string { 663 idxKey := func(def ds.IndexDefinition) string {
664 So(def, ShouldNotBeNil) 664 So(def, ShouldNotBeNil)
665 return "idx::" + string(serialize.ToBytes(*def.PrepForIdxTable() )) 665 return "idx::" + string(serialize.ToBytes(*def.PrepForIdxTable() ))
666 } 666 }
667 667
668 numItms := func(c memCollection) uint64 {
669 ret, _ := c.GetTotals()
670 return ret
671 }
672
673 Convey("Test Compound indexes", t, func() { 668 Convey("Test Compound indexes", t, func() {
674 type Model struct { 669 type Model struct {
675 ID int64 `gae:"$id"` 670 ID int64 `gae:"$id"`
676 671
677 Field1 []string 672 Field1 []string
678 Field2 []int64 673 Field2 []int64
679 } 674 }
680 675
681 c := Use(context.Background()) 676 c := Use(context.Background())
682 t := ds.GetTestable(c).(*dsImpl) 677 t := ds.GetTestable(c).(*dsImpl)
683 head := t.data.head 678 head := t.data.head
684 679
685 So(ds.Put(c, &Model{1, []string{"hello", "world"}, []int64{10, 1 1}}), ShouldBeNil) 680 So(ds.Put(c, &Model{1, []string{"hello", "world"}, []int64{10, 1 1}}), ShouldBeNil)
686 681
687 idx := ds.IndexDefinition{ 682 idx := ds.IndexDefinition{
688 Kind: "Model", 683 Kind: "Model",
689 SortBy: []ds.IndexColumn{ 684 SortBy: []ds.IndexColumn{
690 {Property: "Field2"}, 685 {Property: "Field2"},
691 }, 686 },
692 } 687 }
693 688
694 » » coll := head.GetCollection(idxKey(idx)) 689 » » coll := head.Snapshot().GetCollection(idxKey(idx))
695 So(coll, ShouldNotBeNil) 690 So(coll, ShouldNotBeNil)
696 » » So(numItms(coll), ShouldEqual, 2) 691 » » So(countItems(coll), ShouldEqual, 2)
697 692
698 idx.SortBy[0].Property = "Field1" 693 idx.SortBy[0].Property = "Field1"
699 » » coll = head.GetCollection(idxKey(idx)) 694 » » coll = head.Snapshot().GetCollection(idxKey(idx))
700 So(coll, ShouldNotBeNil) 695 So(coll, ShouldNotBeNil)
701 » » So(numItms(coll), ShouldEqual, 2) 696 » » So(countItems(coll), ShouldEqual, 2)
702 697
703 idx.SortBy = append(idx.SortBy, ds.IndexColumn{Property: "Field1 "}) 698 idx.SortBy = append(idx.SortBy, ds.IndexColumn{Property: "Field1 "})
704 So(head.GetCollection(idxKey(idx)), ShouldBeNil) 699 So(head.GetCollection(idxKey(idx)), ShouldBeNil)
705 700
706 t.AddIndexes(&idx) 701 t.AddIndexes(&idx)
707 » » coll = head.GetCollection(idxKey(idx)) 702 » » coll = head.Snapshot().GetCollection(idxKey(idx))
708 So(coll, ShouldNotBeNil) 703 So(coll, ShouldNotBeNil)
709 » » So(numItms(coll), ShouldEqual, 4) 704 » » So(countItems(coll), ShouldEqual, 4)
710 }) 705 })
711 } 706 }
712 707
713 // High level test for regression in how zero time is stored, 708 // High level test for regression in how zero time is stored,
714 // see https://codereview.chromium.org/1334043003/ 709 // see https://codereview.chromium.org/1334043003/
715 func TestDefaultTimeField(t *testing.T) { 710 func TestDefaultTimeField(t *testing.T) {
716 t.Parallel() 711 t.Parallel()
717 712
718 Convey("Default time.Time{} can be stored", t, func() { 713 Convey("Default time.Time{} can be stored", t, func() {
719 type Model struct { 714 type Model struct {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 // Add "foos" to a new namespace, then confirm that it g ets indexed. 803 // Add "foos" to a new namespace, then confirm that it g ets indexed.
809 So(ds.Put(infoS.MustNamespace(ctx, "qux"), foos), Should BeNil) 804 So(ds.Put(infoS.MustNamespace(ctx, "qux"), foos), Should BeNil)
810 ds.GetTestable(ctx).CatchupIndexes() 805 ds.GetTestable(ctx).CatchupIndexes()
811 806
812 results = nil 807 results = nil
813 So(ds.GetAll(infoS.MustNamespace(ctx, "qux"), q, &result s), ShouldBeNil) 808 So(ds.GetAll(infoS.MustNamespace(ctx, "qux"), q, &result s), ShouldBeNil)
814 So(len(results), ShouldEqual, 2) 809 So(len(results), ShouldEqual, 2)
815 }) 810 })
816 }) 811 })
817 } 812 }
OLDNEW
« no previous file with comments | « impl/memory/datastore_index_test.go ('k') | impl/memory/doc.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698