storage_client.py: clean up test_add_server/test_add_descriptor, remove .test_servers

This commit is contained in:
Brian Warner 2011-02-26 19:10:56 -07:00
parent cba3de04a4
commit 9b9ea3f739
5 changed files with 15 additions and 21 deletions

View File

@ -71,15 +71,16 @@ class StorageFarmBroker:
# own Reconnector, and will give us a RemoteReference when we ask # own Reconnector, and will give us a RemoteReference when we ask
# them for it. # them for it.
self.servers = {} self.servers = {}
# self.test_servers are statically configured from unit tests
self.test_servers = {} # serverid -> rref
self.introducer_client = None self.introducer_client = None
# these two are used in unit tests # these two are used in unit tests
def test_add_server(self, serverid, rref): def test_add_rref(self, serverid, rref):
self.test_servers[serverid] = rref s = NativeStorageServer(serverid, {})
def test_add_descriptor(self, serverid, dsc): s.rref = rref
self.servers[serverid] = dsc self.servers[serverid] = s
def test_add_server(self, serverid, s):
self.servers[serverid] = s
def use_introducer(self, introducer_client): def use_introducer(self, introducer_client):
self.introducer_client = ic = introducer_client self.introducer_client = ic = introducer_client
@ -124,7 +125,6 @@ class StorageFarmBroker:
def get_all_serverids(self): def get_all_serverids(self):
serverids = set() serverids = set()
serverids.update(self.test_servers.keys())
serverids.update(self.servers.keys()) serverids.update(self.servers.keys())
return frozenset(serverids) return frozenset(serverids)
@ -133,13 +133,7 @@ class StorageFarmBroker:
if s.get_rref()]) if s.get_rref()])
def get_known_servers(self): def get_known_servers(self):
servers = [] return sorted(self.servers.values(), key=lambda s: s.get_serverid())
for serverid,rref in self.test_servers.items():
s = NativeStorageServer(serverid, {})
s.rref = rref
servers.append(s)
servers.extend(self.servers.values())
return sorted(servers, key=lambda s: s.get_serverid())
def get_nickname_for_serverid(self, serverid): def get_nickname_for_serverid(self, serverid):
if serverid in self.servers: if serverid in self.servers:

View File

@ -28,8 +28,8 @@ class WebResultsRendering(unittest.TestCase, WebRenderingMixin):
"my-version": "ver", "my-version": "ver",
"oldest-supported": "oldest", "oldest-supported": "oldest",
} }
dsc = NativeStorageServer(peerid, ann_d) s = NativeStorageServer(peerid, ann_d)
sb.test_add_descriptor(peerid, dsc) sb.test_add_server(peerid, s)
c = FakeClient() c = FakeClient()
c.storage_broker = sb c.storage_broker = sb
return c return c

View File

@ -129,11 +129,11 @@ class Basic(testutil.ReallyEqualMixin, unittest.TestCase):
def test_permute(self): def test_permute(self):
sb = StorageFarmBroker(None, True) sb = StorageFarmBroker(None, True)
for k in ["%d" % i for i in range(5)]: for k in ["%d" % i for i in range(5)]:
sb.test_add_server(k, "rref") sb.test_add_rref(k, "rref")
self.failUnlessReallyEqual(self._permute(sb, "one"), ['3','1','0','4','2']) self.failUnlessReallyEqual(self._permute(sb, "one"), ['3','1','0','4','2'])
self.failUnlessReallyEqual(self._permute(sb, "two"), ['0','4','2','1','3']) self.failUnlessReallyEqual(self._permute(sb, "two"), ['0','4','2','1','3'])
sb.test_servers.clear() sb.servers.clear()
self.failUnlessReallyEqual(self._permute(sb, "one"), []) self.failUnlessReallyEqual(self._permute(sb, "one"), [])
def test_versions(self): def test_versions(self):

View File

@ -188,7 +188,7 @@ def make_storagebroker(s=None, num_peers=10):
storage_broker = StorageFarmBroker(None, True) storage_broker = StorageFarmBroker(None, True)
for peerid in peerids: for peerid in peerids:
fss = FakeStorageServer(peerid, s) fss = FakeStorageServer(peerid, s)
storage_broker.test_add_server(peerid, fss) storage_broker.test_add_rref(peerid, fss)
return storage_broker return storage_broker
def make_nodemaker(s=None, num_peers=10): def make_nodemaker(s=None, num_peers=10):

View File

@ -196,8 +196,8 @@ class FakeClient:
peers = [ ("%20d"%fakeid, FakeStorageServer(mode[fakeid])) peers = [ ("%20d"%fakeid, FakeStorageServer(mode[fakeid]))
for fakeid in range(self.num_servers) ] for fakeid in range(self.num_servers) ]
self.storage_broker = StorageFarmBroker(None, permute_peers=True) self.storage_broker = StorageFarmBroker(None, permute_peers=True)
for (serverid, server) in peers: for (serverid, rref) in peers:
self.storage_broker.test_add_server(serverid, server) self.storage_broker.test_add_rref(serverid, rref)
self.last_peers = [p[1] for p in peers] self.last_peers = [p[1] for p in peers]
def log(self, *args, **kwargs): def log(self, *args, **kwargs):