Rename GetNumServers to NumServers()

Matches the style of the rest of the repo
This commit is contained in:
Sean Chittenden 2016-02-24 22:09:49 -08:00
parent 9de9cf90f1
commit d5f72e8c07
4 changed files with 13 additions and 13 deletions

View File

@ -340,7 +340,7 @@ func (c *Client) RPC(method string, args interface{}, reply interface{}) error {
// Stats is used to return statistics for debugging and insight // Stats is used to return statistics for debugging and insight
// for various sub-systems // for various sub-systems
func (c *Client) Stats() map[string]map[string]string { func (c *Client) Stats() map[string]map[string]string {
numServers := c.serverMgr.GetNumServers() numServers := c.serverMgr.NumServers()
toString := func(v uint64) string { toString := func(v uint64) string {
return strconv.FormatUint(v, 10) return strconv.FormatUint(v, 10)

View File

@ -84,7 +84,7 @@ func TestClient_JoinLAN(t *testing.T) {
t.Fatalf("err: %v", err) t.Fatalf("err: %v", err)
} }
testutil.WaitForResult(func() (bool, error) { testutil.WaitForResult(func() (bool, error) {
return c1.serverMgr.GetNumServers() == 1, nil return c1.serverMgr.NumServers() == 1, nil
}, func(err error) { }, func(err error) {
t.Fatalf("expected consul server") t.Fatalf("expected consul server")
}) })
@ -100,7 +100,7 @@ func TestClient_JoinLAN(t *testing.T) {
// Check we have a new consul // Check we have a new consul
testutil.WaitForResult(func() (bool, error) { testutil.WaitForResult(func() (bool, error) {
return c1.serverMgr.GetNumServers() == 1, nil return c1.serverMgr.NumServers() == 1, nil
}, func(err error) { }, func(err error) {
t.Fatalf("expected consul server") t.Fatalf("expected consul server")
}) })

View File

@ -162,14 +162,6 @@ func (sm *ServerManager) FindServer() *server_details.ServerDetails {
} }
} }
// GetNumServers takes out an internal "read lock" and returns the number of
// servers. numServers includes both healthy and unhealthy servers.
func (sm *ServerManager) GetNumServers() (numServers int) {
serverCfg := sm.getServerConfig()
numServers = len(serverCfg.servers)
return numServers
}
// getServerConfig is a convenience method which hides the locking semantics // getServerConfig is a convenience method which hides the locking semantics
// of atomic.Value from the caller. // of atomic.Value from the caller.
func (sm *ServerManager) getServerConfig() serverConfig { func (sm *ServerManager) getServerConfig() serverConfig {
@ -218,6 +210,14 @@ func (sm *ServerManager) NotifyFailedServer(server *server_details.ServerDetails
} }
} }
// NumServers takes out an internal "read lock" and returns the number of
// servers. numServers includes both healthy and unhealthy servers.
func (sm *ServerManager) NumServers() (numServers int) {
serverCfg := sm.getServerConfig()
numServers = len(serverCfg.servers)
return numServers
}
// RebalanceServers takes out an internal write lock and shuffles the list of // RebalanceServers takes out an internal write lock and shuffles the list of
// servers on this agent. This allows for a redistribution of work across // servers on this agent. This allows for a redistribution of work across
// consul servers and provides a guarantee that the order of the server list // consul servers and provides a guarantee that the order of the server list

View File

@ -84,14 +84,14 @@ func TestServerManager_FindServer(t *testing.T) {
func TestServerManager_GetNumServers(t *testing.T) { func TestServerManager_GetNumServers(t *testing.T) {
sm := makeMockServerManager() sm := makeMockServerManager()
var num int var num int
num = sm.GetNumServers() num = sm.NumServers()
if num != 0 { if num != 0 {
t.Fatalf("Expected zero servers to start") t.Fatalf("Expected zero servers to start")
} }
s := &server_details.ServerDetails{} s := &server_details.ServerDetails{}
sm.AddServer(s) sm.AddServer(s)
num = sm.GetNumServers() num = sm.NumServers()
if num != 1 { if num != 1 {
t.Fatalf("Expected one server after AddServer") t.Fatalf("Expected one server after AddServer")
} }