mirror of
https://github.com/go-kit/kit.git
synced 2025-07-17 01:12:38 +02:00
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.
This commit is contained in:
@ -10,7 +10,7 @@ import (
|
|||||||
"github.com/go-kit/kit/sd"
|
"github.com/go-kit/kit/sd"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ sd.Instancer = &Instancer{} // API check
|
var _ sd.Instancer = (*Instancer)(nil) // API check
|
||||||
|
|
||||||
var consulState = []*consul.ServiceEntry{
|
var consulState = []*consul.ServiceEntry{
|
||||||
{
|
{
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
"github.com/go-kit/kit/sd"
|
"github.com/go-kit/kit/sd"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ sd.Instancer = &Instancer{} // API check
|
var _ sd.Instancer = (*Instancer)(nil) // API check
|
||||||
|
|
||||||
func TestRefresh(t *testing.T) {
|
func TestRefresh(t *testing.T) {
|
||||||
name := "some.service.internal"
|
name := "some.service.internal"
|
||||||
|
@ -19,9 +19,7 @@ func TestDefaultEndpointer(t *testing.T) {
|
|||||||
f = func(instance string) (endpoint.Endpoint, io.Closer, error) {
|
f = func(instance string) (endpoint.Endpoint, io.Closer, error) {
|
||||||
return endpoint.Nop, c[instance], nil
|
return endpoint.Nop, c[instance], nil
|
||||||
}
|
}
|
||||||
instancer = &mockInstancer{
|
instancer = &mockInstancer{instance.NewCache()}
|
||||||
cache: instance.NewCache(),
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
// set initial state
|
// set initial state
|
||||||
instancer.Update(sd.Event{Instances: []string{"a", "b"}})
|
instancer.Update(sd.Event{Instances: []string{"a", "b"}})
|
||||||
@ -59,21 +57,7 @@ func TestDefaultEndpointer(t *testing.T) {
|
|||||||
// and therefore does not have access to the endpointer's private members.
|
// and therefore does not have access to the endpointer's private members.
|
||||||
}
|
}
|
||||||
|
|
||||||
type mockInstancer struct {
|
type mockInstancer struct{ *instance.Cache }
|
||||||
cache *instance.Cache
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *mockInstancer) Update(event sd.Event) {
|
|
||||||
m.cache.Update(event)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *mockInstancer) Register(ch chan<- sd.Event) {
|
|
||||||
m.cache.Register(ch)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *mockInstancer) Deregister(ch chan<- sd.Event) {
|
|
||||||
m.cache.Deregister(ch)
|
|
||||||
}
|
|
||||||
|
|
||||||
type closer chan struct{}
|
type closer chan struct{}
|
||||||
|
|
||||||
|
@ -10,6 +10,8 @@ import (
|
|||||||
"github.com/go-kit/kit/sd"
|
"github.com/go-kit/kit/sd"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var _ sd.Instancer = (*Instancer)(nil) // API check
|
||||||
|
|
||||||
var (
|
var (
|
||||||
node = &stdetcd.Node{
|
node = &stdetcd.Node{
|
||||||
Key: "/foo",
|
Key: "/foo",
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
"github.com/go-kit/kit/sd"
|
"github.com/go-kit/kit/sd"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ sd.Instancer = &Instancer{} // API check
|
var _ sd.Instancer = (*Instancer)(nil) // API check
|
||||||
|
|
||||||
func TestInstancer(t *testing.T) {
|
func TestInstancer(t *testing.T) {
|
||||||
connection := &testConnection{
|
connection := &testConnection{
|
||||||
|
@ -22,6 +22,7 @@ type Event struct {
|
|||||||
type Instancer interface {
|
type Instancer interface {
|
||||||
Register(chan<- Event)
|
Register(chan<- Event)
|
||||||
Deregister(chan<- Event)
|
Deregister(chan<- Event)
|
||||||
|
Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
// FixedInstancer yields a fixed set of instances.
|
// FixedInstancer yields a fixed set of instances.
|
||||||
@ -32,3 +33,6 @@ func (d FixedInstancer) Register(ch chan<- Event) { ch <- Event{Instances: d} }
|
|||||||
|
|
||||||
// Deregister implements Instancer.
|
// Deregister implements Instancer.
|
||||||
func (d FixedInstancer) Deregister(ch chan<- Event) {}
|
func (d FixedInstancer) Deregister(ch chan<- Event) {}
|
||||||
|
|
||||||
|
// Stop implements Instancer.
|
||||||
|
func (d FixedInstancer) Stop() {}
|
||||||
|
@ -45,6 +45,10 @@ func (c *Cache) State() sd.Event {
|
|||||||
return c.state
|
return c.state
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stop implements Instancer. Since the cache is just a plain-old store of data,
|
||||||
|
// Stop is a no-op.
|
||||||
|
func (c *Cache) Stop() {}
|
||||||
|
|
||||||
// Register implements Instancer.
|
// Register implements Instancer.
|
||||||
func (c *Cache) Register(ch chan<- sd.Event) {
|
func (c *Cache) Register(ch chan<- sd.Event) {
|
||||||
c.mtx.Lock()
|
c.mtx.Lock()
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
"github.com/go-kit/kit/sd"
|
"github.com/go-kit/kit/sd"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ sd.Instancer = &Cache{} // API check
|
var _ sd.Instancer = (*Cache)(nil) // API check
|
||||||
|
|
||||||
// The test verifies the following:
|
// The test verifies the following:
|
||||||
// registering causes initial notification of the current state
|
// registering causes initial notification of the current state
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"github.com/go-kit/kit/sd"
|
"github.com/go-kit/kit/sd"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ sd.Instancer = &Instancer{}
|
var _ sd.Instancer = (*Instancer)(nil) // API check
|
||||||
|
|
||||||
func TestInstancer(t *testing.T) {
|
func TestInstancer(t *testing.T) {
|
||||||
client := newFakeClient()
|
client := newFakeClient()
|
||||||
|
Reference in New Issue
Block a user