Codebase list golang-github-go-kit-kit / 961b593
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 changed file(s) with 17 addition(s) and 23 deletion(s). Raw diff Collapse all Expand all
99 "github.com/go-kit/kit/sd"
1010 )
1111
12 var _ sd.Instancer = &Instancer{} // API check
12 var _ sd.Instancer = (*Instancer)(nil) // API check
1313
1414 var consulState = []*consul.ServiceEntry{
1515 {
99 "github.com/go-kit/kit/sd"
1010 )
1111
12 var _ sd.Instancer = &Instancer{} // API check
12 var _ sd.Instancer = (*Instancer)(nil) // API check
1313
1414 func TestRefresh(t *testing.T) {
1515 name := "some.service.internal"
1818 f = func(instance string) (endpoint.Endpoint, io.Closer, error) {
1919 return endpoint.Nop, c[instance], nil
2020 }
21 instancer = &mockInstancer{
22 cache: instance.NewCache(),
23 }
21 instancer = &mockInstancer{instance.NewCache()}
2422 )
2523 // set initial state
2624 instancer.Update(sd.Event{Instances: []string{"a", "b"}})
5856 // and therefore does not have access to the endpointer's private members.
5957 }
6058
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 }
7660
7761 type closer chan struct{}
7862
88 "github.com/go-kit/kit/log"
99 "github.com/go-kit/kit/sd"
1010 )
11
12 var _ sd.Instancer = (*Instancer)(nil) // API check
1113
1214 var (
1315 node = &stdetcd.Node{
88 "github.com/go-kit/kit/sd"
99 )
1010
11 var _ sd.Instancer = &Instancer{} // API check
11 var _ sd.Instancer = (*Instancer)(nil) // API check
1212
1313 func TestInstancer(t *testing.T) {
1414 connection := &testConnection{
2121 type Instancer interface {
2222 Register(chan<- Event)
2323 Deregister(chan<- Event)
24 Stop()
2425 }
2526
2627 // FixedInstancer yields a fixed set of instances.
3132
3233 // Deregister implements Instancer.
3334 func (d FixedInstancer) Deregister(ch chan<- Event) {}
35
36 // Stop implements Instancer.
37 func (d FixedInstancer) Stop() {}
4444 return c.state
4545 }
4646
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
4751 // Register implements Instancer.
4852 func (c *Cache) Register(ch chan<- sd.Event) {
4953 c.mtx.Lock()
77 "github.com/go-kit/kit/sd"
88 )
99
10 var _ sd.Instancer = &Cache{} // API check
10 var _ sd.Instancer = (*Cache)(nil) // API check
1111
1212 // The test verifies the following:
1313 // registering causes initial notification of the current state
66 "github.com/go-kit/kit/sd"
77 )
88
9 var _ sd.Instancer = &Instancer{}
9 var _ sd.Instancer = (*Instancer)(nil) // API check
1010
1111 func TestInstancer(t *testing.T) {
1212 client := newFakeClient()