def test_dispatcher_start_handler(self): """ Test the StartHandler of DispatcherActor """ # Define DispatcherState dispatcher_state = DispatcherState(Mock(), None, None) assert dispatcher_state.initialized is False # Define StartHandler start_handler = StartHandler(dispatcher_state) # Test Random message when state is not initialized to_send = [ OKMessage(), ErrorMessage("Error"), HWPCReport("test", "test", "test", {}) ] for msg in to_send: start_handler.handle(msg) assert dispatcher_state.initialized is False # Try to initialize the state start_handler.handle(StartMessage()) assert dispatcher_state.initialized is True
def test_dispatcher_start_handler(self): """ Test the StartHandler of DispatcherActor """ # Define DispatcherState fake_socket_interface = get_fake_socket_interface() dispatcher_state = DispatcherState(Actor._initial_behaviour, fake_socket_interface, Mock(), None, None) assert dispatcher_state.initialized is False # Define StartHandler start_handler = StartHandler() # Test Random message when state is not initialized to_send = [ OKMessage(), ErrorMessage("Error"), HWPCReport("test", "test", "test", {}) ] for msg in to_send: start_handler.handle(msg, dispatcher_state) assert fake_socket_interface.method_calls == [] assert dispatcher_state.initialized is False # Try to initialize the state start_handler.handle(StartMessage(), dispatcher_state) assert dispatcher_state.initialized is True
def __init__(self, name, formula_init_function, route_table, level_logger=logging.WARNING, timeout=None): """ :param str name: Actor name :param func formula_init_function: Function for creating Formula :param route_table: initialized route table of the DispatcherActor :type route_table: powerapi.dispatcher.state.RouteTable :param int level_logger: Define the level of the logger :param bool timeout: Define the time in millisecond to wait for a message before run timeout_handler """ Actor.__init__(self, name, level_logger, timeout) # (func): Function for creating Formula self.formula_init_function = formula_init_function # (powerapi.DispatcherState): Actor state self.state = DispatcherState(Actor._initial_behaviour, SocketInterface(name, timeout), self.logger, self._create_factory(), route_table)
def init_state(): """ return a fresh dispatcher state """ return DispatcherState(Mock(), lambda formula_id: Mock(), RouteTable())