| OLD | NEW |
| 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 coordinatorTest | 5 package coordinatorTest |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "fmt" |
| 8 "sort" | 9 "sort" |
| 9 "sync" | 10 "sync" |
| 10 | 11 |
| 11 "github.com/luci/luci-go/logdog/api/endpoints/coordinator/services/v1" | 12 "github.com/luci/luci-go/logdog/api/endpoints/coordinator/services/v1" |
| 12 "github.com/luci/luci-go/logdog/appengine/coordinator" | 13 "github.com/luci/luci-go/logdog/appengine/coordinator" |
| 13 "golang.org/x/net/context" | 14 "golang.org/x/net/context" |
| 14 ) | 15 ) |
| 15 | 16 |
| 16 // ArchivalPublisher is a testing implementation of a | 17 // ArchivalPublisher is a testing implementation of a |
| 17 // coordinator.ArchivalPublisher. It records which archival tasks were | 18 // coordinator.ArchivalPublisher. It records which archival tasks were |
| 18 // scheduled and offers accessors to facilitate test assertions. | 19 // scheduled and offers accessors to facilitate test assertions. |
| 19 type ArchivalPublisher struct { | 20 type ArchivalPublisher struct { |
| 20 sync.Mutex | 21 sync.Mutex |
| 21 | 22 |
| 22 // Err, if not nil, is the error returned by Publish. | 23 // Err, if not nil, is the error returned by Publish. |
| 23 Err error | 24 Err error |
| 24 | 25 |
| 26 closed bool |
| 25 tasks []*logdog.ArchiveTask | 27 tasks []*logdog.ArchiveTask |
| 26 archivalIndex uint64 | 28 archivalIndex uint64 |
| 27 } | 29 } |
| 28 | 30 |
| 29 var _ coordinator.ArchivalPublisher = (*ArchivalPublisher)(nil) | 31 var _ coordinator.ArchivalPublisher = (*ArchivalPublisher)(nil) |
| 30 | 32 |
| 33 func (ap *ArchivalPublisher) Close() error { |
| 34 ap.Lock() |
| 35 defer ap.Unlock() |
| 36 |
| 37 if ap.closed { |
| 38 return fmt.Errorf("already closed") |
| 39 } |
| 40 ap.closed = true |
| 41 |
| 42 return nil |
| 43 } |
| 44 |
| 31 // Publish implements coordinator.ArchivalPublisher. | 45 // Publish implements coordinator.ArchivalPublisher. |
| 32 func (ap *ArchivalPublisher) Publish(c context.Context, at *logdog.ArchiveTask)
error { | 46 func (ap *ArchivalPublisher) Publish(c context.Context, at *logdog.ArchiveTask)
error { |
| 33 ap.Lock() | 47 ap.Lock() |
| 34 defer ap.Unlock() | 48 defer ap.Unlock() |
| 35 | 49 |
| 50 if ap.closed { |
| 51 return fmt.Errorf("closed") |
| 52 } |
| 53 |
| 36 if err := ap.Err; err != nil { | 54 if err := ap.Err; err != nil { |
| 37 return err | 55 return err |
| 38 } | 56 } |
| 39 | 57 |
| 40 ap.tasks = append(ap.tasks, at) | 58 ap.tasks = append(ap.tasks, at) |
| 41 return nil | 59 return nil |
| 42 } | 60 } |
| 43 | 61 |
| 44 // NewPublishIndex implements coordinator.ArchivalPublisher. | 62 // NewPublishIndex implements coordinator.ArchivalPublisher. |
| 45 func (ap *ArchivalPublisher) NewPublishIndex() uint64 { | 63 func (ap *ArchivalPublisher) NewPublishIndex() uint64 { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 76 sort.Strings(taskHashes) | 94 sort.Strings(taskHashes) |
| 77 return taskHashes | 95 return taskHashes |
| 78 } | 96 } |
| 79 | 97 |
| 80 // Clear clears recorded tasks. | 98 // Clear clears recorded tasks. |
| 81 func (ap *ArchivalPublisher) Clear() { | 99 func (ap *ArchivalPublisher) Clear() { |
| 82 ap.Lock() | 100 ap.Lock() |
| 83 defer ap.Unlock() | 101 defer ap.Unlock() |
| 84 ap.tasks = nil | 102 ap.tasks = nil |
| 85 } | 103 } |
| OLD | NEW |