Skip to content

Commit

Permalink
#323: finalize InformAndTransfer testing and fix typos in Rank
Browse files Browse the repository at this point in the history
  • Loading branch information
cwschilly committed Jun 14, 2023
1 parent 0d259c4 commit 24bd3cc
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 57 deletions.
20 changes: 18 additions & 2 deletions src/lbaf/Execution/lbsInformAndTransferAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,28 @@ def __init__(
sys.excepthook = exc_handler
raise SystemExit(1)

# No information about peers is known initially
self.__known_peers = {}

def get_known_peers(self):
"""Return all known peers."""
return self.__known_peers

def __process_message(self, r_rcv: Rank, m: Message):
"""Process message received by rank."""
# Make rank aware of itself
if r_rcv not in self.__known_peers:
self.__known_peers[r_rcv] = {r_rcv}

# Process the message
self.__known_peers[r_rcv].update(m.get_support())

def __forward_message(self, i: int, r_snd: Rank, loads: set, f:int):
def __forward_message(self, i: int, r_snd: Rank, f:int):
"""Forward information message to rank peers sampled from known ones."""
# Make rank aware of itself
if r_snd not in self.__known_peers:
self.__known_peers[r_snd] = {r_snd}

# Create load message tagged at given information round
msg = Message(i, self.__known_peers[r_snd])

Expand Down Expand Up @@ -148,7 +164,7 @@ def __execute_information_stage(self):
for r_snd in rank_set:
# Collect message when destination list is not empty
dst, msg = self.__forward_message(
i, r_snd, rank_set, self.__fanout)
i, r_snd, self.__fanout)
for r_rcv in dst:
messages.setdefault(r_rcv, []).append(msg)

Expand Down
4 changes: 2 additions & 2 deletions src/lbaf/Model/lbsRank.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(
# Initialize other instance variables
self.__size = 0.0

# Start with empty shared blokck information
# Start with empty shared block information
self.__shared_blocks = {}

def copy(self, rank):
Expand Down Expand Up @@ -189,7 +189,7 @@ def get_migratable_load(self) -> float:
return sum([o.get_load() for o in self.__migratable_objects])

def get_sentinel_load(self) -> float:
"""Return sentinel load oon rank."""
"""Return sentinel load on rank."""
return sum([o.get_load() for o in self.__sentinel_objects])

def get_received_volume(self):
Expand Down
62 changes: 10 additions & 52 deletions tests/test_lbs_inform_and_transfer_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,82 +31,40 @@ def setUp(self):
rank_qoi=None,
object_qoi=None)

@patch.object(random, "sample")
def test_lbs_inform_and_transfer_initialize_message(self, random_mock):
self.rank._Rank__known_loads[self.rank] = self.rank.get_load()
temp_rank_1 = Rank(r_id=1, logger=self.logger)
temp_rank_1._Rank__known_loads[temp_rank_1] = 4.0
temp_rank_2 = Rank(r_id=2, logger=self.logger)
temp_rank_2._Rank__known_loads[temp_rank_2] = 5.0
random_mock.return_value = [temp_rank_1, temp_rank_2]
self.assertEqual(
self.inform_and_transfer._InformAndTransferAlgorithm__initialize_message(
self.rank,
loads={self.rank, temp_rank_1, temp_rank_2},
f=4)[0],
[temp_rank_1, temp_rank_2]
)
self.assertEqual(
self.inform_and_transfer._InformAndTransferAlgorithm__initialize_message(
self.rank,
loads={self.rank, temp_rank_1, temp_rank_2},
f=4)[1].get_round(),
Message(1, {"loads": self.rank._Rank__known_loads}).get_round()
)
self.assertEqual(
self.inform_and_transfer._InformAndTransferAlgorithm__initialize_message(
self.rank,
loads={self.rank, temp_rank_1, temp_rank_2},
f=4)[1].get_content(),
Message(1, {"loads": self.rank._Rank__known_loads}).get_content()
)

@patch.object(random, "sample")
def test_lbs_inform_and_transfer_forward_message(self, random_mock):
self.rank._Rank__known_loads[self.rank] = self.rank.get_load()
temp_rank_1 = Rank(r_id=1, logger=self.logger)
temp_rank_1._Rank__known_loads[temp_rank_1] = 4.0
temp_rank_2 = Rank(r_id=2, logger=self.logger)
temp_rank_2._Rank__known_loads[temp_rank_2] = 5.0
random_mock.return_value = [temp_rank_1, temp_rank_2]

self.assertEqual(
self.inform_and_transfer._InformAndTransferAlgorithm__forward_message(
i=2,
r=self.rank,
loads=set(),
r_snd=self.rank,
f=4)[0],
[temp_rank_1, temp_rank_2]
)
self.assertEqual(
self.inform_and_transfer._InformAndTransferAlgorithm__forward_message(
i=2,
r=self.rank,
loads=set(),
r_snd=self.rank,
f=4)[1].get_round(),
Message(2, {"loads": self.rank._Rank__known_loads}).get_round()
Message(2, {"loads": self.inform_and_transfer.get_known_peers()}).get_round()
)
self.assertEqual(
self.inform_and_transfer._InformAndTransferAlgorithm__forward_message(
i=2,
r=self.rank,
loads=set(),
f=4)[1].get_content(),
Message(2, {"loads": self.rank._Rank__known_loads}).get_content()
r_snd=self.rank,
f=4)[1].get_support(),
Message(2, self.inform_and_transfer.get_known_peers()[self.rank]).get_support()
)

def test_lbs_inform_and_transfer_process_message(self):
self.rank._Rank__known_loads[self.rank] = self.rank.get_load()
temp_rank_1 = Rank(r_id=1, logger=self.logger)
temp_rank_1._Rank__known_loads[temp_rank_1] = 4.0
self.assertEqual(self.rank.get_load(), 9.5)
self.inform_and_transfer._InformAndTransferAlgorithm__process_message(
self.rank,
Message(1, {"loads": self.rank._Rank__known_loads})
)
self.assertEqual(
self.rank._Rank__known_loads,
{self.rank: 9.5}
self.rank, Message(1,{temp_rank_1: 4.0})
)
known_peers = self.inform_and_transfer.get_known_peers()
self.assertEqual(known_peers, {self.rank: {self.rank, temp_rank_1}})

if __name__ == "__main__":
unittest.main()
1 change: 0 additions & 1 deletion tests/unit/test_lbs_rank.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ def test_lbs_rank_remove_migratable_object(self):
self.rank.add_migratable_object(temp_object)
self.migratable_objects.add(temp_object)
self.assertEqual(self.rank.get_migratable_objects(), self.migratable_objects)
self.rank._Rank__known_loads[temp_rank] = 4.0
self.rank.remove_migratable_object(temp_object, temp_rank)
self.migratable_objects.remove(temp_object)
self.assertEqual(self.rank.get_migratable_objects(), self.migratable_objects)
Expand Down

0 comments on commit 24bd3cc

Please sign in to comment.