OLD | NEW |
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 "testing" | 9 "testing" |
10 | 10 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 keys := make([]dsS.Key, len(foos)) | 132 keys := make([]dsS.Key, len(foos)) |
133 for i, f := range foos { | 133 for i, f := range foos { |
134 keys[i] = ds.KeyForObj(&f) | 134 keys[i] = ds.KeyForObj(&f) |
135 } | 135 } |
136 | 136 |
137 Convey("ensure that group versions persist acros
s deletes", func() { | 137 Convey("ensure that group versions persist acros
s deletes", func() { |
138 So(ds.DeleteMulti(append(keys, k)), Shou
ldBeNil) | 138 So(ds.DeleteMulti(append(keys, k)), Shou
ldBeNil) |
139 | 139 |
140 // TODO(riannucci): replace with a Count
query instead of this cast | 140 // TODO(riannucci): replace with a Count
query instead of this cast |
141 /* | 141 /* |
142 » » » » » » ents := ds.(*dsImpl).data.store.
GetCollection("ents:") | 142 » » » » » » ents := ds.(*dsImpl).data.head.G
etCollection("ents:") |
143 num, _ := ents.GetTotals() | 143 num, _ := ents.GetTotals() |
144 // /__entity_root_ids__,Foo | 144 // /__entity_root_ids__,Foo |
145 // /Foo,1/__entity_group__,1 | 145 // /Foo,1/__entity_group__,1 |
146 // /Foo,1/__entity_group_ids__,1 | 146 // /Foo,1/__entity_group_ids__,1 |
147 So(num, ShouldEqual, 3) | 147 So(num, ShouldEqual, 3) |
148 */ | 148 */ |
149 | 149 |
150 So(testGetMeta(c, k), ShouldEqual, 22) | 150 So(testGetMeta(c, k), ShouldEqual, 22) |
151 | 151 |
152 So(ds.Put(&Foo{Id: 1}), ShouldBeNil) | 152 So(ds.Put(&Foo{Id: 1}), ShouldBeNil) |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 }) | 421 }) |
422 | 422 |
423 }) | 423 }) |
424 } | 424 } |
425 | 425 |
426 func TestCompoundIndexes(t *testing.T) { | 426 func TestCompoundIndexes(t *testing.T) { |
427 t.Parallel() | 427 t.Parallel() |
428 | 428 |
429 idxKey := func(def dsS.IndexDefinition) string { | 429 idxKey := func(def dsS.IndexDefinition) string { |
430 So(def, ShouldNotBeNil) | 430 So(def, ShouldNotBeNil) |
431 » » return "idx::" + string(serialize.ToBytes(def)) | 431 » » return "idx::" + string(serialize.ToBytes(*def.PrepForIdxTable()
)) |
432 } | 432 } |
433 | 433 |
434 numItms := func(c *memCollection) uint64 { | 434 numItms := func(c *memCollection) uint64 { |
435 ret, _ := c.GetTotals() | 435 ret, _ := c.GetTotals() |
436 return ret | 436 return ret |
437 } | 437 } |
438 | 438 |
439 Convey("Test Compound indexes", t, func() { | 439 Convey("Test Compound indexes", t, func() { |
440 type Model struct { | 440 type Model struct { |
441 ID int64 `gae:"$id"` | 441 ID int64 `gae:"$id"` |
442 | 442 |
443 Field1 []string | 443 Field1 []string |
444 Field2 []int64 | 444 Field2 []int64 |
445 } | 445 } |
446 | 446 |
447 c := Use(context.Background()) | 447 c := Use(context.Background()) |
448 ds := dsS.Get(c) | 448 ds := dsS.Get(c) |
449 t := ds.Raw().Testable().(*dsImpl) | 449 t := ds.Raw().Testable().(*dsImpl) |
450 » » store := t.data.store | 450 » » head := t.data.head |
451 | 451 |
452 So(ds.Put(&Model{1, []string{"hello", "world"}, []int64{10, 11}}
), ShouldBeNil) | 452 So(ds.Put(&Model{1, []string{"hello", "world"}, []int64{10, 11}}
), ShouldBeNil) |
453 | 453 |
454 idx := dsS.IndexDefinition{ | 454 idx := dsS.IndexDefinition{ |
455 Kind: "Model", | 455 Kind: "Model", |
456 SortBy: []dsS.IndexColumn{ | 456 SortBy: []dsS.IndexColumn{ |
457 {Property: "Field2"}, | 457 {Property: "Field2"}, |
458 }, | 458 }, |
459 } | 459 } |
460 | 460 |
461 » » coll := store.GetCollection(idxKey(idx)) | 461 » » coll := head.GetCollection(idxKey(idx)) |
462 So(coll, ShouldNotBeNil) | 462 So(coll, ShouldNotBeNil) |
463 So(numItms(coll), ShouldEqual, 2) | 463 So(numItms(coll), ShouldEqual, 2) |
464 | 464 |
465 idx.SortBy[0].Property = "Field1" | 465 idx.SortBy[0].Property = "Field1" |
466 » » coll = store.GetCollection(idxKey(idx)) | 466 » » coll = head.GetCollection(idxKey(idx)) |
467 So(coll, ShouldNotBeNil) | 467 So(coll, ShouldNotBeNil) |
468 So(numItms(coll), ShouldEqual, 2) | 468 So(numItms(coll), ShouldEqual, 2) |
469 | 469 |
470 idx.SortBy = append(idx.SortBy, dsS.IndexColumn{Property: "Field
1"}) | 470 idx.SortBy = append(idx.SortBy, dsS.IndexColumn{Property: "Field
1"}) |
471 » » So(store.GetCollection(idxKey(idx)), ShouldBeNil) | 471 » » So(head.GetCollection(idxKey(idx)), ShouldBeNil) |
472 | 472 |
473 t.AddIndexes(&idx) | 473 t.AddIndexes(&idx) |
474 » » coll = store.GetCollection(idxKey(idx)) | 474 » » coll = head.GetCollection(idxKey(idx)) |
475 So(coll, ShouldNotBeNil) | 475 So(coll, ShouldNotBeNil) |
476 So(numItms(coll), ShouldEqual, 4) | 476 So(numItms(coll), ShouldEqual, 4) |
477 }) | 477 }) |
478 } | 478 } |
OLD | NEW |