def __init__(self, endpoint, autodiscovery_timeout=10, autodiscovery_interval=60, *args, **kwargs): """ Create a new Client object, and launch a timer for the object. @param endpoint: String something like: test.lwgyhw.cfg.usw2.cache.amazonaws.com:11211 @autodiscovery_timeout: Number Secondes for socket connection timeout when do autodiscovery @autodiscovery_interval: Number Seconds interval for check cluster status @client_debug: String A file name, if set, will write debug message to that file All Other parameters will be passed to python-memcached """ self.endpoint = endpoint self.autodiscovery_timeout = autodiscovery_timeout elasticache_logger.debug('endpoint: %s' % endpoint) self.cluster = Cluster(endpoint, autodiscovery_timeout) self.ring = MemcacheRing(self.cluster.servers, *args, **kwargs) self.need_update = False self.lock = Lock() self.timer = RepeatTimer('autodiscovery', autodiscovery_interval, self._update) self.timer.start()
def test_kwargs(self): self.timer = RepeatTimer('test_timer', 1, self.mock_func, kwargs={ 'arg1': 3, 'arg2': 'foo' }) self.timer.start() time.sleep(2) self.mock_func.assert_called_with(arg1=3, arg2='foo')
def test_args(self): self.timer = RepeatTimer('test_timer', 1, self.mock_func, args=[1, 2]) self.timer.start() time.sleep(2) self.mock_func.assert_called_with(1, 2)
def test_run_timer(self): self.timer = RepeatTimer('test_timer', 1, self.mock_func) self.timer.start() time.sleep(3) self.assertTrue(self.mock_func.call_count >= 2)