Server also implements ConsulRPC interface

This commit is contained in:
Armon Dadgar 2013-12-19 15:18:25 -08:00
parent 9eb6ab8196
commit b0d6c443da
3 changed files with 23 additions and 0 deletions

View File

@ -12,6 +12,12 @@ import (
"sync"
)
// ConsulRPC is used to provide either a Client or Server,
// both of which can be used to perform an RPC call
type ConsulRPC interface {
RPC(method string, args interface{}, reply interface{}) error
}
// Client is Consul client which uses RPC to communicate with the
// services for service discovery, health checking, and DC forwarding.
type Client struct {

View File

@ -359,3 +359,9 @@ func (s *Server) RemoveFailedNode(node string) error {
func (s *Server) IsLeader() bool {
return s.raft.State() == raft.Leader
}
// RPC is used to make a local RPC call
func (s *Server) RPC(method string, args interface{}, reply interface{}) error {
addr := s.rpcListener.Addr()
return s.connPool.RPC(addr, method, args, reply)
}

View File

@ -184,3 +184,14 @@ func TestServer_Leave(t *testing.T) {
t.Fatalf("should have 1 peer: %v", p1)
}
}
func TestServer_RPC(t *testing.T) {
dir1, s1 := testServer(t)
defer os.RemoveAll(dir1)
defer s1.Shutdown()
var out struct{}
if err := s1.RPC("Status.Ping", struct{}{}, &out); err != nil {
t.Fatalf("err: %v", err)
}
}