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

Side by Side Diff: logdog/common/storage/bigtable/storage_test.go

Issue 2611253005: Fix BigTable multi-entry row cached Tail. (Closed)
Patch Set: Created 3 years, 11 months 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
OLDNEW
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 package bigtable 5 package bigtable
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "strconv" 9 "strconv"
10 "testing" 10 "testing"
11 11
12 "github.com/luci/luci-go/common/config" 12 "github.com/luci/luci-go/common/config"
13 "github.com/luci/luci-go/common/data/recordio" 13 "github.com/luci/luci-go/common/data/recordio"
14 "github.com/luci/luci-go/logdog/common/storage" 14 "github.com/luci/luci-go/logdog/common/storage"
15 "github.com/luci/luci-go/logdog/common/storage/memory"
15 "github.com/luci/luci-go/logdog/common/types" 16 "github.com/luci/luci-go/logdog/common/types"
16 "golang.org/x/net/context" 17 "golang.org/x/net/context"
17 18
18 . "github.com/luci/luci-go/common/testing/assertions" 19 . "github.com/luci/luci-go/common/testing/assertions"
19 . "github.com/smartystreets/goconvey/convey" 20 . "github.com/smartystreets/goconvey/convey"
20 ) 21 )
21 22
22 func mustGetIndex(e *storage.Entry) types.MessageIndex { 23 func mustGetIndex(e *storage.Entry) types.MessageIndex {
23 idx, err := e.GetStreamIndex() 24 idx, err := e.GetStreamIndex()
24 if err != nil { 25 if err != nil {
25 panic(err) 26 panic(err)
26 } 27 }
27 return idx 28 return idx
28 } 29 }
29 30
30 func TestStorage(t *testing.T) { 31 func TestStorage(t *testing.T) {
31 t.Parallel() 32 t.Parallel()
32 33
33 Convey(`A BigTable storage instance bound to a testing BigTable instance `, t, func() { 34 Convey(`A BigTable storage instance bound to a testing BigTable instance `, t, func() {
34 » » s := NewMemoryInstance(context.Background(), Options{}) 35 » » var cache memory.Cache
36 » » s := NewMemoryInstance(context.Background(), Options{
37 » » » Cache: &cache,
38 » » })
35 defer s.Close() 39 defer s.Close()
36 40
37 project := config.ProjectName("test-project") 41 project := config.ProjectName("test-project")
38 get := func(path string, index int, limit int, keysOnly bool) ([ ]string, error) { 42 get := func(path string, index int, limit int, keysOnly bool) ([ ]string, error) {
39 req := storage.GetRequest{ 43 req := storage.GetRequest{
40 Project: project, 44 Project: project,
41 Path: types.StreamPath(path), 45 Path: types.StreamPath(path),
42 Index: types.MessageIndex(index), 46 Index: types.MessageIndex(index),
43 Limit: limit, 47 Limit: limit,
44 KeysOnly: keysOnly, 48 KeysOnly: keysOnly,
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 if err != nil { 208 if err != nil {
205 return "", err 209 return "", err
206 } 210 }
207 return string(e.D), nil 211 return string(e.D), nil
208 } 212 }
209 213
210 Convey(`A tail request for "A" returns A{4}.`, f unc() { 214 Convey(`A tail request for "A" returns A{4}.`, f unc() {
211 got, err := tail("A") 215 got, err := tail("A")
212 So(err, ShouldBeNil) 216 So(err, ShouldBeNil)
213 So(got, ShouldEqual, "4") 217 So(got, ShouldEqual, "4")
218
219 Convey(`(Cache) A second request also re turns A{4}.`, func() {
220 got, err := tail("A")
221 So(err, ShouldBeNil)
222 So(got, ShouldEqual, "4")
223 })
214 }) 224 })
215 225
216 Convey(`A tail request for "B" returns nothing ( no contiguous logs).`, func() { 226 Convey(`A tail request for "B" returns nothing ( no contiguous logs).`, func() {
217 _, err := tail("B") 227 _, err := tail("B")
218 So(err, ShouldEqual, storage.ErrDoesNotE xist) 228 So(err, ShouldEqual, storage.ErrDoesNotE xist)
219 }) 229 })
220 230
221 Convey(`A tail request for "C" returns 2.`, func () { 231 Convey(`A tail request for "C" returns 2.`, func () {
222 got, err := tail("C") 232 got, err := tail("C")
223 So(err, ShouldBeNil) 233 So(err, ShouldBeNil)
224 So(got, ShouldEqual, "2") 234 So(got, ShouldEqual, "2")
235
236 Convey(`(Cache) A second request also re turns 2.`, func() {
237 got, err := tail("C")
238 So(err, ShouldBeNil)
239 So(got, ShouldEqual, "2")
240 })
241
242 Convey(`(Cache) After "3" is added, a se cond request returns 4.`, func() {
243 So(put("C", 3, "3"), ShouldBeNil )
244
245 got, err := tail("C")
246 So(err, ShouldBeNil)
247 So(got, ShouldEqual, "4")
248 })
225 }) 249 })
226 250
227 Convey(`A tail request for "INVALID" errors NOT FOUND.`, func() { 251 Convey(`A tail request for "INVALID" errors NOT FOUND.`, func() {
228 _, err := tail("INVALID") 252 _, err := tail("INVALID")
229 So(err, ShouldEqual, storage.ErrDoesNotE xist) 253 So(err, ShouldEqual, storage.ErrDoesNotE xist)
230 }) 254 })
231 }) 255 })
232 }) 256 })
233 }) 257 })
234 } 258 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698