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

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

Issue 2435113002: LogDog: Add Storage-layer data caching. (Closed)
Patch Set: Fix byteLimit bug. Created 4 years, 1 month 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
« no previous file with comments | « logdog/common/storage/archive/storage.go ('k') | logdog/common/storage/bigtable/bigtable.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The LUCI Authors. All rights reserved. 1 // Copyright 2016 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 archive 5 package archive
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "fmt" 9 "fmt"
10 "io" 10 "io"
11 "io/ioutil" 11 "io/ioutil"
12 "testing" 12 "testing"
13 13
14 "github.com/luci/luci-go/common/errors" 14 "github.com/luci/luci-go/common/errors"
15 "github.com/luci/luci-go/common/gcloud/gs" 15 "github.com/luci/luci-go/common/gcloud/gs"
16 "github.com/luci/luci-go/logdog/api/logpb" 16 "github.com/luci/luci-go/logdog/api/logpb"
17 "github.com/luci/luci-go/logdog/common/archive" 17 "github.com/luci/luci-go/logdog/common/archive"
18 "github.com/luci/luci-go/logdog/common/renderer" 18 "github.com/luci/luci-go/logdog/common/renderer"
19 "github.com/luci/luci-go/logdog/common/storage" 19 "github.com/luci/luci-go/logdog/common/storage"
20 "github.com/luci/luci-go/logdog/common/storage/memory"
20 21
21 cloudStorage "cloud.google.com/go/storage" 22 cloudStorage "cloud.google.com/go/storage"
22 "github.com/golang/protobuf/proto" 23 "github.com/golang/protobuf/proto"
23 "golang.org/x/net/context" 24 "golang.org/x/net/context"
24 25
25 . "github.com/luci/luci-go/common/testing/assertions" 26 . "github.com/luci/luci-go/common/testing/assertions"
26 . "github.com/smartystreets/goconvey/convey" 27 . "github.com/smartystreets/goconvey/convey"
27 ) 28 )
28 29
29 const ( 30 const (
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 } 307 }
307 }) 308 })
308 } 309 }
309 }) 310 })
310 311
311 // Individual error test cases. 312 // Individual error test cases.
312 for _, tc := range []struct { 313 for _, tc := range []struct {
313 title string 314 title string
314 fn func() error 315 fn func() error
315 }{ 316 }{
316 » » » {"Get", func() error { return st.Get(storage.GetRequest{ }, nil) }}, 317 » » » {"Get", func() error { return st.Get(storage.GetRequest{ }, func(*storage.Entry) bool { return true }) }},
317 {"Tail", func() (err error) { 318 {"Tail", func() (err error) {
318 _, err = st.Tail("", "") 319 _, err = st.Tail("", "")
319 return 320 return
320 }}, 321 }},
321 } { 322 } {
322 » » » Convey(fmt.Sprintf("Error case: %q", tc.title), func() { 323 » » » Convey(fmt.Sprintf("Testing retrieval: %q", tc.title), f unc() {
323 Convey(`With missing log stream returns ErrDoesN otExist.`, func() { 324 Convey(`With missing log stream returns ErrDoesN otExist.`, func() {
324 stImpl.streamPath = "does-not-exist" 325 stImpl.streamPath = "does-not-exist"
325 326
326 So(st.Get(storage.GetRequest{}, nil), Sh ouldEqual, storage.ErrDoesNotExist) 327 So(st.Get(storage.GetRequest{}, nil), Sh ouldEqual, storage.ErrDoesNotExist)
327 }) 328 })
328 329
329 Convey(`With a client error returns that error.` , func() { 330 Convey(`With a client error returns that error.` , func() {
330 client.err = errors.New("test error") 331 client.err = errors.New("test error")
331 332
332 So(errors.Unwrap(tc.fn()), ShouldEqual, client.err) 333 So(errors.Unwrap(tc.fn()), ShouldEqual, client.err)
(...skipping 15 matching lines...) Expand all
348 client.index = []byte{0x00} 349 client.index = []byte{0x00}
349 350
350 So(tc.fn(), ShouldErrLike, "failed to un marshal index") 351 So(tc.fn(), ShouldErrLike, "failed to un marshal index")
351 }) 352 })
352 353
353 Convey(`With junk stream data returns an error.` , func() { 354 Convey(`With junk stream data returns an error.` , func() {
354 client.stream = []byte{0x00, 0x01, 0xff} 355 client.stream = []byte{0x00, 0x01, 0xff}
355 356
356 So(tc.fn(), ShouldErrLike, "failed to un marshal") 357 So(tc.fn(), ShouldErrLike, "failed to un marshal")
357 }) 358 })
359
360 Convey(`With data entries and a cache, only load s the index once.`, func() {
361 var cache memory.Cache
362 stImpl.Cache = &cache
363
364 gen.generate("foo", "bar", "baz", "qux", "quux")
365 client.load(&gen)
366
367 // Assert that an attempted load will fa il with an error. This is so
368 // we don't accidentally test something that doesn't follow the path
369 // we're intending to follow.
370 client.indexErr = errors.New("not using a cache")
371 So(errors.Unwrap(tc.fn()), ShouldEqual, client.indexErr)
372
373 for i := 0; i < 10; i++ {
374 if i == 0 {
375 // First time successful ly reads the index.
376 client.indexErr = nil
377 } else {
378 // Subsequent attempts t o load the index will result in an error.
379 // This ensures that if they are successful, it's because we're
380 // hitting the cache.
381 client.indexErr = errors .New("not using a cache")
382 }
383
384 So(tc.fn(), ShouldBeNil)
385 }
386 })
358 }) 387 })
359 } 388 }
360 389
361 Convey(`Tail with no log entries returns ErrDoesNotExist.`, func () { 390 Convey(`Tail with no log entries returns ErrDoesNotExist.`, func () {
362 client.load(&gen) 391 client.load(&gen)
363 392
364 _, err := st.Tail("", "") 393 _, err := st.Tail("", "")
365 So(err, ShouldEqual, storage.ErrDoesNotExist) 394 So(err, ShouldEqual, storage.ErrDoesNotExist)
366 }) 395 })
367 }) 396 })
368 } 397 }
OLDNEW
« no previous file with comments | « logdog/common/storage/archive/storage.go ('k') | logdog/common/storage/bigtable/bigtable.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698