當前位置: 首頁>>代碼示例>>Python>>正文


Python NodeManager.initialize方法代碼示例

本文整理匯總了Python中rediscluster.nodemanager.NodeManager.initialize方法的典型用法代碼示例。如果您正苦於以下問題:Python NodeManager.initialize方法的具體用法?Python NodeManager.initialize怎麽用?Python NodeManager.initialize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rediscluster.nodemanager.NodeManager的用法示例。


在下文中一共展示了NodeManager.initialize方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_cluster_one_instance

# 需要導入模塊: from rediscluster.nodemanager import NodeManager [as 別名]
# 或者: from rediscluster.nodemanager.NodeManager import initialize [as 別名]
def test_cluster_one_instance():
    """
    If the cluster exists of only 1 node then there is some hacks that must
    be validated they work.
    """
    with patch.object(StrictRedis, 'execute_command') as mock_execute_command:
        return_data = [[0, 16383, ['', 7006]]]

        def patch_execute_command(*args, **kwargs):
            if args == ('CONFIG GET', 'cluster-require-full-coverage'):
                return {'cluster-require-full-coverage': 'yes'}
            else:
                return return_data

        # mock_execute_command.return_value = return_data
        mock_execute_command.side_effect = patch_execute_command

        n = NodeManager(startup_nodes=[{"host": "127.0.0.1", "port": 7006}])
        n.initialize()

        assert n.nodes == {"127.0.0.1:7006": {
            'host': '127.0.0.1',
            'name': '127.0.0.1:7006',
            'port': 7006,
            'server_type': 'master',
        }}

        assert len(n.slots) == 16384
        for i in range(0, 16384):
            assert n.slots[i] == [{
                "host": "127.0.0.1",
                "name": "127.0.0.1:7006",
                "port": 7006,
                "server_type": "master",
            }]
開發者ID:Grokzen,項目名稱:redis-py-cluster,代碼行數:37,代碼來源:test_node_manager.py

示例2: test_cluster_one_instance

# 需要導入模塊: from rediscluster.nodemanager import NodeManager [as 別名]
# 或者: from rediscluster.nodemanager.NodeManager import initialize [as 別名]
def test_cluster_one_instance():
    """
    If the cluster exists of only 1 node then there is some hacks that must
    be validated they work.
    """
    with patch.object(StrictRedis, 'execute_command') as mock_execute_command:
        return_data = [[0, 16383, ['', 7006]]]
        mock_execute_command.return_value = return_data

        n = NodeManager(startup_nodes=[{"host": "127.0.0.1", "port": 7006}])
        n.initialize()

        assert n.nodes == {"127.0.0.1:7006": {
            'host': '127.0.0.1',
            'name': '127.0.0.1:7006',
            'port': 7006,
            'server_type': 'master',
        }}

        assert len(n.slots) == 16384
        assert n.slots[0] == {
            "host": "127.0.0.1",
            "name": "127.0.0.1:7006",
            "port": 7006,
            "server_type": "master",
        }
開發者ID:huangfupeng,項目名稱:redis-py-cluster,代碼行數:28,代碼來源:test_node_manager.py

示例3: test_all_nodes

# 需要導入模塊: from rediscluster.nodemanager import NodeManager [as 別名]
# 或者: from rediscluster.nodemanager.NodeManager import initialize [as 別名]
def test_all_nodes():
    """
    Set a list of nodes and it should be possible to itterate over all
    """
    n = NodeManager(startup_nodes=[{"host": "127.0.0.1", "port": 7000}])
    n.initialize()

    nodes = [node for node in n.nodes.values()]

    for i, node in enumerate(n.all_nodes()):
        assert node in nodes
開發者ID:huangfupeng,項目名稱:redis-py-cluster,代碼行數:13,代碼來源:test_node_manager.py

示例4: test_cluster_slots_error

# 需要導入模塊: from rediscluster.nodemanager import NodeManager [as 別名]
# 或者: from rediscluster.nodemanager.NodeManager import initialize [as 別名]
def test_cluster_slots_error():
    """
    Check that exception is raised if initialize can't execute
    'CLUSTER SLOTS' command.
    """
    with patch.object(StrictRedisCluster, 'execute_command') as execute_command_mock:
        execute_command_mock.side_effect = Exception("foobar")

        n = NodeManager(startup_nodes=[{}])

        with pytest.raises(RedisClusterException):
            n.initialize()
開發者ID:huangfupeng,項目名稱:redis-py-cluster,代碼行數:14,代碼來源:test_node_manager.py

示例5: test_all_nodes_masters

# 需要導入模塊: from rediscluster.nodemanager import NodeManager [as 別名]
# 或者: from rediscluster.nodemanager.NodeManager import initialize [as 別名]
def test_all_nodes_masters():
    """
    Set a list of nodes with random masters/slaves config and it shold be possible
    to itterate over all of them.
    """
    n = NodeManager(startup_nodes=[{"host": "127.0.0.1", "port": 7000}, {"host": "127.0.0.1", "port": 7001}])
    n.initialize()

    nodes = [node for node in n.nodes.values() if node['server_type'] == 'master']

    for node in n.all_masters():
        assert node in nodes
開發者ID:huangfupeng,項目名稱:redis-py-cluster,代碼行數:14,代碼來源:test_node_manager.py

示例6: test_flush_slots_nodes_cache

