From 8e3c83a258813094a277339c8cf4d0577cfb4941 Mon Sep 17 00:00:00 2001 From: Sean Chittenden Date: Wed, 24 Feb 2016 22:09:49 -0800 Subject: [PATCH] Rename GetNumServers to NumServers() Matches the style of the rest of the repo --- consul/client.go | 2 +- consul/client_test.go | 4 ++-- consul/server_manager/server_manager.go | 16 ++++++++-------- consul/server_manager/server_manager_test.go | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/consul/client.go b/consul/client.go index 78643a34ed..4f2de2a191 100644 --- a/consul/client.go +++ b/consul/client.go @@ -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 // for various sub-systems func (c *Client) Stats() map[string]map[string]string { - numServers := c.serverMgr.GetNumServers() + numServers := c.serverMgr.NumServers() toString := func(v uint64) string { return strconv.FormatUint(v, 10) diff --git a/consul/client_test.go b/consul/client_test.go index 1249800949..8caf765249 100644 --- a/consul/client_test.go +++ b/consul/client_test.go @@ -84,7 +84,7 @@ func TestClient_JoinLAN(t *testing.T) { t.Fatalf("err: %v", err) } testutil.WaitForResult(func() (bool, error) { - return c1.serverMgr.GetNumServers() == 1, nil + return c1.serverMgr.NumServers() == 1, nil }, func(err error) { t.Fatalf("expected consul server") }) @@ -100,7 +100,7 @@ func TestClient_JoinLAN(t *testing.T) { // Check we have a new consul testutil.WaitForResult(func() (bool, error) { - return c1.serverMgr.GetNumServers() == 1, nil + return c1.serverMgr.NumServers() == 1, nil }, func(err error) { t.Fatalf("expected consul server") }) diff --git a/consul/server_manager/server_manager.go b/consul/server_manager/server_manager.go index e3342a9236..b327b20f24 100644 --- a/consul/server_manager/server_manager.go +++ b/consul/server_manager/server_manager.go @@ -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 // of atomic.Value from the caller. 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 // 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 diff --git a/consul/server_manager/server_manager_test.go b/consul/server_manager/server_manager_test.go index b5285d505d..2fa61a3dc5 100644 --- a/consul/server_manager/server_manager_test.go +++ b/consul/server_manager/server_manager_test.go @@ -84,14 +84,14 @@ func TestServerManager_FindServer(t *testing.T) { func TestServerManager_GetNumServers(t *testing.T) { sm := makeMockServerManager() var num int - num = sm.GetNumServers() + num = sm.NumServers() if num != 0 { t.Fatalf("Expected zero servers to start") } s := &server_details.ServerDetails{} sm.AddServer(s) - num = sm.GetNumServers() + num = sm.NumServers() if num != 1 { t.Fatalf("Expected one server after AddServer") }