Index: go/src/infra/gae/libs/gae/memory/memcache_test.go |
diff --git a/go/src/infra/gae/libs/wrapper/memory/memcache_test.go b/go/src/infra/gae/libs/gae/memory/memcache_test.go |
similarity index 59% |
rename from go/src/infra/gae/libs/wrapper/memory/memcache_test.go |
rename to go/src/infra/gae/libs/gae/memory/memcache_test.go |
index ab1934c7aea78b8a39f47e86d67d223e6ab8764c..0829aa40185f6da07d4d7b1ec71ddfdcaaa19da0 100644 |
--- a/go/src/infra/gae/libs/wrapper/memory/memcache_test.go |
+++ b/go/src/infra/gae/libs/gae/memory/memcache_test.go |
@@ -5,16 +5,14 @@ |
package memory |
import ( |
- "infra/gae/libs/wrapper" |
- "infra/gae/libs/wrapper/unsafe" |
- "infra/libs/clock/testclock" |
+ "golang.org/x/net/context" |
+ "infra/gae/libs/gae" |
"testing" |
"time" |
- . "github.com/smartystreets/goconvey/convey" |
- "golang.org/x/net/context" |
+ "github.com/luci/luci-go/common/clock/testclock" |
- "appengine/memcache" |
+ . "github.com/smartystreets/goconvey/convey" |
) |
func TestMemcache(t *testing.T) { |
@@ -24,45 +22,45 @@ func TestMemcache(t *testing.T) { |
now := time.Date(2015, 1, 1, 0, 0, 0, 0, time.UTC) |
c, tc := testclock.UseTime(context.Background(), now) |
c = Use(c) |
- mc := wrapper.GetMC(c) |
- mci := wrapper.GetMC(c).(*memcacheImpl) |
+ mc := gae.GetMC(c) |
+ mci := gae.GetMC(c).(*memcacheImpl) |
So(mc, ShouldNotEqual, mci) // two impls with the same memcacheData |
Convey("implements MCSingleReadWriter", func() { |
Convey("Add", func() { |
- itm := &memcache.Item{ |
- Key: "sup", |
- Value: []byte("cool"), |
- Expiration: time.Second, |
+ itm := &mcItem{ |
+ key: "sup", |
+ value: []byte("cool"), |
+ expiration: time.Second, |
} |
err := mc.Add(itm) |
So(err, ShouldBeNil) |
Convey("which rejects objects already there", func() { |
err := mc.Add(itm) |
- So(err, ShouldEqual, memcache.ErrNotStored) |
+ So(err, ShouldEqual, gae.ErrMCNotStored) |
}) |
Convey("which can be broken intentionally", func() { |
mci.BreakFeatures(nil, "Add") |
err := mc.Add(itm) |
- So(err, ShouldEqual, memcache.ErrServerError) |
+ So(err, ShouldEqual, gae.ErrMCServerError) |
}) |
}) |
Convey("Get", func() { |
- itm := &memcache.Item{ |
- Key: "sup", |
- Value: []byte("cool"), |
- Expiration: time.Second, |
+ itm := &mcItem{ |
+ key: "sup", |
+ value: []byte("cool"), |
+ expiration: time.Second, |
} |
err := mc.Add(itm) |
So(err, ShouldBeNil) |
- testItem := &memcache.Item{ |
- Key: "sup", |
- Value: []byte("cool"), |
+ testItem := &mcItem{ |
+ key: "sup", |
+ value: []byte("cool"), |
+ CasID: 1, |
} |
- unsafe.MCSetCasID(testItem, 1) |
i, err := mc.Get("sup") |
So(err, ShouldBeNil) |
So(i, ShouldResemble, testItem) |
@@ -70,23 +68,23 @@ func TestMemcache(t *testing.T) { |
Convey("which can expire", func() { |
tc.Add(time.Second * 4) |
i, err := mc.Get("sup") |
- So(err, ShouldEqual, memcache.ErrCacheMiss) |
+ So(err, ShouldEqual, gae.ErrMCCacheMiss) |
So(i, ShouldBeNil) |
}) |
Convey("which can be broken intentionally", func() { |
mci.BreakFeatures(nil, "Get") |
_, err := mc.Get("sup") |
- So(err, ShouldEqual, memcache.ErrServerError) |
+ So(err, ShouldEqual, gae.ErrMCServerError) |
}) |
}) |
Convey("Delete", func() { |
Convey("works if it's there", func() { |
- itm := &memcache.Item{ |
- Key: "sup", |
- Value: []byte("cool"), |
- Expiration: time.Second, |
+ itm := &mcItem{ |
+ key: "sup", |
+ value: []byte("cool"), |
+ expiration: time.Second, |
} |
err := mc.Add(itm) |
So(err, ShouldBeNil) |
@@ -95,40 +93,40 @@ func TestMemcache(t *testing.T) { |
So(err, ShouldBeNil) |
i, err := mc.Get("sup") |
- So(err, ShouldEqual, memcache.ErrCacheMiss) |
+ So(err, ShouldEqual, gae.ErrMCCacheMiss) |
So(i, ShouldBeNil) |
}) |
Convey("but not if it's not there", func() { |
err := mc.Delete("sup") |
- So(err, ShouldEqual, memcache.ErrCacheMiss) |
+ So(err, ShouldEqual, gae.ErrMCCacheMiss) |
}) |
Convey("and can be broken", func() { |
mci.BreakFeatures(nil, "Delete") |
err := mc.Delete("sup") |
- So(err, ShouldEqual, memcache.ErrServerError) |
+ So(err, ShouldEqual, gae.ErrMCServerError) |
}) |
}) |
Convey("Set", func() { |
- itm := &memcache.Item{ |
- Key: "sup", |
- Value: []byte("cool"), |
- Expiration: time.Second, |
+ itm := &mcItem{ |
+ key: "sup", |
+ value: []byte("cool"), |
+ expiration: time.Second, |
} |
err := mc.Add(itm) |
So(err, ShouldBeNil) |
- itm.Value = []byte("newp") |
+ itm.SetValue([]byte("newp")) |
err = mc.Set(itm) |
So(err, ShouldBeNil) |
- testItem := &memcache.Item{ |
- Key: "sup", |
- Value: []byte("newp"), |
+ testItem := &mcItem{ |
+ key: "sup", |
+ value: []byte("newp"), |
+ CasID: 2, |
} |
- unsafe.MCSetCasID(testItem, 2) |
i, err := mc.Get("sup") |
So(err, ShouldBeNil) |
So(i, ShouldResemble, testItem) |
@@ -136,66 +134,66 @@ func TestMemcache(t *testing.T) { |
Convey("and can be broken", func() { |
mci.BreakFeatures(nil, "Set") |
err := mc.Set(itm) |
- So(err, ShouldEqual, memcache.ErrServerError) |
+ So(err, ShouldEqual, gae.ErrMCServerError) |
}) |
}) |
Convey("CompareAndSwap", func() { |
- itm := &memcache.Item{ |
- Key: "sup", |
- Value: []byte("cool"), |
- Expiration: time.Second * 2, |
- } |
+ itm := gae.MCItem(&mcItem{ |
+ key: "sup", |
+ value: []byte("cool"), |
+ expiration: time.Second * 2, |
+ }) |
err := mc.Add(itm) |
So(err, ShouldBeNil) |
Convey("works after a Get", func() { |
itm, err = mc.Get("sup") |
So(err, ShouldBeNil) |
- So(unsafe.MCGetCasID(itm), ShouldEqual, 1) |
+ So(itm.(*mcItem).CasID, ShouldEqual, 1) |
- itm.Value = []byte("newp") |
+ itm.SetValue([]byte("newp")) |
err = mc.CompareAndSwap(itm) |
So(err, ShouldBeNil) |
}) |
Convey("but fails if you don't", func() { |
- itm.Value = []byte("newp") |
+ itm.SetValue([]byte("newp")) |
err = mc.CompareAndSwap(itm) |
- So(err, ShouldEqual, memcache.ErrCASConflict) |
+ So(err, ShouldEqual, gae.ErrMCCASConflict) |
}) |
Convey("and fails if the item is expired/gone", func() { |
tc.Add(3 * time.Second) |
- itm.Value = []byte("newp") |
+ itm.SetValue([]byte("newp")) |
err = mc.CompareAndSwap(itm) |
- So(err, ShouldEqual, memcache.ErrNotStored) |
+ So(err, ShouldEqual, gae.ErrMCNotStored) |
}) |
Convey("and can be broken", func() { |
mci.BreakFeatures(nil, "CompareAndSwap") |
err = mc.CompareAndSwap(itm) |
- So(err, ShouldEqual, memcache.ErrServerError) |
+ So(err, ShouldEqual, gae.ErrMCServerError) |
}) |
}) |
}) |
Convey("check that the internal implementation is sane", func() { |
curTime := now |
- err := mc.Add(&memcache.Item{ |
- Key: "sup", |
- Value: []byte("cool"), |
- Expiration: time.Second * 2, |
+ err := mc.Add(&mcItem{ |
+ key: "sup", |
+ value: []byte("cool"), |
+ expiration: time.Second * 2, |
}) |
So(err, ShouldBeNil) |
So(len(mci.data.items), ShouldEqual, 1) |
So(mci.data.casID, ShouldEqual, 1) |
- So(mci.data.items["sup"], ShouldResemble, &unsafe.Item{ |
- Key: "sup", |
- Value: []byte("cool"), |
+ So(mci.data.items["sup"], ShouldResemble, &mcItem{ |
+ key: "sup", |
+ value: []byte("cool"), |
+ expiration: time.Duration(curTime.Add(time.Second * 2).UnixNano()), |
CasID: 1, |
- Expiration: time.Duration(curTime.Add(time.Second * 2).UnixNano()), |
}) |
el, err := mc.Get("sup") |
@@ -203,11 +201,11 @@ func TestMemcache(t *testing.T) { |
So(len(mci.data.items), ShouldEqual, 1) |
So(mci.data.casID, ShouldEqual, 1) |
- testItem := &memcache.Item{ |
- Key: "sup", |
- Value: []byte("cool"), |
+ testItem := &mcItem{ |
+ key: "sup", |
+ value: []byte("cool"), |
+ CasID: 1, |
} |
- unsafe.MCSetCasID(testItem, 1) |
So(el, ShouldResemble, testItem) |
}) |