diff --git a/src/lbaf/Execution/lbsInformAndTransferAlgorithm.py b/src/lbaf/Execution/lbsInformAndTransferAlgorithm.py index 8fa957dad..fbbeb7ed6 100644 --- a/src/lbaf/Execution/lbsInformAndTransferAlgorithm.py +++ b/src/lbaf/Execution/lbsInformAndTransferAlgorithm.py @@ -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]) @@ -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) diff --git a/src/lbaf/Model/lbsRank.py b/src/lbaf/Model/lbsRank.py index ef1b5a33d..fffd056e8 100644 --- a/src/lbaf/Model/lbsRank.py +++ b/src/lbaf/Model/lbsRank.py @@ -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): @@ -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): diff --git a/tests/test_lbs_inform_and_transfer_algorithm.py b/tests/test_lbs_inform_and_transfer_algorithm.py index 91551bcc2..7f3223d5c 100644 --- a/tests/test_lbs_inform_and_transfer_algorithm.py +++ b/tests/test_lbs_inform_and_transfer_algorithm.py @@ -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() \ No newline at end of file diff --git a/tests/unit/test_lbs_rank.py b/tests/unit/test_lbs_rank.py index 5e5aeb658..817f2d156 100644 --- a/tests/unit/test_lbs_rank.py +++ b/tests/unit/test_lbs_rank.py @@ -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)