def test_get_memcached_client(self, mock_cacheregion): self.flags(memcached_servers=None) self.flags(group='cache', enabled=False) self.assertRaises(RuntimeError, cache_utils.get_memcached_client, expiration_time=60) self.flags(memcached_servers=['localhost:11211']) self.assertIsNotNone( cache_utils.get_memcached_client(expiration_time=60)) self.flags(memcached_servers=['localhost:11211']) self.assertIsNotNone( cache_utils.get_memcached_client(expiration_time=60)) self.flags(memcached_servers=None) self.flags(group='cache', enabled=True) self.flags(group='cache', memcache_servers=['localhost:11211']) self.assertIsNotNone( cache_utils.get_memcached_client(expiration_time=60)) mock_cacheregion.assert_has_calls([ mock.call('dogpile.cache.memcached', arguments={'url': ['localhost:11211']}, expiration_time=60), mock.call('dogpile.cache.memcached', arguments={'url': ['localhost:11211']}, expiration_time=60), mock.call('dogpile.cache.null', _config_argument_dict=mock.ANY, _config_prefix='cache.oslo.arguments.', expiration_time=60, wrap=None) ])
def test_get_memcached_client(self, mock_cacheregion): self.flags(memcached_servers=None) self.flags(group='cache', enabled=False) self.assertRaises( RuntimeError, cache_utils.get_memcached_client, expiration_time=60) self.flags(memcached_servers=['localhost:11211']) self.assertIsNotNone( cache_utils.get_memcached_client(expiration_time=60)) self.flags(memcached_servers=['localhost:11211']) self.assertIsNotNone( cache_utils.get_memcached_client(expiration_time=60)) self.flags(memcached_servers=None) self.flags(group='cache', enabled=True) self.flags(group='cache', memcache_servers=['localhost:11211']) self.assertIsNotNone( cache_utils.get_memcached_client(expiration_time=60)) mock_cacheregion.assert_has_calls( [mock.call('dogpile.cache.memcached', arguments={'url': ['localhost:11211']}, expiration_time=60), mock.call('dogpile.cache.memcached', arguments={'url': ['localhost:11211']}, expiration_time=60), mock.call('dogpile.cache.null', _config_argument_dict=mock.ANY, _config_prefix='cache.oslo.arguments.', expiration_time=60, wrap=None)] )
def test_get_memcached_client(self, mock_cacheregion): self.flags(group='cache', enabled=True) self.flags(group='cache', memcache_servers=['localhost:11211']) self.assertIsNotNone( cache_utils.get_memcached_client(expiration_time=60)) methods_called = [a[0] for n, a, k in mock_cacheregion.mock_calls] self.assertEqual(['dogpile.cache.null'], methods_called)
def __init__(self, *args, **kwargs): self.mc = cache_utils.get_memcached_client( expiration_time=CONF.service_down_time)