当前位置: 首页>>代码示例>>Python>>正文


Python Cluster._make_key方法代码示例

本文整理汇总了Python中cluster.Cluster._make_key方法的典型用法代码示例。如果您正苦于以下问题:Python Cluster._make_key方法的具体用法?Python Cluster._make_key怎么用?Python Cluster._make_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cluster.Cluster的用法示例。


在下文中一共展示了Cluster._make_key方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestCluster

# 需要导入模块: from cluster import Cluster [as 别名]
# 或者: from cluster.Cluster import _make_key [as 别名]
class TestCluster(unittest.TestCase):

    def setUp(self):
        print "### setUp ###"
        self.cluster = Cluster()

    def test_make_key(self):
        print "test_make_key"
        text = "%s:%s" % (HOST, PORT)
        self.assertEqual(self.cluster._make_key(HOST, PORT), text)

    def test_set_role(self):
        self.cluster.add_node(host=HOST, port=PORT, role=ROLE_MASTER, status=REDIS_STATUS_OK)
        self.cluster._set_role(HOST, PORT, ROLE_MASTER)
        node = self.cluster.get_node(HOST, PORT)
        self.assertTrue(node.is_master)

    def test_filtered_list(self):
        print "test_filtered_list"
        self.cluster.add_node(host=HOST, port=PORT, role=ROLE_MASTER, status=REDIS_STATUS_OK)
        self.cluster.add_node(host=HOST, port=PORT+1, role=ROLE_SLAVE, status=REDIS_STATUS_KO)
        self.cluster.add_node(host=HOST, port=PORT+2, role=ROLE_SLAVE, status=REDIS_STATUS_OK)
        testlist = self.cluster.filtered_list(roles=(ROLE_MASTER))
        self.assertEqual(len(testlist), 1)
        self.assertTrue(testlist[0].is_master())
        self.assertTrue(testlist[0].is_alive())
        testlist = self.cluster.filtered_list(roles=(ROLE_SLAVE))
        self.assertEqual(len(testlist), 2)
        self.assertTrue(testlist[0].is_slave() and testlist[1].is_slave())
        testlist = self.cluster.filtered_list()
        self.assertEqual(len(testlist), 3)
        testlist = self.cluster.filtered_list(status=REDIS_STATUS_KO)
        self.assertEqual(len(testlist), 1)
        self.assertTrue(testlist[0].is_slave() and not testlist[0].is_alive())
        testlist = self.cluster.filtered_list(status=REDIS_STATUS_OK)
        self.assertEqual(len(testlist), 2)
        testlist = self.cluster.filtered_list(roles=ROLE_MASTER, status=REDIS_STATUS_KO)
        self.assertEqual(len(testlist), 0)
        testlist = self.cluster.filtered_list(roles=(ROLE_MASTER,ROLE_SLAVE), status=REDIS_STATUS_KO)
        self.assertEqual(len(testlist), 1)
        self.assertTrue(testlist[0].is_slave() and not testlist[0].is_alive())

    def test_add_single_master(self):
        print "test_add_single_master"
        self.cluster.add_node(host=HOST, port=PORT, role=ROLE_MASTER, status=REDIS_STATUS_OK)
        self.assertEqual(len(self.cluster), 1)
        node = self.cluster.get_master()
        self.assertTrue(node.is_master() and node.is_alive())

    def test_add_single_slave(self):
        print "test_add_single_slave"
        self.cluster.add_node(host=HOST, port=PORT, role=ROLE_SLAVE, status=REDIS_STATUS_OK)
        self.assertEqual(len(self.cluster), 1)
        self.assertIsNone(self.cluster.get_master())
        node = self.cluster.get_node(host=HOST, port=PORT)
        self.assertTrue(node.is_slave() and node.is_alive())

    def test_promote_new_master_single_node(self):
        print "test_promote_new_master_single_node"
        old_master = self.cluster.add_node(host=HOST, port=PORT, role=ROLE_MASTER, status=REDIS_STATUS_OK)
        self.assertEqual(len(self.cluster), 1)
        self.cluster.promote_new_master(old_master)
        node = self.cluster.get_master()
        self.assertTrue(node is not None)
        self.assertTrue(node.is_master())
        self.assertFalse(node.is_alive())

    def test_str(self):
        print "test_str"
        self.cluster.add_node(host=HOST, port=PORT, role=ROLE_MASTER, status=REDIS_STATUS_OK)
        self.cluster.add_node(host=HOST, port=PORT+1, role=ROLE_SLAVE, status=REDIS_STATUS_OK)
        self.assertEqual("(localhost:1000,master,OK),(localhost:1001,slave,OK)", str(self.cluster))

    def _create_message(self, redis_host, redis_port, redis_status):
        worker_name = '%s:%s' % (redis_host, redis_port)
        text = "%s,%s" % (worker_name, redis_status)
        return text

    def tearDown(self):
        print "### tearDown ###"
        self.cluster = None
开发者ID:AloneRoad,项目名称:redis_failover,代码行数:83,代码来源:test_cluster.py


注:本文中的cluster.Cluster._make_key方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。