示例#1
0
文件: test.py 项目: racker/moecache
    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)
示例#2
0
文件: test.py 项目: racker/moecache
 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)
示例#3
0
文件: test.py 项目: racker/moecache
 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)
示例#4
0
文件: test.py 项目: racker/moecache
    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)
示例#5
0
文件: test.py 项目: racker/moecache
    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
示例#6
0
    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)
示例#7
0
文件: test.py 项目: racker/moecache
 def setUp(self):
     self.client = moecache.Client(('127.0.0.1', self.port))
示例#8
0
文件: test.py 项目: racker/moecache
 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)
示例#9
0
 def setUp(self):
     self.client = moecache.Client([('127.0.0.1', port)
                                    for _, port in self.servers])