def test_connect_timeout(self): # using normal timeout # client usually does lazy connect, but we don't want to confuse # connect and non-connect timeout, so connect manually with moecache.Client((self.unavailable_ip, 11211), timeout=1) \ as client: self.assertRaises(socket.timeout, client.stats)
def test_set_get(self): with helpers.start_new_memcached_server(mock=True) \ as (mock_memcached, port), \ moecache.Client(('127.0.0.1', port)) as client: key = 'set_get' val = 'DhuWmC' client.set(key, val) mcval = client.get(key) self.assertEqual(val, mcval)
def test_get_timeout(self): with helpers.start_new_memcached_server( mock=True, additional_args=['--get-delay', '2']) \ as (mock_memcached, port), \ moecache.Client(('127.0.0.1', port), timeout=1) as client: key = 'get_timeout' val = 'cMuBde' client.set(key, val) # when running unpatched eventlet, # the following will fail w/ socket.error, EAGAIN self.assertRaises(socket.timeout, client.get, key)
def test_gone(self): with helpers.start_new_memcached_server() as (mock_memcached, port), \ moecache.Client(('127.0.0.1', port)) as client: key = 'gone' val = 'QWMcxh' client.set(key, val) mock_memcached.terminate() mock_memcached.wait() self.assertRaises(Exception, client.get, key)
def test_hardfail(self): with helpers.start_new_memcached_server() as (mock_memcached, port), \ moecache.Client(('127.0.0.1', port)) as client: key = 'hardfail' val = 'FuOIdn' client.set(key, val) mock_memcached.kill() # sends SIGKILL mock_memcached.wait() with helpers.start_new_memcached_server(port=port): mcval = client.get(key) self.assertEqual(mcval, None) # val lost when restarted
def __init__(self, conf): rawr.Rawr.__init__(self) log.info("Processing configuration") def split_mc_nodes(nodes): return [util.splitport(n, 11211) for n in nodes] conf_converters = {'memcached:servers': split_mc_nodes} conf = config.process(conf, conf_converters) log.info("Connecting to memcache") cache = moecache.Client(**conf['memcached']) # Force moecache to raise an exception if something is wrong. log.debug("Cache check: %s : %s", "_key_", cache.get("_key_")) log.info("Connecting to mongo") dbname = conf['database'] settings = conf['mongodb'] mc_primary = MongoClient(readPreference='primary', **settings) mc_secondary = MongoClient(readPreference='secondary', **settings) db_primary = mc_primary[dbname] db_secondary = mc_secondary[dbname] log.info("Initializing events collection") self._init_events(db_primary, conf['event_ttl']) log.info("Setting up routes") # This is ugly and I would like to find a better way. ctl_shared = controllers.Shared(cache, conf['test_mode']) args_health = { 'mongo_db': db_primary, 'shared': ctl_shared, 'fields': conf['health_fields'], } args_main = { 'mongo_db': db_secondary, 'shared': ctl_shared, 'authtoken_prefix': conf['token_prefix'], 'token_hashing_threshold': conf['token_hashing_threshold'], } self.add_route(r'/health$', controllers.HealthController, args_health) self.add_route(r'/.+', controllers.MainController, args_main)
def setUp(self): self.client = moecache.Client(('127.0.0.1', self.port))
def test_connect_timeout2(self): # using connect timeout with moecache.Client((self.unavailable_ip, 11211), connect_timeout=1) \ as client: self.assertRaises(socket.timeout, client.stats)
def setUp(self): self.client = moecache.Client([('127.0.0.1', port) for _, port in self.servers])