2018-05-24 23:35:25 -07:00
|
|
|
from __future__ import absolute_import, division, print_function
|
2018-03-07 10:18:58 -08:00
|
|
|
|
|
|
|
import os
|
|
|
|
import unittest
|
|
|
|
|
2018-05-24 23:35:25 -07:00
|
|
|
import redis
|
|
|
|
|
2018-03-07 10:18:58 -08:00
|
|
|
import ray
|
|
|
|
|
|
|
|
|
2018-05-24 23:35:25 -07:00
|
|
|
def parse_client(addr_port_str):
|
|
|
|
redis_address, redis_port = addr_port_str.split(":")
|
|
|
|
return redis.StrictRedis(host=redis_address, port=redis_port)
|
|
|
|
|
|
|
|
|
2018-04-11 10:11:35 -07:00
|
|
|
@unittest.skipIf(not os.environ.get('RAY_USE_NEW_GCS', False),
|
|
|
|
"Tests functionality of the new GCS.")
|
2018-03-07 10:18:58 -08:00
|
|
|
class CredisTest(unittest.TestCase):
|
|
|
|
def setUp(self):
|
2018-03-18 14:02:19 -07:00
|
|
|
self.config = ray.init(num_workers=0)
|
2018-03-07 10:18:58 -08:00
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
ray.worker.cleanup()
|
|
|
|
|
|
|
|
def test_credis_started(self):
|
2018-05-24 23:35:25 -07:00
|
|
|
assert "redis_address" in self.config
|
|
|
|
primary = parse_client(self.config['redis_address'])
|
|
|
|
assert primary.ping() is True
|
2018-06-20 14:40:57 -07:00
|
|
|
member = primary.lrange('RedisShards', 0, -1)[0]
|
|
|
|
shard = parse_client(member.decode())
|
|
|
|
|
|
|
|
# TODO(zongheng): remove these next four lines of horror, once task
|
|
|
|
# table is correctly placed in the data shard & swapping master and
|
|
|
|
# member modules.
|
|
|
|
member = self.config['redis_address']
|
|
|
|
temp = primary
|
|
|
|
primary = shard
|
|
|
|
shard = temp
|
2018-05-24 23:35:25 -07:00
|
|
|
|
|
|
|
# Check that primary has loaded credis' master module.
|
|
|
|
chain = primary.execute_command('MASTER.GET_CHAIN')
|
|
|
|
assert len(chain) == 1
|
|
|
|
|
|
|
|
# Check that the shard has loaded credis' member module.
|
2018-06-20 14:40:57 -07:00
|
|
|
assert chain[0].decode() == member
|
2018-05-24 23:35:25 -07:00
|
|
|
assert shard.execute_command('MEMBER.SN') == -1
|
2018-03-07 10:18:58 -08:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main(verbosity=2)
|