Index: filter/count/count_test.go |
diff --git a/filter/count/count_test.go b/filter/count/count_test.go |
index 08f2b2fa1bbea2c1fe1a7f20c706a9b2bad2adcb..28edc53034d9815ef928964896727fdf659693d4 100644 |
--- a/filter/count/count_test.go |
+++ b/filter/count/count_test.go |
@@ -10,9 +10,9 @@ import ( |
"github.com/luci/gae/filter/featureBreaker" |
"github.com/luci/gae/impl/memory" |
+ "github.com/luci/gae/service/datastore" |
"github.com/luci/gae/service/info" |
"github.com/luci/gae/service/memcache" |
- "github.com/luci/gae/service/rawdatastore" |
"github.com/luci/gae/service/taskqueue" |
. "github.com/smartystreets/goconvey/convey" |
"golang.org/x/net/context" |
@@ -21,14 +21,6 @@ import ( |
func TestCount(t *testing.T) { |
t.Parallel() |
- pnil := func(_ rawdatastore.Key, err error) { |
- So(err, ShouldBeNil) |
- } |
- |
- gnil := func(_ rawdatastore.PropertyMap, err error) { |
- So(err, ShouldBeNil) |
- } |
- |
Convey("Test Count filter", t, func() { |
c, fb := featureBreaker.FilterRDS(memory.Use(context.Background()), nil) |
c, ctr := FilterRDS(c) |
@@ -36,32 +28,25 @@ func TestCount(t *testing.T) { |
So(c, ShouldNotBeNil) |
So(ctr, ShouldNotBeNil) |
- rds := rawdatastore.Get(c) |
+ ds := datastore.Get(c) |
+ vals := []datastore.PropertyMap{{ |
+ "Val": {datastore.MkProperty(100)}, |
+ "$key": {datastore.MkPropertyNI(ds.NewKey("Kind", "", 1, nil))}, |
+ }} |
- Convey("Calling a rds function should reflect in counter", func() { |
- p := rawdatastore.Property{} |
- p.SetValue(100, false) |
- keys := []rawdatastore.Key{rds.NewKey("Kind", "", 0, nil)} |
- vals := []rawdatastore.PropertyLoadSaver{&rawdatastore.PropertyMap{"Val": {p}}} |
- |
- So(rds.PutMulti(keys, vals, pnil), ShouldBeNil) |
+ Convey("Calling a ds function should reflect in counter", func() { |
+ So(ds.PutMulti(vals), ShouldBeNil) |
So(ctr.NewKey.Successes, ShouldEqual, 1) |
So(ctr.PutMulti.Successes, ShouldEqual, 1) |
Convey("effects are cumulative", func() { |
- So(rds.PutMulti(keys, vals, pnil), ShouldBeNil) |
+ So(ds.PutMulti(vals), ShouldBeNil) |
So(ctr.PutMulti.Successes, ShouldEqual, 2) |
Convey("even within transactions", func() { |
- root := rds.NewKey("Root", "", 1, nil) |
- rds.RunInTransaction(func(c context.Context) error { |
- rds := rawdatastore.Get(c) |
- keys := []rawdatastore.Key{ |
- rds.NewKey("Kind", "hi", 0, root), |
- rds.NewKey("Kind", "there", 0, root), |
- } |
- vals = append(vals, vals[0]) |
- So(rds.PutMulti(keys, vals, pnil), ShouldBeNil) |
+ ds.RunInTransaction(func(c context.Context) error { |
+ ds := datastore.Get(c) |
+ So(ds.PutMulti(append(vals, vals[0])), ShouldBeNil) |
return nil |
}, nil) |
}) |
@@ -69,23 +54,16 @@ func TestCount(t *testing.T) { |
}) |
Convey("errors count against errors", func() { |
- keys := []rawdatastore.Key{rds.NewKey("Kind", "", 1, nil)} |
- vals := []rawdatastore.PropertyLoadSaver{&rawdatastore.PropertyMap{"Val": {{}}}} |
- |
fb.BreakFeatures(nil, "GetMulti") |
- rds.GetMulti(keys, gnil) |
+ ds.GetMulti(vals) |
So(ctr.GetMulti.Errors, ShouldEqual, 1) |
fb.UnbreakFeatures("GetMulti") |
- err := rds.PutMulti(keys, vals, func(k rawdatastore.Key, err error) { |
- keys[0] = k |
- So(err, ShouldBeNil) |
- }) |
- So(err, ShouldBeNil) |
+ So(ds.PutMulti(vals), ShouldBeNil) |
- rds.GetMulti(keys, gnil) |
+ ds.GetMulti(vals) |
So(ctr.GetMulti.Errors, ShouldEqual, 1) |
So(ctr.GetMulti.Successes, ShouldEqual, 1) |
So(ctr.GetMulti.Total(), ShouldEqual, 2) |
@@ -142,17 +120,17 @@ func ExampleFilterRDS() { |
// Apply the counter.FilterRDS |
c, counter := FilterRDS(c) |
- // functions use RDS from the context like normal... they don't need to know |
+ // functions use ds from the context like normal... they don't need to know |
// that there are any filters at all. |
someCalledFunc := func(c context.Context) { |
- rds := rawdatastore.Get(c) |
- key := rds.NewKey("Kind", "", 1, nil) |
- prop := rawdatastore.Property{} |
- prop.SetValue(100, false) |
- val := rawdatastore.PropertyMap{ |
- "FieldName": {prop}, |
+ ds := datastore.Get(c) |
+ vals := []datastore.PropertyMap{{ |
+ "FieldName": {datastore.MkProperty(100)}, |
+ "$key": {datastore.MkProperty(ds.NewKey("Kind", "", 1, nil))}}, |
+ } |
+ if err := ds.PutMulti(vals); err != nil { |
+ panic(err) |
} |
- rds.PutMulti([]rawdatastore.Key{key}, []rawdatastore.PropertyLoadSaver{&val}, nil) |
} |
// Using the other function. |