示例#1
0
 def test_default_redis_connection(self):
     app = tasks.initialize_celery()
     ch = app.broker_connection().channel()
     ch.client.set('mykey', '1')
     self.assertEqual(ch.client.get('mykey'), '1')
     self.assertEqual(ch.client.info()['tcp_port'], 6379)
     self.assertEqual(app.backend.client.info()['tcp_port'], 6379)
示例#2
0
 def test_default_redis_connection(self):
     app = tasks.initialize_celery()
     ch = app.broker_connection().channel()
     ch.client.set('mykey', '1')
     self.assertEqual(ch.client.get('mykey'), '1')
     self.assertEqual(ch.client.info()['tcp_port'], 6379)
     self.assertEqual(app.backend.client.info()['tcp_port'], 6379)
示例#3
0
 def with_env_var(self, env_var, env_value, redis_port):
     os.environ[env_var] = env_value
     app = tasks.initialize_celery()
     ch = app.broker_connection().channel()
     ch.client.set('mykey', env_var)
     self.assertEqual(ch.client.get('mykey'), env_var)
     self.assertEqual(ch.client.info()['tcp_port'], redis_port)
     self.assertEqual(app.backend.client.info()['tcp_port'], redis_port)
示例#4
0
 def test_simple_redis_string(self):
     os.environ['REDIS_ENDPOINT'] = "redis://:[email protected]:51113/0"
     app = tasks.initialize_celery()
     ch = app.broker_connection().channel()
     ch.client.set('mykey', '1')
     self.assertEqual(ch.client.get('mykey'), '1')
     self.assertEqual(ch.client.info()['tcp_port'], 51113)
     self.assertEqual(app.backend.client.info()['tcp_port'], 51113)
示例#5
0
 def with_env_var(self, env_var):
     os.environ[env_var] = "sentinel://:[email protected]:51111,127.0.0.1:51112/service_name:mymaster"
     app = tasks.initialize_celery()
     ch = app.broker_connection().channel()
     ch.client.set('mykey', '1')
     self.assertEqual(ch.client.get('mykey'), '1')
     self.assertEqual(ch.client.info()['tcp_port'], 51113)
     self.assertEqual(app.backend.client.info()['tcp_port'], 51113)
示例#6
0
 def test_simple_redis_string(self):
     os.environ['REDIS_ENDPOINT'] = "redis://:[email protected]:{}/0".format(
         self.master_port)
     app = tasks.initialize_celery()
     ch = app.broker_connection().channel()
     ch.client.set('mykey_simple_redis', '1')
     self.assertEqual(ch.client.get('mykey_simple_redis'), '1')
     self.assertEqual(ch.client.info()['tcp_port'], self.master_port)
     self.assertEqual(app.backend.client.info()['tcp_port'],
                      self.master_port)
示例#7
0
 def test_sentinel_connection_pool_reconnect(self):
     os.environ[
         'SENTINEL_ENDPOINT'] = "sentinel://:[email protected]:51111/service_name:mymaster"
     app = tasks.initialize_celery()
     app_client = app.backend.client
     self.redis_clients_manager(kill=True)
     app_client.set('mykey_connection_pool_client',
                    'sentinel_connection_pool')
     self.assertEqual(app_client.get('mykey_connection_pool_client'),
                      'sentinel_connection_pool')
     self.assertEqual(self.redis_clients_manager(), 1)
示例#8
0
 def test_sentinel_connection_pool_shared(self):
     os.environ[
         'SENTINEL_ENDPOINT'] = "sentinel://:[email protected]:51111/service_name:mymaster"
     app = tasks.initialize_celery()
     app_client = []
     for x in range(10):
         app_client.append(app.backend.client)
         app_client[x].set('mykey_app_client_shared',
                           'sentinel_connection_shared_{}'.format(x))
         self.assertEqual(app_client[x].get('mykey_app_client_shared'),
                          'sentinel_connection_shared_{}'.format(x))
     self.assertEqual(id(app_client[0].connection_pool),
                      id(app_client[9].connection_pool))
     self.assertEqual(self.redis_clients_manager(), 1)
示例#9
0
 def test_sentinel_master_failover(self):
     os.environ[
         'SENTINEL_ENDPOINT'] = "sentinel://:[email protected]:51111/service_name:mymaster"
     app = tasks.initialize_celery()
     ch = app.broker_connection().channel()
     redis_conn = redis.StrictRedis().from_url(
         "redis://:[email protected]:{}".format(self.master_port))
     self.assertEqual(redis_conn.info()['role'], 'master')
     redis_conn = redis.StrictRedis().from_url("redis://127.0.0.1:51111")
     redis_conn.execute_command("sentinel failover mymaster")
     redis_conn = redis.StrictRedis().from_url(
         "redis://:[email protected]:{}".format(self.master_port))
     timeout_failover = 0
     while redis_conn.info()['role'] == 'slave' and timeout_failover <= 30:
         time.sleep(1)
         timeout_failover += 1
     self.assertEqual(ch.client.info()['role'], 'master')
     ch.client.set('mykey_failover', 'sentinel_failover_key')
     self.assertEqual(ch.client.get('mykey_failover'),
                      'sentinel_failover_key')
     self.assertEqual(app.backend.client.get('mykey_failover'),
                      'sentinel_failover_key')