sd: add Stop method to Instancer interface
Every implementation (modulo mock/test impls) already provided this
method, and so it makes sense to lift it to the interface definition.
Closes #566.
Peter Bourgon
6 years ago
9 | 9 |
"github.com/go-kit/kit/sd"
|
10 | 10 |
)
|
11 | 11 |
|
12 | |
var _ sd.Instancer = &Instancer{} // API check
|
|
12 |
var _ sd.Instancer = (*Instancer)(nil) // API check
|
13 | 13 |
|
14 | 14 |
var consulState = []*consul.ServiceEntry{
|
15 | 15 |
{
|
9 | 9 |
"github.com/go-kit/kit/sd"
|
10 | 10 |
)
|
11 | 11 |
|
12 | |
var _ sd.Instancer = &Instancer{} // API check
|
|
12 |
var _ sd.Instancer = (*Instancer)(nil) // API check
|
13 | 13 |
|
14 | 14 |
func TestRefresh(t *testing.T) {
|
15 | 15 |
name := "some.service.internal"
|
18 | 18 |
f = func(instance string) (endpoint.Endpoint, io.Closer, error) {
|
19 | 19 |
return endpoint.Nop, c[instance], nil
|
20 | 20 |
}
|
21 | |
instancer = &mockInstancer{
|
22 | |
cache: instance.NewCache(),
|
23 | |
}
|
|
21 |
instancer = &mockInstancer{instance.NewCache()}
|
24 | 22 |
)
|
25 | 23 |
// set initial state
|
26 | 24 |
instancer.Update(sd.Event{Instances: []string{"a", "b"}})
|
|
58 | 56 |
// and therefore does not have access to the endpointer's private members.
|
59 | 57 |
}
|
60 | 58 |
|
61 | |
type mockInstancer struct {
|
62 | |
cache *instance.Cache
|
63 | |
}
|
64 | |
|
65 | |
func (m *mockInstancer) Update(event sd.Event) {
|
66 | |
m.cache.Update(event)
|
67 | |
}
|
68 | |
|
69 | |
func (m *mockInstancer) Register(ch chan<- sd.Event) {
|
70 | |
m.cache.Register(ch)
|
71 | |
}
|
72 | |
|
73 | |
func (m *mockInstancer) Deregister(ch chan<- sd.Event) {
|
74 | |
m.cache.Deregister(ch)
|
75 | |
}
|
|
59 |
type mockInstancer struct{ *instance.Cache }
|
76 | 60 |
|
77 | 61 |
type closer chan struct{}
|
78 | 62 |
|
8 | 8 |
"github.com/go-kit/kit/log"
|
9 | 9 |
"github.com/go-kit/kit/sd"
|
10 | 10 |
)
|
|
11 |
|
|
12 |
var _ sd.Instancer = (*Instancer)(nil) // API check
|
11 | 13 |
|
12 | 14 |
var (
|
13 | 15 |
node = &stdetcd.Node{
|
8 | 8 |
"github.com/go-kit/kit/sd"
|
9 | 9 |
)
|
10 | 10 |
|
11 | |
var _ sd.Instancer = &Instancer{} // API check
|
|
11 |
var _ sd.Instancer = (*Instancer)(nil) // API check
|
12 | 12 |
|
13 | 13 |
func TestInstancer(t *testing.T) {
|
14 | 14 |
connection := &testConnection{
|
21 | 21 |
type Instancer interface {
|
22 | 22 |
Register(chan<- Event)
|
23 | 23 |
Deregister(chan<- Event)
|
|
24 |
Stop()
|
24 | 25 |
}
|
25 | 26 |
|
26 | 27 |
// FixedInstancer yields a fixed set of instances.
|
|
31 | 32 |
|
32 | 33 |
// Deregister implements Instancer.
|
33 | 34 |
func (d FixedInstancer) Deregister(ch chan<- Event) {}
|
|
35 |
|
|
36 |
// Stop implements Instancer.
|
|
37 |
func (d FixedInstancer) Stop() {}
|
44 | 44 |
return c.state
|
45 | 45 |
}
|
46 | 46 |
|
|
47 |
// Stop implements Instancer. Since the cache is just a plain-old store of data,
|
|
48 |
// Stop is a no-op.
|
|
49 |
func (c *Cache) Stop() {}
|
|
50 |
|
47 | 51 |
// Register implements Instancer.
|
48 | 52 |
func (c *Cache) Register(ch chan<- sd.Event) {
|
49 | 53 |
c.mtx.Lock()
|
7 | 7 |
"github.com/go-kit/kit/sd"
|
8 | 8 |
)
|
9 | 9 |
|
10 | |
var _ sd.Instancer = &Cache{} // API check
|
|
10 |
var _ sd.Instancer = (*Cache)(nil) // API check
|
11 | 11 |
|
12 | 12 |
// The test verifies the following:
|
13 | 13 |
// registering causes initial notification of the current state
|
6 | 6 |
"github.com/go-kit/kit/sd"
|
7 | 7 |
)
|
8 | 8 |
|
9 | |
var _ sd.Instancer = &Instancer{}
|
|
9 |
var _ sd.Instancer = (*Instancer)(nil) // API check
|
10 | 10 |
|
11 | 11 |
func TestInstancer(t *testing.T) {
|
12 | 12 |
client := newFakeClient()
|