mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-02 11:16:41 +00:00
test_upload.py: factor out FakeServerTracker
This commit is contained in:
parent
9fc55bad25
commit
13d284b087
@ -725,6 +725,11 @@ def is_happy_enough(servertoshnums, h, k):
|
|||||||
# print "HAAPP{Y"
|
# print "HAAPP{Y"
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
class FakeServerTracker:
|
||||||
|
def __init__(self, serverid, buckets):
|
||||||
|
self.serverid = serverid
|
||||||
|
self.buckets = buckets
|
||||||
|
|
||||||
class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
|
class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
|
||||||
ShouldFailMixin):
|
ShouldFailMixin):
|
||||||
def find_all_shares(self, unused=None):
|
def find_all_shares(self, unused=None):
|
||||||
@ -1355,13 +1360,9 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
|
|||||||
# if not provided with a upload_servers argument, it should just
|
# if not provided with a upload_servers argument, it should just
|
||||||
# return the first argument unchanged.
|
# return the first argument unchanged.
|
||||||
self.failUnlessEqual(shares, merge_peers(shares, set([])))
|
self.failUnlessEqual(shares, merge_peers(shares, set([])))
|
||||||
class FakeServerTracker:
|
|
||||||
pass
|
|
||||||
trackers = []
|
trackers = []
|
||||||
for (i, server) in [(i, "server%d" % i) for i in xrange(5, 9)]:
|
for (i, server) in [(i, "server%d" % i) for i in xrange(5, 9)]:
|
||||||
t = FakeServerTracker()
|
t = FakeServerTracker(server, [i])
|
||||||
t.serverid = server
|
|
||||||
t.buckets = [i]
|
|
||||||
trackers.append(t)
|
trackers.append(t)
|
||||||
expected = {
|
expected = {
|
||||||
1 : set(["server1"]),
|
1 : set(["server1"]),
|
||||||
@ -1387,9 +1388,7 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
|
|||||||
expected = {}
|
expected = {}
|
||||||
for (i, server) in [(i, "server%d" % i) for i in xrange(10)]:
|
for (i, server) in [(i, "server%d" % i) for i in xrange(10)]:
|
||||||
shares3[i] = set([server])
|
shares3[i] = set([server])
|
||||||
t = FakeServerTracker()
|
t = FakeServerTracker(server, [i])
|
||||||
t.serverid = server
|
|
||||||
t.buckets = [i]
|
|
||||||
trackers.append(t)
|
trackers.append(t)
|
||||||
expected[i] = set([server])
|
expected[i] = set([server])
|
||||||
self.failUnlessEqual(expected, merge_peers(shares3, set(trackers)))
|
self.failUnlessEqual(expected, merge_peers(shares3, set(trackers)))
|
||||||
@ -1423,13 +1422,9 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
|
|||||||
# ServerTracker instances, but for testing it is fine to make a
|
# ServerTracker instances, but for testing it is fine to make a
|
||||||
# FakeServerTracker whose job is to hold those instance variables to
|
# FakeServerTracker whose job is to hold those instance variables to
|
||||||
# test that part.
|
# test that part.
|
||||||
class FakeServerTracker:
|
|
||||||
pass
|
|
||||||
trackers = []
|
trackers = []
|
||||||
for (i, server) in [(i, "server%d" % i) for i in xrange(5, 9)]:
|
for (i, server) in [(i, "server%d" % i) for i in xrange(5, 9)]:
|
||||||
t = FakeServerTracker()
|
t = FakeServerTracker(server, [i])
|
||||||
t.serverid = server
|
|
||||||
t.buckets = [i]
|
|
||||||
trackers.append(t)
|
trackers.append(t)
|
||||||
# Recall that test1 is a server layout with servers_of_happiness
|
# Recall that test1 is a server layout with servers_of_happiness
|
||||||
# = 3. Since there isn't any overlap between the shnum ->
|
# = 3. Since there isn't any overlap between the shnum ->
|
||||||
@ -1441,9 +1436,7 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
|
|||||||
# Now add an overlapping server to trackers. This is redundant,
|
# Now add an overlapping server to trackers. This is redundant,
|
||||||
# so it should not cause the previously reported happiness value
|
# so it should not cause the previously reported happiness value
|
||||||
# to change.
|
# to change.
|
||||||
t = FakeServerTracker()
|
t = FakeServerTracker("server1", [1])
|
||||||
t.serverid = "server1"
|
|
||||||
t.buckets = [1]
|
|
||||||
trackers.append(t)
|
trackers.append(t)
|
||||||
test2 = merge_peers(test1, set(trackers))
|
test2 = merge_peers(test1, set(trackers))
|
||||||
happy = servers_of_happiness(test2)
|
happy = servers_of_happiness(test2)
|
||||||
@ -1460,13 +1453,9 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
|
|||||||
4 : set(['server4']),
|
4 : set(['server4']),
|
||||||
}
|
}
|
||||||
trackers = []
|
trackers = []
|
||||||
t = FakeServerTracker()
|
t = FakeServerTracker('server5', [4])
|
||||||
t.serverid = 'server5'
|
|
||||||
t.buckets = [4]
|
|
||||||
trackers.append(t)
|
trackers.append(t)
|
||||||
t = FakeServerTracker()
|
t = FakeServerTracker('server6', [3, 5])
|
||||||
t.serverid = 'server6'
|
|
||||||
t.buckets = [3, 5]
|
|
||||||
trackers.append(t)
|
trackers.append(t)
|
||||||
# The value returned by servers_of_happiness is the size
|
# The value returned by servers_of_happiness is the size
|
||||||
# of a maximum matching in the bipartite graph that
|
# of a maximum matching in the bipartite graph that
|
||||||
|
Loading…
Reference in New Issue
Block a user