Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: impl/memory/datastore_test.go

Issue 1494223002: Add API to allow you to get the non-transactional datastore or taskqueue. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: fix doc and naming Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « impl/memory/datastore.go ('k') | impl/memory/taskqueue.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "time" 10 "time"
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 248
249 So(pm.SetMeta("key", k), ShouldB eNil) 249 So(pm.SetMeta("key", k), ShouldB eNil)
250 So(ds.Get(pm).Error(), ShouldCon tainSubstring, "cross-group") 250 So(ds.Get(pm).Error(), ShouldCon tainSubstring, "cross-group")
251 return nil 251 return nil
252 }, nil) 252 }, nil)
253 So(err, ShouldBeNil) 253 So(err, ShouldBeNil)
254 }) 254 })
255 255
256 Convey("Get takes a snapshot", func() { 256 Convey("Get takes a snapshot", func() {
257 err := ds.RunInTransaction(func(c contex t.Context) error { 257 err := ds.RunInTransaction(func(c contex t.Context) error {
258 » » » » » » txnDS := dsS.Get(c) 258 » » » » » » ds := dsS.Get(c)
259 259
260 » » » » » » So(txnDS.Get(f), ShouldBeNil) 260 » » » » » » So(ds.Get(f), ShouldBeNil)
261 So(f.Val, ShouldEqual, 10) 261 So(f.Val, ShouldEqual, 10)
262 262
263 // Don't ever do this in a real program unless you want to guarantee 263 // Don't ever do this in a real program unless you want to guarantee
264 // a failed transaction :) 264 // a failed transaction :)
265 f.Val = 11 265 f.Val = 11
266 » » » » » » So(ds.Put(f), ShouldBeNil) 266 » » » » » » So(dsS.GetNoTxn(c).Put(f), Shoul dBeNil)
267 267
268 » » » » » » So(txnDS.Get(f), ShouldBeNil) 268 » » » » » » So(ds.Get(f), ShouldBeNil)
269 So(f.Val, ShouldEqual, 10) 269 So(f.Val, ShouldEqual, 10)
270 270
271 return nil 271 return nil
272 }, nil) 272 }, nil)
273 So(err, ShouldBeNil) 273 So(err, ShouldBeNil)
274 274
275 f := &Foo{ID: 1} 275 f := &Foo{ID: 1}
276 So(ds.Get(f), ShouldBeNil) 276 So(ds.Get(f), ShouldBeNil)
277 So(f.Val, ShouldEqual, 11) 277 So(f.Val, ShouldEqual, 11)
278 }) 278 })
279 279
280 Convey("and snapshots are consistent even after Puts", func() { 280 Convey("and snapshots are consistent even after Puts", func() {
281 err := ds.RunInTransaction(func(c contex t.Context) error { 281 err := ds.RunInTransaction(func(c contex t.Context) error {
282 » » » » » » txnDS := dsS.Get(c) 282 » » » » » » ds := dsS.Get(c)
283 283
284 f := &Foo{ID: 1} 284 f := &Foo{ID: 1}
285 » » » » » » So(txnDS.Get(f), ShouldBeNil) 285 » » » » » » So(ds.Get(f), ShouldBeNil)
286 So(f.Val, ShouldEqual, 10) 286 So(f.Val, ShouldEqual, 10)
287 287
288 // Don't ever do this in a real program unless you want to guarantee 288 // Don't ever do this in a real program unless you want to guarantee
289 // a failed transaction :) 289 // a failed transaction :)
290 f.Val = 11 290 f.Val = 11
291 » » » » » » So(ds.Put(f), ShouldBeNil) 291 » » » » » » So(dsS.GetNoTxn(c).Put(f), Shoul dBeNil)
292 292
293 » » » » » » So(txnDS.Get(f), ShouldBeNil) 293 » » » » » » So(ds.Get(f), ShouldBeNil)
294 So(f.Val, ShouldEqual, 10) 294 So(f.Val, ShouldEqual, 10)
295 295
296 f.Val = 20 296 f.Val = 20
297 » » » » » » So(txnDS.Put(f), ShouldBeNil) 297 » » » » » » So(ds.Put(f), ShouldBeNil)
298 298
299 » » » » » » So(txnDS.Get(f), ShouldBeNil) 299 » » » » » » So(ds.Get(f), ShouldBeNil)
300 So(f.Val, ShouldEqual, 10) // st ill gets 10 300 So(f.Val, ShouldEqual, 10) // st ill gets 10
301 301
302 return nil 302 return nil
303 }, &dsS.TransactionOptions{Attempts: 1}) 303 }, &dsS.TransactionOptions{Attempts: 1})
304 So(err.Error(), ShouldContainSubstring, "concurrent") 304 So(err.Error(), ShouldContainSubstring, "concurrent")
305 305
306 f := &Foo{ID: 1} 306 f := &Foo{ID: 1}
307 So(ds.Get(f), ShouldBeNil) 307 So(ds.Get(f), ShouldBeNil)
308 So(f.Val, ShouldEqual, 11) 308 So(f.Val, ShouldEqual, 11)
309 }) 309 })
(...skipping 24 matching lines...) Expand all
334 // Note: I think this implementation is actually /slightly/ wrong. 334 // Note: I think this implementation is actually /slightly/ wrong.
335 // According to my read of the docs for appengine, when you open a 335 // According to my read of the docs for appengine, when you open a
336 // transaction it actually (essentially) holds a reference to the 336 // transaction it actually (essentially) holds a reference to the
337 // entire datastore. Our implementation takes a snapshot of the 337 // entire datastore. Our implementation takes a snapshot of the
338 // entity group as soon as something obs erves/affects it. 338 // entity group as soon as something obs erves/affects it.
339 // 339 //
340 // That said... I'm not sure if there's really a semantic difference. 340 // That said... I'm not sure if there's really a semantic difference.
341 err := ds.RunInTransaction(func(c contex t.Context) error { 341 err := ds.RunInTransaction(func(c contex t.Context) error {
342 So(dsS.Get(c).Put(&Foo{ID: 1, Va l: 21}), ShouldBeNil) 342 So(dsS.Get(c).Put(&Foo{ID: 1, Va l: 21}), ShouldBeNil)
343 343
344 » » » » » » err := ds.RunInTransaction(func( c context.Context) error { 344 » » » » » » err := dsS.GetNoTxn(c).RunInTran saction(func(c context.Context) error {
345 So(dsS.Get(c).Put(&Foo{I D: 1, Val: 27}), ShouldBeNil) 345 So(dsS.Get(c).Put(&Foo{I D: 1, Val: 27}), ShouldBeNil)
346 return nil 346 return nil
347 }, nil) 347 }, nil)
348 So(err, ShouldBeNil) 348 So(err, ShouldBeNil)
349 349
350 return nil 350 return nil
351 }, nil) 351 }, nil)
352 So(err.Error(), ShouldContainSubstring, "concurrent") 352 So(err.Error(), ShouldContainSubstring, "concurrent")
353 353
354 f := &Foo{ID: 1} 354 f := &Foo{ID: 1}
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 f := &Foo{ID: 1} 414 f := &Foo{ID: 1}
415 So(ds.Get(f), ShouldBeNil) 415 So(ds.Get(f), ShouldBeNil)
416 So(f.Val, ShouldEqual, 10) 416 So(f.Val, ShouldEqual, 10)
417 }) 417 })
418 }) 418 })
419 419
420 Convey("Transaction retries", func() { 420 Convey("Transaction retries", func() {
421 tst := ds.Testable() 421 tst := ds.Testable()
422 Reset(func() { tst.SetTransactionRetryCo unt(0) }) 422 Reset(func() { tst.SetTransactionRetryCo unt(0) })
423 423
424 » » » » » Convey("SetTransactionRetryCount set to zere", func() { 424 » » » » » Convey("SetTransactionRetryCount set to zero", func() {
425 tst.SetTransactionRetryCount(0) 425 tst.SetTransactionRetryCount(0)
426 calls := 0 426 calls := 0
427 So(ds.RunInTransaction(func(c co ntext.Context) error { 427 So(ds.RunInTransaction(func(c co ntext.Context) error {
428 calls++ 428 calls++
429 return nil 429 return nil
430 }, nil), ShouldBeNil) 430 }, nil), ShouldBeNil)
431 So(calls, ShouldEqual, 1) 431 So(calls, ShouldEqual, 1)
432 }) 432 })
433 433
434 Convey("default TransactionOptions is 3 attempts", func() { 434 Convey("default TransactionOptions is 3 attempts", func() {
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 So(ds.Put(&Model{ID: 1, Value: []int64{20, 30}}), ShouldBeNil) 624 So(ds.Put(&Model{ID: 1, Value: []int64{20, 30}}), ShouldBeNil)
625 625
626 vals := []dsS.PropertyMap{} 626 vals := []dsS.PropertyMap{}
627 So(ds.GetAll(dsS.NewQuery("Model").Project("Value"), &vals), Sho uldBeNil) 627 So(ds.GetAll(dsS.NewQuery("Model").Project("Value"), &vals), Sho uldBeNil)
628 So(len(vals), ShouldEqual, 2) 628 So(len(vals), ShouldEqual, 2)
629 629
630 So(vals[0]["Value"][0].Value(), ShouldEqual, 20) 630 So(vals[0]["Value"][0].Value(), ShouldEqual, 20)
631 So(vals[1]["Value"][0].Value(), ShouldEqual, 30) 631 So(vals[1]["Value"][0].Value(), ShouldEqual, 30)
632 }) 632 })
633 } 633 }
OLDNEW
« no previous file with comments | « impl/memory/datastore.go ('k') | impl/memory/taskqueue.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698