def test_cached_resolve(self): resolver_mock = Mock() instance_name = "instance_name_of_service" resolver_mock.resolve = MagicMock(return_value=instance_name) uuid = "uuid-of-service" resolver = CachingServiceInstanceNameResolver(resolver_mock) result = resolver.resolve(uuid) resolver_mock.resolve.assert_called_once_with(uuid) assert instance_name == result resolver_mock.reset_mock() result = resolver.resolve(uuid) assert resolver_mock.resolve.call_count == 0 assert instance_name == result
def __init__(self, configuration, exit_flag): self._exit_flag = exit_flag self._logger = logging.getLogger(__name__) self._logger.info("Initialized scaling engine with configuration %s", repr(configuration)) self._services_dictionary = configuration.services_dictionary self._metrics_receiver = configuration.metrics_receiver self._metrics = ScalingMetrics() self._rule_checker = RuleChecker(configuration.scaling_policies, configuration.services_dictionary) self._executed_tasks_receiver = configuration.executed_task_receiver self._scaling_action_sender = configuration.scaling_action_sender atexit.register(self._on_engine_shutdown) self._running_services_registry = RunningServicesRegistry( configuration.services_dictionary) instance_name_resolver = ServiceInstanceNameResolver( configuration.etcd_connection) self._service_instance_name_resolver = CachingServiceInstanceNameResolver( instance_name_resolver)