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

Unified Diff: appengine/logdog/coordinator/coordinatorTest/archival.go

Issue 1863973002: LogDog: Update to archival V2. (Closed) Base URL: https://github.com/luci/luci-go@grpcutil-errors
Patch Set: Fix proto comment. 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 side-by-side diff with in-line comments
Download patch
Index: appengine/logdog/coordinator/coordinatorTest/archival.go
diff --git a/appengine/logdog/coordinator/coordinatorTest/archival.go b/appengine/logdog/coordinator/coordinatorTest/archival.go
new file mode 100644
index 0000000000000000000000000000000000000000..532a8c0930e97fa3670fe18d2de431a4d665b884
--- /dev/null
+++ b/appengine/logdog/coordinator/coordinatorTest/archival.go
@@ -0,0 +1,69 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package coordinatorTest
+
+import (
+ "sort"
+ "sync"
+
+ "github.com/luci/luci-go/appengine/logdog/coordinator"
+ "github.com/luci/luci-go/common/api/logdog_coordinator/services/v1"
+ "github.com/luci/luci-go/common/logdog/types"
+ "golang.org/x/net/context"
+)
+
+// ArchivalPublisher is a testing implementation of a
+// coordinator.ArchivalPublisher. It records which archival tasks were
+// scheduled and offers accessors to facilitate test assertions.
+type ArchivalPublisher struct {
+ sync.Mutex
+
+ // Err, if not nil, is the error returned by Publish.
+ Err error
+
+ tasks []*logdog.ArchiveTask
+}
+
+var _ coordinator.ArchivalPublisher = (*ArchivalPublisher)(nil)
+
+// Publish implements coordinator.ArchivalPublisher.
+func (ap *ArchivalPublisher) Publish(c context.Context, at *logdog.ArchiveTask) error {
+ ap.Lock()
+ defer ap.Unlock()
+
+ if err := ap.Err; err != nil {
+ return err
+ }
+
+ ap.tasks = append(ap.tasks, at)
+ return nil
+}
+
+// Tasks returns the dispatched archival tasks in the order in which they were
+// dispatched.
+func (ap *ArchivalPublisher) Tasks() []*logdog.ArchiveTask {
+ ap.Lock()
+ defer ap.Unlock()
+
+ taskCopy := make([]*logdog.ArchiveTask, len(ap.tasks))
+ for i, at := range ap.tasks {
+ taskCopy[i] = at
+ }
+ return taskCopy
+}
+
+// StreamNames returns a sorted list of the "name" component of streams that
+// have had archival tasks submitted.
+func (ap *ArchivalPublisher) StreamNames() []string {
+ tasks := ap.Tasks()
+
+ taskStreams := make([]string, len(tasks))
+ for i, at := range tasks {
+ _, name := types.StreamPath(at.Path).Split()
+ taskStreams[i] = string(name)
+ }
+ sort.Strings(taskStreams)
+ return taskStreams
+}
« no previous file with comments | « appengine/logdog/coordinator/config/config.go ('k') | appengine/logdog/coordinator/coordinatorTest/config.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698