| 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 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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 | 240 |
| 241 // now we see it | 241 // now we see it |
| 242 So(3, fooShouldHave(ds), 10, 20, 30, 40) | 242 So(3, fooShouldHave(ds), 10, 20, 30, 40) |
| 243 return nil | 243 return nil |
| 244 }, &datastore.TransactionOptions{XG: true}), Sho
uldBeNil) | 244 }, &datastore.TransactionOptions{XG: true}), Sho
uldBeNil) |
| 245 | 245 |
| 246 // 2 because we are simulating a transaction fai
lure | 246 // 2 because we are simulating a transaction fai
lure |
| 247 So(under.PutMulti.Total(), ShouldEqual, 2) | 247 So(under.PutMulti.Total(), ShouldEqual, 2) |
| 248 So(under.DeleteMulti.Total(), ShouldEqual, 2) | 248 So(under.DeleteMulti.Total(), ShouldEqual, 2) |
| 249 | 249 |
| 250 » » » » // 'over' Put operations are amplified because t
he inner transaction | 250 » » » » So(over.PutMulti.Total(), ShouldEqual, 8) |
| 251 » » » » // commits go through the 'over' filter on the o
uter transaction. So it's | |
| 252 » » » » // # Puts + # inner txns, times 2 because we are
simulating a failed | |
| 253 » » » » // transaction. | |
| 254 » » » » So(over.PutMulti.Total(), ShouldEqual, 10) | |
| 255 | 251 |
| 256 So(7, fooShouldHave(ds)) | 252 So(7, fooShouldHave(ds)) |
| 257 So(3, fooShouldHave(ds), 10, 20, 30, 40) | 253 So(3, fooShouldHave(ds), 10, 20, 30, 40) |
| 258 }) | 254 }) |
| 259 | 255 |
| 260 Convey("can allocate IDs from an inner transaction", fun
c() { | 256 Convey("can allocate IDs from an inner transaction", fun
c() { |
| 261 nums := []int64{4, 8, 15, 16, 23, 42} | 257 nums := []int64{4, 8, 15, 16, 23, 42} |
| 262 k := (*datastore.Key)(nil) | 258 k := (*datastore.Key)(nil) |
| 263 So(ds.RunInTransaction(func(c context.Context) e
rror { | 259 So(ds.RunInTransaction(func(c context.Context) e
rror { |
| 264 ds := datastore.Get(c) | 260 ds := datastore.Get(c) |
| (...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 | 827 |
| 832 vals = []*Foo{} | 828 vals = []*Foo{} |
| 833 So(ds.GetAll(q, &vals), ShouldBe
Nil) | 829 So(ds.GetAll(q, &vals), ShouldBe
Nil) |
| 834 So(vals, ShouldResemble, []*Foo{
foo1, projectData[0], foo7}) | 830 So(vals, ShouldResemble, []*Foo{
foo1, projectData[0], foo7}) |
| 835 | 831 |
| 836 return nil | 832 return nil |
| 837 }, nil), ShouldBeNil) | 833 }, nil), ShouldBeNil) |
| 838 | 834 |
| 839 vals = []*Foo{} | 835 vals = []*Foo{} |
| 840 So(ds.GetAll(q, &vals), ShouldBeNil) | 836 So(ds.GetAll(q, &vals), ShouldBeNil) |
| 841 » » » » » So(vals, ShouldResemble, []*Foo{foo1, pr
ojectData[0], foo7}) | 837 » » » » » So(vals, ShouldResembleV, []*Foo{foo1, p
rojectData[0], foo7}) |
| 842 | 838 |
| 843 return nil | 839 return nil |
| 844 }, nil), ShouldBeNil) | 840 }, nil), ShouldBeNil) |
| 845 | 841 |
| 846 vals := []*Foo{} | 842 vals := []*Foo{} |
| 847 So(ds.GetAll(q, &vals), ShouldBeNil) | 843 So(ds.GetAll(q, &vals), ShouldBeNil) |
| 848 So(vals, ShouldResemble, []*Foo{foo1, projectDat
a[0], foo7}) | 844 So(vals, ShouldResemble, []*Foo{foo1, projectDat
a[0], foo7}) |
| 849 | 845 |
| 850 }) | 846 }) |
| 851 | 847 |
| 852 Convey("start transaction from inside query", func() { | 848 Convey("start transaction from inside query", func() { |
| 853 _, _, ds := mkds(projectData) | 849 _, _, ds := mkds(projectData) |
| 854 So(ds.RunInTransaction(func(c context.Context) e
rror { | 850 So(ds.RunInTransaction(func(c context.Context) e
rror { |
| 855 ds := datastore.Get(c) | 851 ds := datastore.Get(c) |
| 856 | 852 |
| 857 q := datastore.NewQuery("Foo").Ancestor(
root) | 853 q := datastore.NewQuery("Foo").Ancestor(
root) |
| 858 return ds.Run(q, func(pm datastore.Prope
rtyMap, _ datastore.CursorCB) bool { | 854 return ds.Run(q, func(pm datastore.Prope
rtyMap, _ datastore.CursorCB) bool { |
| 859 So(ds.RunInTransaction(func(c co
ntext.Context) error { | 855 So(ds.RunInTransaction(func(c co
ntext.Context) error { |
| 856 ds := datastore.Get(c) |
| 860 pm["Value"] = append(pm[
"Value"], datastore.MkProperty("wat")) | 857 pm["Value"] = append(pm[
"Value"], datastore.MkProperty("wat")) |
| 861 return ds.Put(pm) | 858 return ds.Put(pm) |
| 862 }, nil), ShouldBeNil) | 859 }, nil), ShouldBeNil) |
| 863 return true | 860 return true |
| 864 }) | 861 }) |
| 865 }, &datastore.TransactionOptions{XG: true}), Sho
uldBeNil) | 862 }, &datastore.TransactionOptions{XG: true}), Sho
uldBeNil) |
| 866 | 863 |
| 867 So(ds.Run(datastore.NewQuery("Foo"), func(pm dat
astore.PropertyMap, _ datastore.CursorCB) bool { | 864 So(ds.Run(datastore.NewQuery("Foo"), func(pm dat
astore.PropertyMap, _ datastore.CursorCB) bool { |
| 868 val := pm["Value"] | 865 val := pm["Value"] |
| 869 So(val[len(val)-1].Value(), ShouldResemb
le, "wat") | 866 So(val[len(val)-1].Value(), ShouldResemb
le, "wat") |
| 870 return true | 867 return true |
| 871 }), ShouldBeNil) | 868 }), ShouldBeNil) |
| 872 }) | 869 }) |
| 873 | 870 |
| 874 }) | 871 }) |
| 875 | 872 |
| 876 }) | 873 }) |
| 877 | 874 |
| 878 } | 875 } |
| OLD | NEW |