2 | 2 |
package eureka
|
3 | 3 |
|
4 | 4 |
import (
|
5 | |
"io"
|
6 | 5 |
"os"
|
7 | 6 |
"testing"
|
8 | 7 |
"time"
|
9 | 8 |
|
10 | 9 |
"github.com/hudl/fargo"
|
11 | 10 |
|
12 | |
"github.com/go-kit/kit/endpoint"
|
13 | 11 |
"github.com/go-kit/kit/log"
|
14 | |
"github.com/go-kit/kit/sd"
|
15 | 12 |
)
|
16 | 13 |
|
17 | 14 |
// Package sd/eureka provides a wrapper around the Netflix Eureka service
|
|
49 | 46 |
// This should be enough time for the Eureka server response cache to update.
|
50 | 47 |
time.Sleep(time.Second)
|
51 | 48 |
|
52 | |
// Build a Eureka subscriber.
|
53 | |
factory := func(instance string) (endpoint.Endpoint, io.Closer, error) {
|
54 | |
t.Logf("factory invoked for %q", instance)
|
55 | |
return endpoint.Nop, nil, nil
|
56 | |
}
|
|
49 |
// Build a Eureka instancer.
|
57 | 50 |
instancer := NewInstancer(
|
58 | 51 |
&fargoConnection,
|
59 | 52 |
appNameTest,
|
60 | 53 |
log.With(logger, "component", "instancer"),
|
61 | 54 |
)
|
62 | 55 |
defer instancer.Stop()
|
63 | |
endpointer := sd.NewEndpointer(instancer, factory, log.With(logger, "component", "endpointer"))
|
64 | 56 |
|
65 | |
// We should have one endpoint immediately after subscriber instantiation.
|
66 | |
endpoints, err := endpointer.Endpoints()
|
67 | |
if err != nil {
|
68 | |
t.Error(err)
|
|
57 |
// We should have one instance immediately after subscriber instantiation.
|
|
58 |
state := instancer.State()
|
|
59 |
if state.Err != nil {
|
|
60 |
t.Error(state.Err)
|
69 | 61 |
}
|
70 | |
if want, have := 1, len(endpoints); want != have {
|
|
62 |
if want, have := 1, len(state.Instances); want != have {
|
71 | 63 |
t.Errorf("want %d, have %d", want, have)
|
72 | 64 |
}
|
73 | 65 |
|
|
80 | 72 |
// configured with the properties mentioned in the function comments.
|
81 | 73 |
time.Sleep(2 * time.Second)
|
82 | 74 |
|
83 | |
// Now we should have two endpoints.
|
84 | |
endpoints, err = endpointer.Endpoints()
|
85 | |
if err != nil {
|
86 | |
t.Error(err)
|
|
75 |
// Now we should have two instances.
|
|
76 |
state = instancer.State()
|
|
77 |
if state.Err != nil {
|
|
78 |
t.Error(state.Err)
|
87 | 79 |
}
|
88 | |
if want, have := 2, len(endpoints); want != have {
|
|
80 |
if want, have := 2, len(state.Instances); want != have {
|
89 | 81 |
t.Errorf("want %d, have %d", want, have)
|
90 | 82 |
}
|
91 | 83 |
|