add server plugins feature and add zookeeper/etcd/consul registries

This commit is contained in:
smallnest
2017-10-17 16:49:07 +08:00
parent 81380d019b
commit 402c9578fd
16 changed files with 781 additions and 14 deletions

38
serverplugin/etcd_test.go Normal file
View File

@@ -0,0 +1,38 @@
// +build etcd
package serverplugin
import (
"testing"
"time"
metrics "github.com/rcrowley/go-metrics"
"github.com/smallnest/rpcx/server"
)
func TestEtcdRegistry(t *testing.T) {
s := &server.Server{}
r := &EtcdRegisterPlugin{
ServiceAddress: "tcp@127.0.0.1:8972",
EtcdServers: []string{"127.0.0.1:2379"},
BasePath: "/rpcx_test",
Metrics: metrics.NewRegistry(),
Services: make([]string, 1),
UpdateInterval: time.Minute,
}
err := r.Start()
if err != nil {
t.Fatal(err)
}
s.Plugins.Add(r)
s.RegisterName("Arith", new(Arith), "")
go s.Serve("tcp", "127.0.0.1:8972")
defer s.Close()
if len(r.Services) != 1 {
t.Fatal("failed to register services in etcd")
}
}