Package list golang-github-go-kit-kit / e9af46a
Merge pull request #583 from go-kit/instancer-stop sd: add Stop method to Instancer interface Peter Bourgon authored 4 years ago GitHub committed 4 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"}})
6866 // and therefore does not have access to the endpointer's private members.
6967 }
7068
71 type mockInstancer struct {
72 cache *instance.Cache
73 }
74
75 func (m *mockInstancer) Update(event sd.Event) {
76 m.cache.Update(event)
77 }
78
79 func (m *mockInstancer) Register(ch chan<- sd.Event) {
80 m.cache.Register(ch)
81 }
82
83 func (m *mockInstancer) Deregister(ch chan<- sd.Event) {
84 m.cache.Deregister(ch)
85 }
69 type mockInstancer struct{ *instance.Cache }
8670
8771 type closer chan struct{}
8872
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()