Merge pull request #583 from go-kit/instancer-stop
sd: add Stop method to Instancer interface
Peter Bourgon authored 6 years ago
GitHub committed 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"}})
|
|
68 | 66 |
// and therefore does not have access to the endpointer's private members.
|
69 | 67 |
}
|
70 | 68 |
|
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 }
|
86 | 70 |
|
87 | 71 |
type closer chan struct{}
|
88 | 72 |
|
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()
|