| 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 memory | 5 package memory |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "testing" | 8 "testing" |
| 9 "time" | 9 "time" |
| 10 | 10 |
| 11 mcS "github.com/luci/gae/service/memcache" | 11 mcS "github.com/luci/gae/service/memcache" |
| 12 "github.com/luci/luci-go/common/clock/testclock" | 12 "github.com/luci/luci-go/common/clock/testclock" |
| 13 . "github.com/luci/luci-go/common/testing/assertions" |
| 13 . "github.com/smartystreets/goconvey/convey" | 14 . "github.com/smartystreets/goconvey/convey" |
| 14 "golang.org/x/net/context" | 15 "golang.org/x/net/context" |
| 15 ) | 16 ) |
| 16 | 17 |
| 17 func TestMemcache(t *testing.T) { | 18 func TestMemcache(t *testing.T) { |
| 18 t.Parallel() | 19 t.Parallel() |
| 19 | 20 |
| 20 Convey("memcache", t, func() { | 21 Convey("memcache", t, func() { |
| 21 now := time.Date(2015, 1, 1, 0, 0, 0, 0, time.UTC) | 22 now := time.Date(2015, 1, 1, 0, 0, 0, 0, time.UTC) |
| 22 c, tc := testclock.UseTime(context.Background(), now) | 23 c, tc := testclock.UseTime(context.Background(), now) |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 testItem := &mcItem{ | 95 testItem := &mcItem{ |
| 95 key: "sup", | 96 key: "sup", |
| 96 value: []byte("newp"), | 97 value: []byte("newp"), |
| 97 CasID: 2, | 98 CasID: 2, |
| 98 } | 99 } |
| 99 getItm := mc.NewItem("sup") | 100 getItm := mc.NewItem("sup") |
| 100 So(mc.Get(getItm), ShouldBeNil) | 101 So(mc.Get(getItm), ShouldBeNil) |
| 101 So(getItm, ShouldResemble, testItem) | 102 So(getItm, ShouldResemble, testItem) |
| 102 | 103 |
| 103 Convey("Flush works too", func() { | 104 Convey("Flush works too", func() { |
| 104 » » » » » mc.Flush() | 105 » » » » » So(mc.Flush(), ShouldBeNil) |
| 105 So(mc.Get(getItm), ShouldEqual, mcS.ErrC
acheMiss) | 106 So(mc.Get(getItm), ShouldEqual, mcS.ErrC
acheMiss) |
| 106 }) | 107 }) |
| 107 }) | 108 }) |
| 108 | 109 |
| 109 Convey("Increment", func() { | 110 Convey("Increment", func() { |
| 110 val, err := mc.Increment("num", 7, 2) | 111 val, err := mc.Increment("num", 7, 2) |
| 111 So(err, ShouldBeNil) | 112 So(err, ShouldBeNil) |
| 112 So(val, ShouldEqual, 9) | 113 So(val, ShouldEqual, 9) |
| 113 | 114 |
| 114 Convey("IncrementExisting", func() { | 115 Convey("IncrementExisting", func() { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 }) | 162 }) |
| 162 | 163 |
| 163 Convey("check that the internal implementation is sane", func()
{ | 164 Convey("check that the internal implementation is sane", func()
{ |
| 164 curTime := now | 165 curTime := now |
| 165 err := mc.Add(&mcItem{ | 166 err := mc.Add(&mcItem{ |
| 166 key: "sup", | 167 key: "sup", |
| 167 value: []byte("cool"), | 168 value: []byte("cool"), |
| 168 expiration: time.Second * 2, | 169 expiration: time.Second * 2, |
| 169 }) | 170 }) |
| 170 | 171 |
| 171 » » » mc.Get(mc.NewItem("sup")) | 172 » » » So(mc.Get(mc.NewItem("sup")), ShouldBeNil) |
| 172 » » » mc.Get(mc.NewItem("sup")) | 173 » » » So(mc.Get(mc.NewItem("sup")), ShouldBeNil) |
| 173 » » » mc.Get(mc.NewItem("sup")) | 174 » » » So(mc.Get(mc.NewItem("sup")), ShouldBeNil) |
| 174 » » » mc.Get(mc.NewItem("sup")) | 175 » » » So(mc.Get(mc.NewItem("sup")), ShouldBeNil) |
| 175 » » » mc.Get(mc.NewItem("wot")) | 176 » » » So(mc.Get(mc.NewItem("wot")), ShouldErrLike, mcS.ErrCach
eMiss) |
| 176 | 177 |
| 177 mci := mc.Raw().(*memcacheImpl) | 178 mci := mc.Raw().(*memcacheImpl) |
| 178 | 179 |
| 179 So(err, ShouldBeNil) | 180 So(err, ShouldBeNil) |
| 180 stats, err := mc.Stats() | 181 stats, err := mc.Stats() |
| 181 So(err, ShouldBeNil) | 182 So(err, ShouldBeNil) |
| 182 So(stats.Items, ShouldEqual, 1) | 183 So(stats.Items, ShouldEqual, 1) |
| 183 So(stats.Bytes, ShouldEqual, 4) | 184 So(stats.Bytes, ShouldEqual, 4) |
| 184 So(stats.Hits, ShouldEqual, 4) | 185 So(stats.Hits, ShouldEqual, 4) |
| 185 So(stats.Misses, ShouldEqual, 1) | 186 So(stats.Misses, ShouldEqual, 1) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 199 testItem := &mcItem{ | 200 testItem := &mcItem{ |
| 200 key: "sup", | 201 key: "sup", |
| 201 value: []byte("cool"), | 202 value: []byte("cool"), |
| 202 CasID: 1, | 203 CasID: 1, |
| 203 } | 204 } |
| 204 So(getItm, ShouldResemble, testItem) | 205 So(getItm, ShouldResemble, testItem) |
| 205 }) | 206 }) |
| 206 | 207 |
| 207 }) | 208 }) |
| 208 } | 209 } |
| OLD | NEW |