# 需要導入模塊: from rediscluster.nodemanager import NodeManager [as 別名]
# 或者: from rediscluster.nodemanager.NodeManager import initialize [as 別名]
def test_flush_slots_nodes_cache():
    """
    Slots cache should already be populated.
    """
    n = NodeManager([{"host": "127.0.0.1", "port": 7000}])
    n.initialize()
    assert len(n.slots) == NodeManager.RedisClusterHashSlots
    assert len(n.nodes) == 6

    n.flush_slots_cache()
    n.flush_nodes_cache()

    assert len(n.slots) == 0
    assert len(n.nodes) == 0
開發者ID:huangfupeng,項目名稱:redis-py-cluster,代碼行數:16,代碼來源:test_node_manager.py

示例7: test_init_with_down_node

# 需要導入模塊: from rediscluster.nodemanager import NodeManager [as 別名]
# 或者: from rediscluster.nodemanager.NodeManager import initialize [as 別名]
def test_init_with_down_node():
    """
    If I can't connect to one of the nodes, everything should still work.
    But if I can't connect to any of the nodes, exception should be thrown.
    """
    def get_redis_link(host, port, decode_responses=False):
        if port == 7000:
            raise ConnectionError('mock connection error for 7000')
        return StrictRedis(host=host, port=port, decode_responses=decode_responses)

    with patch.object(NodeManager, 'get_redis_link', side_effect=get_redis_link):
        n = NodeManager(startup_nodes=[{"host": "127.0.0.1", "port": 7000}])
        with pytest.raises(RedisClusterException) as e:
            n.initialize()
        assert 'Redis Cluster cannot be connected' in unicode(e.value)
開發者ID:Grokzen,項目名稱:redis-py-cluster,代碼行數:17,代碼來源:test_node_manager.py

示例8: test_reset

# 需要導入模塊: from rediscluster.nodemanager import NodeManager [as 別名]
# 或者: from rediscluster.nodemanager.NodeManager import initialize [as 別名]
def test_reset():
    """
    Test that reset method resets variables back to correct default values.
    """
    n = NodeManager(startup_nodes=[{}])
    n.initialize = Mock()
    n.reset()
    assert n.initialize.call_count == 1
開發者ID:Grokzen,項目名稱:redis-py-cluster,代碼行數:10,代碼來源:test_node_manager.py

示例9: test_init_slots_cache_slots_collision

# 需要導入模塊: from rediscluster.nodemanager import NodeManager [as 別名]
# 或者: from rediscluster.nodemanager.NodeManager import initialize [as 別名]
def test_init_slots_cache_slots_collision():
    """
    Test that if 2 nodes do not agree on the same slots setup it should raise an error.
    In this test both nodes will say that the first slots block should be bound to different
     servers.
    """

    n = NodeManager(startup_nodes=[
        {"host": "127.0.0.1", "port": 7000},
        {"host": "127.0.0.1", "port": 7001},
    ])

    def monkey_link(host=None, port=None, *args, **kwargs):
        """
        Helper function to return custom slots cache data from different redis nodes
        """
        if port == 7000:
            result = [[0, 5460, [b'127.0.0.1', 7000], [b'127.0.0.1', 7003]],
                      [5461, 10922, [b'127.0.0.1', 7001], [b'127.0.0.1', 7004]]]

        elif port == 7001:
            result = [[0, 5460, [b'127.0.0.1', 7001], [b'127.0.0.1', 7003]],
                      [5461, 10922, [b'127.0.0.1', 7000], [b'127.0.0.1', 7004]]]

        else:
            result = []

        r = StrictRedisCluster(host=host, port=port, decode_responses=True)
        orig_execute_command = r.execute_command

        def execute_command(*args, **kwargs):
            if args == ("cluster", "slots"):
                return result
            elif args == ('CONFIG GET', 'cluster-require-full-coverage'):
                return {'cluster-require-full-coverage': 'yes'}
            else:
                return orig_execute_command(*args, **kwargs)

        r.execute_command = execute_command
        return r

    n.get_redis_link = monkey_link
    with pytest.raises(RedisClusterException) as ex:
        n.initialize()
    assert unicode(ex.value).startswith("startup_nodes could not agree on a valid slots cache."), unicode(ex.value)
開發者ID:Grokzen,項目名稱:redis-py-cluster,代碼行數:47,代碼來源:test_node_manager.py

示例10: test_reset

# 需要導入模塊: from rediscluster.nodemanager import NodeManager [as 別名]
# 或者: from rediscluster.nodemanager.NodeManager import initialize [as 別名]
def test_reset():
    """
    Test that reset method resets variables back to correct default values.
    """
    n = NodeManager(startup_nodes=[{}])
    n.initialize = Mock()
    n.slots = {"foo": "bar"}
    n.nodes = ["foo", "bar"]
    n.reset()

    assert n.slots == {}
    assert n.nodes == {}
開發者ID:huangfupeng,項目名稱:redis-py-cluster,代碼行數:14,代碼來源:test_node_manager.py

示例11: test_initialize_follow_cluster

# 需要導入模塊: from rediscluster.nodemanager import NodeManager [as 別名]
# 或者: from rediscluster.nodemanager.NodeManager import initialize [as 別名]
def test_initialize_follow_cluster():
    n = NodeManager(nodemanager_follow_cluster=True, startup_nodes=[{'host': '127.0.0.1', 'port': 7000}])
    n.orig_startup_nodes = None
    n.initialize()
開發者ID:Grokzen,項目名稱:redis-py-cluster,代碼行數:6,代碼來源:test_node_manager.py


注:本文中的rediscluster.nodemanager.NodeManager.initialize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。