| 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 luciConfig "github.com/luci/luci-go/common/config" | 8 luciConfig "github.com/luci/luci-go/common/config" |
| 9 "github.com/luci/luci-go/common/gcloud/gs" | |
| 10 "github.com/luci/luci-go/logdog/api/config/svcconfig" | 9 "github.com/luci/luci-go/logdog/api/config/svcconfig" |
| 11 "github.com/luci/luci-go/logdog/appengine/coordinator" | 10 "github.com/luci/luci-go/logdog/appengine/coordinator" |
| 12 "github.com/luci/luci-go/logdog/appengine/coordinator/config" | 11 "github.com/luci/luci-go/logdog/appengine/coordinator/config" |
| 13 » "github.com/luci/luci-go/logdog/common/storage" | 12 |
| 14 » "github.com/luci/luci-go/logdog/common/storage/caching" | |
| 15 "golang.org/x/net/context" | 13 "golang.org/x/net/context" |
| 16 ) | 14 ) |
| 17 | 15 |
| 18 // Services is a testing stub for a coordinator.Services instance that allows | 16 // Services is a testing stub for a coordinator.Services instance that allows |
| 19 // the user to configure the various services that are returned. | 17 // the user to configure the various services that are returned. |
| 20 type Services struct { | 18 type Services struct { |
| 21 // C, if not nil, will be used to get the return values for Config, over
riding | 19 // C, if not nil, will be used to get the return values for Config, over
riding |
| 22 // local static members. | 20 // local static members. |
| 23 C func() (*config.Config, error) | 21 C func() (*config.Config, error) |
| 24 | 22 |
| 25 // PC, if not nil, will be used to get the return values for ProjectConf
ig, | 23 // PC, if not nil, will be used to get the return values for ProjectConf
ig, |
| 26 // overriding local static members. | 24 // overriding local static members. |
| 27 PC func() (*svcconfig.ProjectConfig, error) | 25 PC func() (*svcconfig.ProjectConfig, error) |
| 28 | 26 |
| 29 // Storage returns an intermediate storage instance for use by this serv
ice. | 27 // Storage returns an intermediate storage instance for use by this serv
ice. |
| 30 // | 28 // |
| 31 // The caller must close the returned instance if successful. | 29 // The caller must close the returned instance if successful. |
| 32 » IS func() (storage.Storage, error) | 30 » // |
| 33 | 31 » // By default, this will return a *BigTableStorage instance bound to the |
| 34 » // GSClient instantiates a Google Storage client. | 32 » // Environment's BigTable instance if the stream is not archived, and an |
| 35 » GS func() (gs.Client, error) | 33 » // *ArchivalStorage instance bound to this Environment's GSClient instan
ce |
| 34 » // if the stream is archived. |
| 35 » ST func(*coordinator.LogStreamState) (coordinator.Storage, error) |
| 36 | 36 |
| 37 // ArchivalPublisher returns an ArchivalPublisher instance. | 37 // ArchivalPublisher returns an ArchivalPublisher instance. |
| 38 AP func() (coordinator.ArchivalPublisher, error) | 38 AP func() (coordinator.ArchivalPublisher, error) |
| 39 | |
| 40 // SC returns a storage caching.Cache instance. If nil, a nil cache valu
e | |
| 41 // will be returned. | |
| 42 SC func() caching.Cache | |
| 43 } | 39 } |
| 44 | 40 |
| 45 var _ coordinator.Services = (*Services)(nil) | 41 var _ coordinator.Services = (*Services)(nil) |
| 46 | 42 |
| 47 // Config implements coordinator.Services. | 43 // Config implements coordinator.Services. |
| 48 func (s *Services) Config(c context.Context) (*config.Config, error) { | 44 func (s *Services) Config(c context.Context) (*config.Config, error) { |
| 49 if s.C != nil { | 45 if s.C != nil { |
| 50 return s.C() | 46 return s.C() |
| 51 } | 47 } |
| 52 return config.Load(c) | 48 return config.Load(c) |
| 53 } | 49 } |
| 54 | 50 |
| 55 // ProjectConfig implements coordinator.Services. | 51 // ProjectConfig implements coordinator.Services. |
| 56 func (s *Services) ProjectConfig(c context.Context, project luciConfig.ProjectNa
me) (*svcconfig.ProjectConfig, error) { | 52 func (s *Services) ProjectConfig(c context.Context, project luciConfig.ProjectNa
me) (*svcconfig.ProjectConfig, error) { |
| 57 if s.PC != nil { | 53 if s.PC != nil { |
| 58 return s.PC() | 54 return s.PC() |
| 59 } | 55 } |
| 60 return config.ProjectConfig(c, project) | 56 return config.ProjectConfig(c, project) |
| 61 } | 57 } |
| 62 | 58 |
| 63 // IntermediateStorage implements coordinator.Services. | 59 // StorageForStream implements coordinator.Services. |
| 64 func (s *Services) IntermediateStorage(c context.Context) (storage.Storage, erro
r) { | 60 func (s *Services) StorageForStream(c context.Context, lst *coordinator.LogStrea
mState) (coordinator.Storage, error) { |
| 65 » if s.IS != nil { | 61 » if s.ST != nil { |
| 66 » » return s.IS() | 62 » » return s.ST(lst) |
| 67 } | 63 } |
| 68 panic("not implemented") | 64 panic("not implemented") |
| 69 } | 65 } |
| 70 | |
| 71 // GSClient implements coordinator.Services. | |
| 72 func (s *Services) GSClient(context.Context) (gs.Client, error) { | |
| 73 if s.GS != nil { | |
| 74 return s.GS() | |
| 75 } | |
| 76 panic("not implemented") | |
| 77 } | |
| 78 | 66 |
| 79 // ArchivalPublisher implements coordinator.Services. | 67 // ArchivalPublisher implements coordinator.Services. |
| 80 func (s *Services) ArchivalPublisher(context.Context) (coordinator.ArchivalPubli
sher, error) { | 68 func (s *Services) ArchivalPublisher(context.Context) (coordinator.ArchivalPubli
sher, error) { |
| 81 if s.AP != nil { | 69 if s.AP != nil { |
| 82 return s.AP() | 70 return s.AP() |
| 83 } | 71 } |
| 84 panic("not implemented") | 72 panic("not implemented") |
| 85 } | 73 } |
| 86 | |
| 87 // StorageCache implements coordinator.Services. | |
| 88 func (s *Services) StorageCache() caching.Cache { | |
| 89 if s.SC != nil { | |
| 90 return s.SC() | |
| 91 } | |
| 92 return nil | |
| 93 } | |
| OLD | NEW |