def run(self, duration): """ Run the simulator for ``duration`` usecs. """ timer = param.MIN_PROPG_DELAY while timer <= duration: for node in self._nodes: node.run(timer) self._config.run(timer) self._stats.run(timer) timer += param.MIN_PROPG_DELAY self._stats.report_end_time(timer)
def test_basic(self): n_rounds = 4 timer = 0 msg_sent_sum = 0 msg_received_sum = 0 for i in range(n_rounds): timer += param.MIN_PROPG_DELAY for node in self.nodes: node.run(timer) # Process remaining messages timer += param.MAX_PROPG_DELAY + (N_NODES * param.MAX_PKT_PROC_LTC) for node in self.nodes: node.process_messages(timer) for app in self.apps: msg_sent_sum += app._sent_messages msg_received_sum += app._received_messages total_time = n_rounds * param.MIN_PROPG_DELAY expected_msgs = (total_time // nullrpc.MESSAGE_INTERVAL) * N_NODES self.assertEqual(msg_sent_sum, expected_msgs) self.assertEqual(msg_sent_sum, msg_received_sum)
def test_nodereport(self): self.server_apps[0]._key_request_counter['k1'] = 50 self.server_apps[0]._key_request_counter['k5'] = 20 self.server_apps[1]._key_request_counter['k1'] = 30 self.server_apps[1]._key_request_counter['k2'] = 30 self.server_apps[1]._key_request_counter['k3'] = 40 self.server_apps[2]._key_request_counter['k2'] = 30 self.server_apps[2]._key_request_counter['k6'] = 5 self.server_apps[2]._key_request_counter['k4'] = 30 for node in self.cache_nodes: node.run(1000000) self.config.run(1000000) node_to_keys = {} for key in ['k1', 'k2', 'k3', 'k4', 'k5', 'k6']: nodes = self.config.key_to_nodes(key, None) self.assertEqual(len(nodes.dst_nodes), 1) keys = node_to_keys.setdefault(nodes.dst_nodes[0].id, []) keys.append(key) for _, keys in node_to_keys.items(): if 'k1' in keys: self.assertEqual(len(keys), 1) elif 'k2' in keys: self.assertEqual(len(keys), 1) elif 'k3' in keys: self.assertTrue('k6' in keys) elif 'k4' in keys: self.assertTrue('k5' in keys) self.server_apps[0]._key_request_counter['k1'] = 90 self.server_apps[0]._key_request_counter['k3'] = 10 self.server_apps[1]._key_request_counter['k1'] = 90 self.server_apps[1]._key_request_counter['k2'] = 10 self.server_apps[2]._key_request_counter['k1'] = 30 self.server_apps[2]._key_request_counter['k2'] = 70 self.server_apps[3]._key_request_counter['k2'] = 40 self.server_apps[3]._key_request_counter['k3'] = 30 self.server_apps[3]._key_request_counter['k4'] = 10 for node in self.cache_nodes: node.run(2000000) self.config.run(2000000) node_to_keys = {} for key in ['k1', 'k2', 'k3', 'k4']: nodes = self.config.key_to_nodes(key, None) if key == 'k1': self.assertEqual(len(nodes.dst_nodes), 3) elif key == 'k2': self.assertEqual(len(nodes.dst_nodes), 4) else: self.assertEqual(len(nodes.dst_nodes), 1) for node in nodes.dst_nodes: keys = node_to_keys.setdefault(node.id, []) keys.append(key) for _, keys in node_to_keys.items(): if 'k1' in keys: self.assertEqual(len(keys), 2) self.assertTrue('k2' in keys) elif 'k3' in keys: self.assertEqual(len(keys), 3) self.assertTrue('k2' in keys) self.assertTrue('k4' in keys)
def run_servers(self, end_time): for node in self.cache_nodes: node.run(end_time)
def run_cache_nodes(self, time): for node in self.cache_nodes: node.run(time)