| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package coordinatorTest |
| 6 |
| 7 import ( |
| 8 "sort" |
| 9 "sync" |
| 10 |
| 11 "github.com/luci/luci-go/appengine/logdog/coordinator" |
| 12 "github.com/luci/luci-go/common/api/logdog_coordinator/services/v1" |
| 13 "github.com/luci/luci-go/common/logdog/types" |
| 14 "golang.org/x/net/context" |
| 15 ) |
| 16 |
| 17 // ArchivalPublisher is a testing implementation of a |
| 18 // coordinator.ArchivalPublisher. It records which archival tasks were |
| 19 // scheduled and offers accessors to facilitate test assertions. |
| 20 type ArchivalPublisher struct { |
| 21 sync.Mutex |
| 22 |
| 23 // Err, if not nil, is the error returned by Publish. |
| 24 Err error |
| 25 |
| 26 tasks []*logdog.ArchiveTask |
| 27 } |
| 28 |
| 29 var _ coordinator.ArchivalPublisher = (*ArchivalPublisher)(nil) |
| 30 |
| 31 // Publish implements coordinator.ArchivalPublisher. |
| 32 func (ap *ArchivalPublisher) Publish(c context.Context, at *logdog.ArchiveTask)
error { |
| 33 ap.Lock() |
| 34 defer ap.Unlock() |
| 35 |
| 36 if err := ap.Err; err != nil { |
| 37 return err |
| 38 } |
| 39 |
| 40 ap.tasks = append(ap.tasks, at) |
| 41 return nil |
| 42 } |
| 43 |
| 44 // Tasks returns the dispatched archival tasks in the order in which they were |
| 45 // dispatched. |
| 46 func (ap *ArchivalPublisher) Tasks() []*logdog.ArchiveTask { |
| 47 ap.Lock() |
| 48 defer ap.Unlock() |
| 49 |
| 50 taskCopy := make([]*logdog.ArchiveTask, len(ap.tasks)) |
| 51 for i, at := range ap.tasks { |
| 52 taskCopy[i] = at |
| 53 } |
| 54 return taskCopy |
| 55 } |
| 56 |
| 57 // StreamNames returns a sorted list of the "name" component of streams that |
| 58 // have had archival tasks submitted. |
| 59 func (ap *ArchivalPublisher) StreamNames() []string { |
| 60 tasks := ap.Tasks() |
| 61 |
| 62 taskStreams := make([]string, len(tasks)) |
| 63 for i, at := range tasks { |
| 64 _, name := types.StreamPath(at.Path).Split() |
| 65 taskStreams[i] = string(name) |
| 66 } |
| 67 sort.Strings(taskStreams) |
| 68 return taskStreams |
| 69 } |
| OLD | NEW |