| 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 // +build appengine | 5 // +build appengine |
| 6 | 6 |
| 7 package prod | 7 package prod |
| 8 | 8 |
| 9 import ( | 9 import ( |
| 10 "testing" | 10 "testing" |
| 11 "time" | 11 "time" |
| 12 | 12 |
| 13 "github.com/luci/gae/service/blobstore" | 13 "github.com/luci/gae/service/blobstore" |
| 14 ds "github.com/luci/gae/service/datastore" | 14 ds "github.com/luci/gae/service/datastore" |
| 15 "github.com/luci/gae/service/info" | 15 "github.com/luci/gae/service/info" |
| 16 mc "github.com/luci/gae/service/memcache" | 16 mc "github.com/luci/gae/service/memcache" |
| 17 | 17 |
| 18 "github.com/luci/luci-go/common/logging" | 18 "github.com/luci/luci-go/common/logging" |
| 19 | 19 |
| 20 "golang.org/x/net/context" | 20 "golang.org/x/net/context" |
| 21 "google.golang.org/appengine/aetest" | 21 "google.golang.org/appengine/aetest" |
| 22 "google.golang.org/appengine/datastore" |
| 22 | 23 |
| 23 . "github.com/smartystreets/goconvey/convey" | 24 . "github.com/smartystreets/goconvey/convey" |
| 24 ) | 25 ) |
| 25 | 26 |
| 26 var ( | 27 var ( |
| 27 mp = ds.MkProperty | 28 mp = ds.MkProperty |
| 28 mpNI = ds.MkPropertyNI | 29 mpNI = ds.MkPropertyNI |
| 29 ) | 30 ) |
| 30 | 31 |
| 31 type TestStruct struct { | 32 type TestStruct struct { |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 Convey("memcache: Set (nil) is the same as Set ([]byte{})", func
() { | 275 Convey("memcache: Set (nil) is the same as Set ([]byte{})", func
() { |
| 275 So(mc.Set(ctx, mc.NewItem(ctx, "bob")), ShouldBeNil) //
normally would panic because Value is nil | 276 So(mc.Set(ctx, mc.NewItem(ctx, "bob")), ShouldBeNil) //
normally would panic because Value is nil |
| 276 | 277 |
| 277 bob, err := mc.GetKey(ctx, "bob") | 278 bob, err := mc.GetKey(ctx, "bob") |
| 278 So(err, ShouldBeNil) | 279 So(err, ShouldBeNil) |
| 279 So(bob.Value(), ShouldResemble, []byte{}) | 280 So(bob.Value(), ShouldResemble, []byte{}) |
| 280 }) | 281 }) |
| 281 }) | 282 }) |
| 282 } | 283 } |
| 283 | 284 |
| 285 func TestRawAppEngineAccess(t *testing.T) { |
| 286 t.Parallel() |
| 287 |
| 288 Convey("An AppEngine testing instance bound to a Context with services i
nstalled", t, func() { |
| 289 inst, err := aetest.NewInstance(&aetest.Options{ |
| 290 StronglyConsistentDatastore: true, |
| 291 }) |
| 292 So(err, ShouldBeNil) |
| 293 defer inst.Close() |
| 294 |
| 295 req, err := inst.NewRequest("GET", "/", nil) |
| 296 So(err, ShouldBeNil) |
| 297 |
| 298 ctx := Use(context.Background(), req) |
| 299 |
| 300 Convey("Can issue a raw datastore Put/Get", func() { |
| 301 key := datastore.NewKey(ctx, "Test", "foo", 0, nil) |
| 302 obj := struct { |
| 303 A string |
| 304 B int64 |
| 305 C time.Time |
| 306 }{"bar", 1337, ds.RoundTime(time.Date(1938, time.January
, 1, 1, 1, 1, 1, time.UTC))} |
| 307 _, err := datastore.Put(ctx, key, &obj) |
| 308 So(err, ShouldBeNil) |
| 309 |
| 310 other := obj |
| 311 other.A, other.B, other.C = "", 0, time.Time{} |
| 312 So(datastore.Get(ctx, key, &other), ShouldBeNil) |
| 313 So(other, ShouldResemble, obj) |
| 314 }) |
| 315 }) |
| 316 } |
| 317 |
| 284 func BenchmarkTransactionsParallel(b *testing.B) { | 318 func BenchmarkTransactionsParallel(b *testing.B) { |
| 285 type Counter struct { | 319 type Counter struct { |
| 286 ID int `gae:"$id"` | 320 ID int `gae:"$id"` |
| 287 Count int | 321 Count int |
| 288 } | 322 } |
| 289 | 323 |
| 290 inst, err := aetest.NewInstance(&aetest.Options{ | 324 inst, err := aetest.NewInstance(&aetest.Options{ |
| 291 StronglyConsistentDatastore: true, | 325 StronglyConsistentDatastore: true, |
| 292 }) | 326 }) |
| 293 if err != nil { | 327 if err != nil { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 317 default: | 351 default: |
| 318 return err | 352 return err |
| 319 } | 353 } |
| 320 }, &ds.TransactionOptions{Attempts: 9999999}) | 354 }, &ds.TransactionOptions{Attempts: 9999999}) |
| 321 if err != nil { | 355 if err != nil { |
| 322 b.Fatalf("failed to run transaction: %v", err) | 356 b.Fatalf("failed to run transaction: %v", err) |
| 323 } | 357 } |
| 324 } | 358 } |
| 325 }) | 359 }) |
| 326 } | 360 } |
| OLD | NEW |