2015-12-09 19:23:16 +00:00
|
|
|
package selector
|
2015-12-09 00:02:45 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2015-12-09 19:23:16 +00:00
|
|
|
|
2019-01-14 15:27:25 +00:00
|
|
|
"github.com/micro/go-micro/registry/memory"
|
2015-12-09 00:02:45 +00:00
|
|
|
)
|
|
|
|
|
2018-12-29 15:44:51 +00:00
|
|
|
func TestRegistrySelector(t *testing.T) {
|
2015-12-09 00:02:45 +00:00
|
|
|
counts := map[string]int{}
|
|
|
|
|
2019-11-16 02:55:11 -08:00
|
|
|
r := memory.NewRegistry(memory.Services(testData))
|
2019-01-14 15:27:25 +00:00
|
|
|
cache := NewSelector(Registry(r))
|
2015-12-09 00:02:45 +00:00
|
|
|
|
2018-12-29 15:44:51 +00:00
|
|
|
next, err := cache.Select("foo")
|
2015-12-09 00:02:45 +00:00
|
|
|
if err != nil {
|
2018-12-29 15:44:51 +00:00
|
|
|
t.Errorf("Unexpected error calling cache select: %v", err)
|
2015-12-09 00:02:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < 100; i++ {
|
|
|
|
node, err := next()
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Expected node err, got err: %v", err)
|
|
|
|
}
|
|
|
|
counts[node.Id]++
|
|
|
|
}
|
|
|
|
|
2018-12-29 15:44:51 +00:00
|
|
|
t.Logf("Selector Counts %v", counts)
|
2016-05-07 00:04:08 +01:00
|
|
|
}
|