Chromium Code Reviews| 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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 func TestTransactionBuffers(t *testing.T) { | 148 func TestTransactionBuffers(t *testing.T) { |
| 149 t.Parallel() | 149 t.Parallel() |
| 150 | 150 |
| 151 Convey("Get/Put/Delete", t, func() { | 151 Convey("Get/Put/Delete", t, func() { |
| 152 under, over, ds := mkds(dataMultiRoot) | 152 under, over, ds := mkds(dataMultiRoot) |
| 153 ds.Testable().SetTransactionRetryCount(1) | 153 ds.Testable().SetTransactionRetryCount(1) |
| 154 | 154 |
| 155 So(under.PutMulti.Total(), ShouldEqual, 0) | 155 So(under.PutMulti.Total(), ShouldEqual, 0) |
| 156 So(over.PutMulti.Total(), ShouldEqual, 0) | 156 So(over.PutMulti.Total(), ShouldEqual, 0) |
| 157 | 157 |
| 158 » » Convey("Good", func() { | 158 » » FocusConvey("Good", func() { |
|
dnj
2015/11/11 16:08:28
Switch back to regular Convey.
| |
| 159 Convey("read-only", func() { | 159 Convey("read-only", func() { |
| 160 So(ds.RunInTransaction(func(c context.Context) e rror { | 160 So(ds.RunInTransaction(func(c context.Context) e rror { |
| 161 ds := datastore.Get(c) | 161 ds := datastore.Get(c) |
| 162 | 162 |
| 163 So(4, fooShouldHave(ds), dataMultiRoot[3 ].Value) | 163 So(4, fooShouldHave(ds), dataMultiRoot[3 ].Value) |
| 164 return nil | 164 return nil |
| 165 }, nil), ShouldBeNil) | 165 }, nil), ShouldBeNil) |
| 166 }) | 166 }) |
| 167 | 167 |
| 168 Convey("single-level read/write", func() { | 168 Convey("single-level read/write", func() { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 180 return nil | 180 return nil |
| 181 }, &datastore.TransactionOptions{XG: true}), Sho uldBeNil) | 181 }, &datastore.TransactionOptions{XG: true}), Sho uldBeNil) |
| 182 | 182 |
| 183 // 2 because we are simulating a transaction fai lure | 183 // 2 because we are simulating a transaction fai lure |
| 184 So(under.PutMulti.Total(), ShouldEqual, 2) | 184 So(under.PutMulti.Total(), ShouldEqual, 2) |
| 185 | 185 |
| 186 So(3, fooShouldHave(ds), 1, 2, 3, 4) | 186 So(3, fooShouldHave(ds), 1, 2, 3, 4) |
| 187 So(4, fooShouldHave(ds), 1, 2, 3, 4) | 187 So(4, fooShouldHave(ds), 1, 2, 3, 4) |
| 188 }) | 188 }) |
| 189 | 189 |
| 190 » » » Convey("multi-level read/write", func() { | 190 » » » FocusConvey("multi-level read/write", func() { |
|
dnj
2015/11/11 16:08:28
Switch back to regular Convey.
iannucci
2015/11/11 18:06:40
oops, done (for both)
| |
| 191 So(ds.RunInTransaction(func(c context.Context) e rror { | 191 So(ds.RunInTransaction(func(c context.Context) e rror { |
| 192 ds := datastore.Get(c) | 192 ds := datastore.Get(c) |
| 193 | 193 |
| 194 So(3, fooShouldHave(ds), dataMultiRoot[2 ].Value) | 194 So(3, fooShouldHave(ds), dataMultiRoot[2 ].Value) |
| 195 | 195 |
| 196 So(3, fooSetTo(ds), 1, 2, 3, 4) | 196 So(3, fooSetTo(ds), 1, 2, 3, 4) |
| 197 So(7, fooSetTo(ds)) | 197 So(7, fooSetTo(ds)) |
| 198 | 198 |
| 199 vals := []*Foo{ | 199 vals := []*Foo{ |
| 200 {ID: 793}, | 200 {ID: 793}, |
| (...skipping 39 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 |