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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 }) | 314 }) |
315 | 315 |
316 }) | 316 }) |
317 | 317 |
318 }) | 318 }) |
319 } | 319 } |
320 | 320 |
321 func TestHuge(t *testing.T) { | 321 func TestHuge(t *testing.T) { |
322 t.Parallel() | 322 t.Parallel() |
323 | 323 |
324 » Convey("inner txn too big allows outer txn", t, func() { | 324 » Convey("testing datastore enforces thresholds", t, func() { |
325 _, _, ds := mkds(dataMultiRoot) | 325 _, _, ds := mkds(dataMultiRoot) |
326 | 326 |
327 » » So(ds.RunInTransaction(func(c context.Context) error { | 327 » » Convey("exceeding inner txn size threshold still allows outer",
func() { |
328 » » » ds := datastore.Get(c) | |
329 | |
330 » » » So(18, fooSetTo(ds), hugeField) | |
331 | |
332 So(ds.RunInTransaction(func(c context.Context) error { | 328 So(ds.RunInTransaction(func(c context.Context) error { |
333 ds := datastore.Get(c) | 329 ds := datastore.Get(c) |
| 330 |
| 331 So(18, fooSetTo(ds), hugeField) |
| 332 |
| 333 So(ds.RunInTransaction(func(c context.Context) e
rror { |
| 334 ds := datastore.Get(c) |
| 335 So(ds.PutMulti(hugeData), ShouldBeNil) |
| 336 return nil |
| 337 }, nil), ShouldErrLike, ErrTransactionTooLarge) |
| 338 |
| 339 return nil |
| 340 }, &datastore.TransactionOptions{XG: true}), ShouldBeNil
) |
| 341 |
| 342 So(18, fooShouldHave(ds), hugeField) |
| 343 }) |
| 344 |
| 345 Convey("exceeding inner txn count threshold still allows outer",
func() { |
| 346 So(ds.RunInTransaction(func(c context.Context) error { |
| 347 ds := datastore.Get(c) |
| 348 |
| 349 So(18, fooSetTo(ds), hugeField) |
| 350 |
| 351 So(ds.RunInTransaction(func(c context.Context) e
rror { |
| 352 ds := datastore.Get(c) |
| 353 p := ds.MakeKey("mom", 1) |
| 354 |
| 355 // This will exceed the budget, since we
've already done one write in |
| 356 // the parent. |
| 357 for i := 1; i <= DefaultWriteCountBudget
; i++ { |
| 358 So(ds.Put(&Foo{ID: int64(i), Par
ent: p}), ShouldBeNil) |
| 359 } |
| 360 return nil |
| 361 }, nil), ShouldErrLike, ErrTransactionTooLarge) |
| 362 |
| 363 return nil |
| 364 }, &datastore.TransactionOptions{XG: true}), ShouldBeNil
) |
| 365 |
| 366 So(18, fooShouldHave(ds), hugeField) |
| 367 }) |
| 368 |
| 369 Convey("exceeding threshold in the parent, then retreating in th
e child is okay", func() { |
| 370 So(ds.RunInTransaction(func(c context.Context) error { |
| 371 ds := datastore.Get(c) |
| 372 |
334 So(ds.PutMulti(hugeData), ShouldBeNil) | 373 So(ds.PutMulti(hugeData), ShouldBeNil) |
| 374 So(18, fooSetTo(ds), hugeField) |
| 375 |
| 376 // We're over threshold! But the child will dele
te most of this and |
| 377 // bring us back to normal. |
| 378 So(ds.RunInTransaction(func(c context.Context) e
rror { |
| 379 ds := datastore.Get(c) |
| 380 keys := make([]*datastore.Key, len(hugeD
ata)) |
| 381 for i, d := range hugeData { |
| 382 keys[i] = ds.KeyForObj(d) |
| 383 } |
| 384 return ds.DeleteMulti(keys) |
| 385 }, nil), ShouldBeNil) |
| 386 |
335 return nil | 387 return nil |
336 » » » }, nil), ShouldErrLike, ErrTransactionTooLarge) | 388 » » » }, &datastore.TransactionOptions{XG: true}), ShouldBeNil
) |
337 | 389 |
338 » » » return nil | 390 » » » So(18, fooShouldHave(ds), hugeField) |
339 » » }, &datastore.TransactionOptions{XG: true}), ShouldBeNil) | 391 » » }) |
340 | |
341 » » So(18, fooShouldHave(ds), hugeField) | |
342 » }) | |
343 | |
344 » Convey("outer txn too big prevents inner txn", t, func() { | |
345 » » _, _, ds := mkds(dataMultiRoot) | |
346 | |
347 » » So(ds.RunInTransaction(func(c context.Context) error { | |
348 » » » ds := datastore.Get(c) | |
349 | |
350 » » » So(ds.PutMulti(hugeData), ShouldBeNil) | |
351 | |
352 » » » So(ds.RunInTransaction(func(c context.Context) error { | |
353 » » » » panic("never!") | |
354 » » » }, nil), ShouldErrLike, ErrTransactionTooLarge) | |
355 | |
356 » » » return nil | |
357 » » }, &datastore.TransactionOptions{XG: true}), ShouldBeNil) | |
358 | |
359 » » So(1, fooShouldHave(ds), hugeField) | |
360 }) | 392 }) |
361 } | 393 } |
362 | 394 |
363 func TestQuerySupport(t *testing.T) { | 395 func TestQuerySupport(t *testing.T) { |
364 t.Parallel() | 396 t.Parallel() |
365 | 397 |
366 Convey("Queries", t, func() { | 398 Convey("Queries", t, func() { |
367 Convey("Good", func() { | 399 Convey("Good", func() { |
368 q := datastore.NewQuery("Foo").Ancestor(root) | 400 q := datastore.NewQuery("Foo").Ancestor(root) |
369 | 401 |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 val := pm["Value"] | 901 val := pm["Value"] |
870 So(val[len(val)-1].Value(), ShouldResemb
le, "wat") | 902 So(val[len(val)-1].Value(), ShouldResemb
le, "wat") |
871 }), ShouldBeNil) | 903 }), ShouldBeNil) |
872 }) | 904 }) |
873 | 905 |
874 }) | 906 }) |
875 | 907 |
876 }) | 908 }) |
877 | 909 |
878 } | 910 } |
OLD | NEW |