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

Side by Side Diff: logdog/common/archive/archive_test.go

Issue 2435883002: LogDog: Fix archival Get/Tail implementations. (Closed)
Patch Set: LogDog: Fix archival Get/Tail implementations. Created 4 years, 2 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 archive 5 package archive
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "fmt" 9 "fmt"
10 "io" 10 "io"
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 cr := iotools.CountingReader{ 146 cr := iotools.CountingReader{
147 Reader: logB, 147 Reader: logB,
148 } 148 }
149 csize := uint64(0) 149 csize := uint64(0)
150 r := recordio.NewReader(&cr, 1024*1024) 150 r := recordio.NewReader(&cr, 1024*1024)
151 d, err := r.ReadFrameAll() 151 d, err := r.ReadFrameAll()
152 if err != nil { 152 if err != nil {
153 return "failed to skip descriptor frame" 153 return "failed to skip descriptor frame"
154 } 154 }
155 for { 155 for {
156 » » offset := cr.Count() 156 » » offset := cr.Count
157 d, err = r.ReadFrameAll() 157 d, err = r.ReadFrameAll()
158 if err == io.EOF { 158 if err == io.EOF {
159 break 159 break
160 } 160 }
161 if err != nil { 161 if err != nil {
162 return fmt.Sprintf("failed to read entry #%d: %v", len(e ntries), err) 162 return fmt.Sprintf("failed to read entry #%d: %v", len(e ntries), err)
163 } 163 }
164 164
165 le := logpb.LogEntry{} 165 le := logpb.LogEntry{}
166 if err := proto.Unmarshal(d, &le); err != nil { 166 if err := proto.Unmarshal(d, &le); err != nil {
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 }) 367 })
368 }) 368 })
369 369
370 Convey(`When building sparse index`, func() { 370 Convey(`When building sparse index`, func() {
371 ts.add(0, 1, 2, 3, 4, 5) 371 ts.add(0, 1, 2, 3, 4, 5)
372 372
373 Convey(`Can build an index for every 3 StreamIndex.`, fu nc() { 373 Convey(`Can build an index for every 3 StreamIndex.`, fu nc() {
374 m.StreamIndexRange = 3 374 m.StreamIndexRange = 3
375 So(Archive(m), ShouldBeNil) 375 So(Archive(m), ShouldBeNil)
376 376
377 » » » » So(&indexB, ic.shouldContainIndexFor, desc, &log B, 0, 3) 377 » » » » So(&indexB, ic.shouldContainIndexFor, desc, &log B, 0, 3, 5)
378 So(indexParams(indexB.Bytes()), ShouldResemble, logpb.LogIndex{ 378 So(indexParams(indexB.Bytes()), ShouldResemble, logpb.LogIndex{
379 Desc: desc, 379 Desc: desc,
380 LastPrefixIndex: 10, 380 LastPrefixIndex: 10,
381 LastStreamIndex: 5, 381 LastStreamIndex: 5,
382 LogEntryCount: 6, 382 LogEntryCount: 6,
383 }) 383 })
384 }) 384 })
385 385
386 Convey(`Can build an index for every 3 PrefixIndex.`, fu nc() { 386 Convey(`Can build an index for every 3 PrefixIndex.`, fu nc() {
387 m.PrefixIndexRange = 3 387 m.PrefixIndexRange = 3
388 So(Archive(m), ShouldBeNil) 388 So(Archive(m), ShouldBeNil)
389 389
390 // Note that in our generated logs, PrefixIndex = 2*StreamIndex. 390 // Note that in our generated logs, PrefixIndex = 2*StreamIndex.
391 » » » » So(&indexB, ic.shouldContainIndexFor, desc, &log B, 0, 2, 4) 391 » » » » So(&indexB, ic.shouldContainIndexFor, desc, &log B, 0, 2, 4, 5)
392 So(indexParams(indexB.Bytes()), ShouldResemble, logpb.LogIndex{ 392 So(indexParams(indexB.Bytes()), ShouldResemble, logpb.LogIndex{
393 Desc: desc, 393 Desc: desc,
394 LastPrefixIndex: 10, 394 LastPrefixIndex: 10,
395 LastStreamIndex: 5, 395 LastStreamIndex: 5,
396 LogEntryCount: 6, 396 LogEntryCount: 6,
397 }) 397 })
398 }) 398 })
399 399
400 Convey(`Can build an index for every 13 bytes.`, func() { 400 Convey(`Can build an index for every 13 bytes.`, func() {
401 ic.fixedSize = 5 401 ic.fixedSize = 5
402 m.ByteRange = 13 402 m.ByteRange = 13
403 m.sizeFunc = func(pb proto.Message) int { 403 m.sizeFunc = func(pb proto.Message) int {
404 // Stub all LogEntry to be 5 bytes. 404 // Stub all LogEntry to be 5 bytes.
405 return 5 405 return 5
406 } 406 }
407 So(Archive(m), ShouldBeNil) 407 So(Archive(m), ShouldBeNil)
408 408
409 So(&indexB, ic.shouldContainIndexFor, desc, &log B, 0, 2, 5) 409 So(&indexB, ic.shouldContainIndexFor, desc, &log B, 0, 2, 5)
410 So(indexParams(indexB.Bytes()), ShouldResemble, logpb.LogIndex{ 410 So(indexParams(indexB.Bytes()), ShouldResemble, logpb.LogIndex{
411 Desc: desc, 411 Desc: desc,
412 LastPrefixIndex: 10, 412 LastPrefixIndex: 10,
413 LastStreamIndex: 5, 413 LastStreamIndex: 5,
414 LogEntryCount: 6, 414 LogEntryCount: 6,
415 }) 415 })
416 }) 416 })
417 }) 417 })
418 }) 418 })
419 } 419 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698