| OLD | NEW |
| 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 txnBuf | 5 package txnBuf |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "bytes" | 8 "bytes" |
| 9 "fmt" | 9 "fmt" |
| 10 "math/rand" | 10 "math/rand" |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 {2, 5}, | 523 {2, 5}, |
| 524 {3, 5}, | 524 {3, 5}, |
| 525 {4, 5}, | 525 {4, 5}, |
| 526 {2, 6}, | 526 {2, 6}, |
| 527 {3, 6}, | 527 {3, 6}, |
| 528 } | 528 } |
| 529 | 529 |
| 530 for i, pm := range vals { | 530 for i, pm := range vals { |
| 531 So(datastore.GetMetaDefault(pm,
"key", nil), ShouldResemble, | 531 So(datastore.GetMetaDefault(pm,
"key", nil), ShouldResemble, |
| 532 ds.MakeKey("Parent", 1,
"Foo", expect[i].id)) | 532 ds.MakeKey("Parent", 1,
"Foo", expect[i].id)) |
| 533 » » » » » » So(pm["Value"][0].Value(), Shoul
dEqual, expect[i].val) | 533 » » » » » » So(pm.Slice("Value")[0].Value(),
ShouldEqual, expect[i].val) |
| 534 } | 534 } |
| 535 | 535 |
| 536 // should remove 4 entries, but there ar
e plenty more to fill | 536 // should remove 4 entries, but there ar
e plenty more to fill |
| 537 So(ds.Delete(ds.MakeKey("Parent", 1, "Fo
o", 2)), ShouldBeNil) | 537 So(ds.Delete(ds.MakeKey("Parent", 1, "Fo
o", 2)), ShouldBeNil) |
| 538 | 538 |
| 539 vals = []datastore.PropertyMap{} | 539 vals = []datastore.PropertyMap{} |
| 540 So(ds.GetAll(q, &vals), ShouldBeNil) | 540 So(ds.GetAll(q, &vals), ShouldBeNil) |
| 541 So(len(vals), ShouldEqual, 10) | 541 So(len(vals), ShouldEqual, 10) |
| 542 | 542 |
| 543 expect = []struct { | 543 expect = []struct { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 554 {4, 7}, | 554 {4, 7}, |
| 555 {3, 8}, | 555 {3, 8}, |
| 556 {3, 9}, | 556 {3, 9}, |
| 557 {4, 9}, | 557 {4, 9}, |
| 558 {4, 11}, | 558 {4, 11}, |
| 559 } | 559 } |
| 560 | 560 |
| 561 for i, pm := range vals { | 561 for i, pm := range vals { |
| 562 So(datastore.GetMetaDefault(pm,
"key", nil), ShouldResemble, | 562 So(datastore.GetMetaDefault(pm,
"key", nil), ShouldResemble, |
| 563 ds.MakeKey("Parent", 1,
"Foo", expect[i].id)) | 563 ds.MakeKey("Parent", 1,
"Foo", expect[i].id)) |
| 564 » » » » » » So(pm["Value"][0].Value(), Shoul
dEqual, expect[i].val) | 564 » » » » » » So(pm.Slice("Value")[0].Value(),
ShouldEqual, expect[i].val) |
| 565 } | 565 } |
| 566 | 566 |
| 567 So(ds.Put(&Foo{ID: 1, Parent: root, Valu
e: []int64{3, 9}}), ShouldBeNil) | 567 So(ds.Put(&Foo{ID: 1, Parent: root, Valu
e: []int64{3, 9}}), ShouldBeNil) |
| 568 | 568 |
| 569 vals = []datastore.PropertyMap{} | 569 vals = []datastore.PropertyMap{} |
| 570 So(ds.GetAll(q, &vals), ShouldBeNil) | 570 So(ds.GetAll(q, &vals), ShouldBeNil) |
| 571 So(len(vals), ShouldEqual, 10) | 571 So(len(vals), ShouldEqual, 10) |
| 572 | 572 |
| 573 expect = []struct { | 573 expect = []struct { |
| 574 id int64 | 574 id int64 |
| 575 val int64 | 575 val int64 |
| 576 }{ | 576 }{ |
| 577 // 'invisible' {1, 3} entry bump
s the {4, 3} into view. | 577 // 'invisible' {1, 3} entry bump
s the {4, 3} into view. |
| 578 {4, 3}, | 578 {4, 3}, |
| 579 {3, 4}, | 579 {3, 4}, |
| 580 {3, 5}, | 580 {3, 5}, |
| 581 {4, 5}, | 581 {4, 5}, |
| 582 {3, 6}, | 582 {3, 6}, |
| 583 {3, 7}, | 583 {3, 7}, |
| 584 {4, 7}, | 584 {4, 7}, |
| 585 {3, 8}, | 585 {3, 8}, |
| 586 {1, 9}, | 586 {1, 9}, |
| 587 {3, 9}, | 587 {3, 9}, |
| 588 {4, 9}, | 588 {4, 9}, |
| 589 } | 589 } |
| 590 | 590 |
| 591 for i, pm := range vals { | 591 for i, pm := range vals { |
| 592 So(datastore.GetMetaDefault(pm,
"key", nil), ShouldResemble, | 592 So(datastore.GetMetaDefault(pm,
"key", nil), ShouldResemble, |
| 593 ds.MakeKey("Parent", 1,
"Foo", expect[i].id)) | 593 ds.MakeKey("Parent", 1,
"Foo", expect[i].id)) |
| 594 » » » » » » So(pm["Value"][0].Value(), Shoul
dEqual, expect[i].val) | 594 » » » » » » So(pm.Slice("Value")[0].Value(),
ShouldEqual, expect[i].val) |
| 595 } | 595 } |
| 596 | 596 |
| 597 return nil | 597 return nil |
| 598 }, nil), ShouldBeNil) | 598 }, nil), ShouldBeNil) |
| 599 | 599 |
| 600 }) | 600 }) |
| 601 | 601 |
| 602 Convey("project+distinct", func() { | 602 Convey("project+distinct", func() { |
| 603 _, _, ds := mkds([]*Foo{ | 603 _, _, ds := mkds([]*Foo{ |
| 604 {ID: 2, Parent: root, Value: []int64{1,
2, 3, 4, 5, 6, 7}}, | 604 {ID: 2, Parent: root, Value: []int64{1,
2, 3, 4, 5, 6, 7}}, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 {2, 7}, | 637 {2, 7}, |
| 638 {3, 8}, | 638 {3, 8}, |
| 639 {3, 9}, | 639 {3, 9}, |
| 640 {4, 11}, | 640 {4, 11}, |
| 641 {5, 70}, | 641 {5, 70}, |
| 642 {4, 100}, | 642 {4, 100}, |
| 643 {5, 101}, | 643 {5, 101}, |
| 644 } | 644 } |
| 645 | 645 |
| 646 for i, pm := range vals { | 646 for i, pm := range vals { |
| 647 » » » » » » So(pm["Value"][0].Value(), Shoul
dEqual, expect[i].val) | 647 » » » » » » So(pm.Slice("Value")[0].Value(),
ShouldEqual, expect[i].val) |
| 648 So(datastore.GetMetaDefault(pm,
"key", nil), ShouldResemble, | 648 So(datastore.GetMetaDefault(pm,
"key", nil), ShouldResemble, |
| 649 ds.MakeKey("Parent", 1,
"Foo", expect[i].id)) | 649 ds.MakeKey("Parent", 1,
"Foo", expect[i].id)) |
| 650 } | 650 } |
| 651 | 651 |
| 652 return nil | 652 return nil |
| 653 }, nil), ShouldBeNil) | 653 }, nil), ShouldBeNil) |
| 654 }) | 654 }) |
| 655 | 655 |
| 656 Convey("overwrite", func() { | 656 Convey("overwrite", func() { |
| 657 data := []*Foo{ | 657 data := []*Foo{ |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 {2, 2}, | 745 {2, 2}, |
| 746 {5, 101}, | 746 {5, 101}, |
| 747 {5, 70}, | 747 {5, 70}, |
| 748 {3, 9}, | 748 {3, 9}, |
| 749 {3, 8}, | 749 {3, 8}, |
| 750 {4, 100}, | 750 {4, 100}, |
| 751 {4, 11}, | 751 {4, 11}, |
| 752 } | 752 } |
| 753 | 753 |
| 754 for i, pm := range vals { | 754 for i, pm := range vals { |
| 755 » » » » » » So(pm["Value"][0].Value(), Shoul
dEqual, expect[i].val) | 755 » » » » » » So(pm.Slice("Value")[0].Value(),
ShouldEqual, expect[i].val) |
| 756 So(datastore.GetMetaDefault(pm,
"key", nil), ShouldResemble, | 756 So(datastore.GetMetaDefault(pm,
"key", nil), ShouldResemble, |
| 757 ds.MakeKey("Parent", 1,
"Foo", expect[i].id)) | 757 ds.MakeKey("Parent", 1,
"Foo", expect[i].id)) |
| 758 } | 758 } |
| 759 | 759 |
| 760 return nil | 760 return nil |
| 761 }, nil), ShouldBeNil) | 761 }, nil), ShouldBeNil) |
| 762 }) | 762 }) |
| 763 | 763 |
| 764 Convey("buffered entity sorts before ineq, but after fir
st parent entity", func() { | 764 Convey("buffered entity sorts before ineq, but after fir
st parent entity", func() { |
| 765 // If we got this wrong, we'd see Foo,3 come bef
ore Foo,2. This might | 765 // If we got this wrong, we'd see Foo,3 come bef
ore Foo,2. This might |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 885 | 885 |
| 886 Convey("start transaction from inside query", func() { | 886 Convey("start transaction from inside query", func() { |
| 887 _, _, ds := mkds(projectData) | 887 _, _, ds := mkds(projectData) |
| 888 So(ds.RunInTransaction(func(c context.Context) e
rror { | 888 So(ds.RunInTransaction(func(c context.Context) e
rror { |
| 889 ds := datastore.Get(c) | 889 ds := datastore.Get(c) |
| 890 | 890 |
| 891 q := datastore.NewQuery("Foo").Ancestor(
root) | 891 q := datastore.NewQuery("Foo").Ancestor(
root) |
| 892 return ds.Run(q, func(pm datastore.Prope
rtyMap) { | 892 return ds.Run(q, func(pm datastore.Prope
rtyMap) { |
| 893 So(ds.RunInTransaction(func(c co
ntext.Context) error { | 893 So(ds.RunInTransaction(func(c co
ntext.Context) error { |
| 894 ds := datastore.Get(c) | 894 ds := datastore.Get(c) |
| 895 » » » » » » » pm["Value"] = append(pm[
"Value"], datastore.MkProperty("wat")) | 895 » » » » » » » pm["Value"] = append(pm.
Slice("Value"), datastore.MkProperty("wat")) |
| 896 return ds.Put(pm) | 896 return ds.Put(pm) |
| 897 }, nil), ShouldBeNil) | 897 }, nil), ShouldBeNil) |
| 898 }) | 898 }) |
| 899 }, &datastore.TransactionOptions{XG: true}), Sho
uldBeNil) | 899 }, &datastore.TransactionOptions{XG: true}), Sho
uldBeNil) |
| 900 | 900 |
| 901 So(ds.Run(datastore.NewQuery("Foo"), func(pm dat
astore.PropertyMap) { | 901 So(ds.Run(datastore.NewQuery("Foo"), func(pm dat
astore.PropertyMap) { |
| 902 » » » » » val := pm["Value"] | 902 » » » » » val := pm.Slice("Value") |
| 903 So(val[len(val)-1].Value(), ShouldResemb
le, "wat") | 903 So(val[len(val)-1].Value(), ShouldResemb
le, "wat") |
| 904 }), ShouldBeNil) | 904 }), ShouldBeNil) |
| 905 }) | 905 }) |
| 906 | 906 |
| 907 }) | 907 }) |
| 908 | 908 |
| 909 }) | 909 }) |
| 910 | 910 |
| 911 } | 911 } |
| OLD | NEW |