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

Side by Side Diff: server/internal/logdog/collector/utils_test.go

Issue 1838803002: LogDog: BigTable batching schema. (Closed) Base URL: https://github.com/luci/luci-go@recordio-split
Patch Set: Minor comments and quality of code tweaks. Created 4 years, 8 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 collector 5 package collector
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "errors" 9 "errors"
10 "fmt" 10 "fmt"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 } 117 }
118 return int(sp.TerminalIndex), true 118 return int(sp.TerminalIndex), true
119 } 119 }
120 120
121 // testStorage is a testing storage instance that returns errors. 121 // testStorage is a testing storage instance that returns errors.
122 type testStorage struct { 122 type testStorage struct {
123 storage.Storage 123 storage.Storage
124 err func() error 124 err func() error
125 } 125 }
126 126
127 func (s *testStorage) Put(r *storage.PutRequest) error { 127 func (s *testStorage) Put(r storage.PutRequest) error {
128 if s.err != nil { 128 if s.err != nil {
129 if err := s.err(); err != nil { 129 if err := s.err(); err != nil {
130 return err 130 return err
131 } 131 }
132 } 132 }
133 return s.Storage.Put(r) 133 return s.Storage.Put(r)
134 } 134 }
135 135
136 // bundleBuilder is a set of utility functions to help test cases construct 136 // bundleBuilder is a set of utility functions to help test cases construct
137 // specific logpb.ButlerLogBundle layouts. 137 // specific logpb.ButlerLogBundle layouts.
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 }, 202 },
203 }, 203 },
204 }, 204 },
205 }, 205 },
206 } 206 }
207 } 207 }
208 208
209 func (b *bundleBuilder) bundle() []byte { 209 func (b *bundleBuilder) bundle() []byte {
210 bytes := b.bundleWithEntries(b.entries...) 210 bytes := b.bundleWithEntries(b.entries...)
211 b.entries = nil 211 b.entries = nil
212
212 return bytes 213 return bytes
213 } 214 }
214 215
215 func (b *bundleBuilder) bundleWithEntries(e ...*logpb.ButlerLogBundle_Entry) []b yte { 216 func (b *bundleBuilder) bundleWithEntries(e ...*logpb.ButlerLogBundle_Entry) []b yte {
216 bundle := logpb.ButlerLogBundle{ 217 bundle := logpb.ButlerLogBundle{
217 Source: "test stream", 218 Source: "test stream",
218 Timestamp: google.NewTimestamp(clock.Now(b)), 219 Timestamp: google.NewTimestamp(clock.Now(b)),
219 Entries: e, 220 Entries: e,
220 } 221 }
221 222
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 st := actual.(storage.Storage) 277 st := actual.(storage.Storage)
277 name := expected[0].(string) 278 name := expected[0].(string)
278 279
279 // Load all entries for this stream. 280 // Load all entries for this stream.
280 req := storage.GetRequest{ 281 req := storage.GetRequest{
281 Path: types.StreamPath(name), 282 Path: types.StreamPath(name),
282 } 283 }
283 284
284 entries := make(map[int]*logpb.LogEntry) 285 entries := make(map[int]*logpb.LogEntry)
285 var ierr error 286 var ierr error
286 » err := st.Get(&req, func(idx types.MessageIndex, d []byte) bool { 287 » err := st.Get(req, func(idx types.MessageIndex, d []byte) bool {
287 le := logpb.LogEntry{} 288 le := logpb.LogEntry{}
288 if ierr = proto.Unmarshal(d, &le); ierr != nil { 289 if ierr = proto.Unmarshal(d, &le); ierr != nil {
289 return false 290 return false
290 } 291 }
291 entries[int(idx)] = &le 292 entries[int(idx)] = &le
292 return true 293 return true
293 }) 294 })
294 if ierr != nil { 295 if ierr != nil {
295 err = ierr 296 err = ierr
296 } 297 }
(...skipping 12 matching lines...) Expand all
309 return fmt.Sprintf("*%d", i) 310 return fmt.Sprintf("*%d", i)
310 } 311 }
311 return "" 312 return ""
312 } 313 }
313 314
314 var failed []string 315 var failed []string
315 for _, exp := range expected[1:] { 316 for _, exp := range expected[1:] {
316 switch e := exp.(type) { 317 switch e := exp.(type) {
317 case int: 318 case int:
318 if err := assertLogEntry(e); err != "" { 319 if err := assertLogEntry(e); err != "" {
319 » » » » failed = append(failed, err) 320 » » » » failed = append(failed, fmt.Sprintf("missing{%s} ", err))
320 } 321 }
321 322
322 case indexRange: 323 case indexRange:
323 var errs []string 324 var errs []string
324 for i := e.start; i <= e.end; i++ { 325 for i := e.start; i <= e.end; i++ {
325 if err := assertLogEntry(i); err != "" { 326 if err := assertLogEntry(i); err != "" {
326 errs = append(errs, err) 327 errs = append(errs, err)
327 } 328 }
328 } 329 }
329 if len(errs) > 0 { 330 if len(errs) > 0 {
(...skipping 18 matching lines...) Expand all
348 extra[i] = fmt.Sprintf("%d", idx) 349 extra[i] = fmt.Sprintf("%d", idx)
349 } 350 }
350 failed = append(failed, fmt.Sprintf("extra{%s}", strings.Join(ex tra, ","))) 351 failed = append(failed, fmt.Sprintf("extra{%s}", strings.Join(ex tra, ",")))
351 } 352 }
352 353
353 if len(failed) > 0 { 354 if len(failed) > 0 {
354 return strings.Join(failed, ", ") 355 return strings.Join(failed, ", ")
355 } 356 }
356 return "" 357 return ""
357 } 358 }
OLDNEW
« no previous file with comments | « server/internal/logdog/collector/collector_test.go ('k') | server/internal/logdog/service/service.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698