Ejemplo n.º 1
0
    def test_retry_with_set_method(self, key, value, retry):
        config = self.config
        config['retry'] = retry

        storage = store.Storage(store.RedisConnection, config)
        self.assertIsInstance(storage.db.db, redis.Redis)
        storage.db.db.set = connect_failer(retry)(storage.db.db.set)

        # Set value in DB with N times failed connection
        self.assertTrue(storage.set(self.get_key(key), value))
        self.assertEqual(storage.db.db.set.calls, retry)

        # Check value in DB
        self.assertEqual(self.redis.get(self.get_key(key)), value)
    def setUp(self):
        self.context = {}
        self.headers = {}

        store_config = {}
        self.store = store.Storage(MockRedisConnection, store_config)
        self.clients = {
            0: ['travel', 'mountain', 'Patagonia'],
            1: ['summer', 'sea'],
            2: ['winter', 'ski'],
            3: ['shopping', 'Milano'],
            4: ['golf']
        }
        for cid, interest in self.clients.items():
            self.store.set("i:%s" % cid, json.dumps(interest))
Ejemplo n.º 3
0
    def setUp(self):
        self.request = api.ClientsInterestsRequest

        store_config = {}
        self.store = store.Storage(MockRedisConnection, store_config)

        # Init test data in storage
        self.clients = {
            1000: ['travel', 'mountain', 'Patagonia'],
            2001: ['summer', 'sea'],
            2002: ['winter', 'ski'],
            3000: ['shopping', 'Milano'],
            5555: ['golf']
        }
        for cid, interest in self.clients.items():
            self.store.set("i:%s" % cid, json.dumps(interest))
Ejemplo n.º 4
0
    def test_retry_fail(self, key, value, retry):
        """
            _retry methor of RedisConnection try to connect N-1 times
            connect_failer drop connect N times
        """
        config = self.config
        config['retry'] = retry - 1

        storage = store.Storage(store.RedisConnection, config)
        self.assertIsInstance(storage.db.db, redis.Redis)
        storage.db.db.set = connect_failer(retry)(storage.db.db.set)

        self.assertTrue(storage.db.db.ping())
        with self.assertRaises(redis.exceptions.ConnectionError):
            storage.set(key, value)
        self.assertEqual(storage.db.db.set.calls, retry)
Ejemplo n.º 5
0
    def setUp(self):
        config = {
            'host': STORE_CONFIG['host'],
            'port': STORE_CONFIG['port'],
            'db': STORE_CONFIG['db'],
            'password': STORE_CONFIG['password'],
            'timeout': 1,
            'retry': 2,
            'backoff_factor': 0.01,
        }

        self.store = store.Storage(store.RedisConnection, config)
        self.redis = redis.Redis(host=config['host'],
                                 port=config['port'],
                                 db=config['db'],
                                 password=config['password'])

        self.prefix = '_test_storage_'
        self.created_data = set()
Ejemplo n.º 6
0
    def setUp(self):
        self.request = api.OnlineScoreRequest

        store_config = {}
        self.store = store.Storage(MockRedisConnection, store_config)
Ejemplo n.º 7
0
 def setUp(self):
     store_config = {}
     self.store = store.Storage(MockRedisConnection, store_config)