def test_all_slots_covered(): decoded_node_info_ok = list(parse_cluster_nodes( RAW_NODE_INFO_DATA_OK.decode('utf-8'), encoding='utf-8' )) manager = ClusterNodesManager.create(decoded_node_info_ok) assert manager.all_slots_covered manager = ClusterNodesManager.create(NODE_INFO_DATA_FAIL) assert not manager.all_slots_covered decoded_node_info_ok[2]['slots'] = list(decoded_node_info_ok[2]['slots']) del decoded_node_info_ok[2]['slots'][0] manager = ClusterNodesManager.create(decoded_node_info_ok) assert not manager.all_slots_covered
def test_all_slots_covered(): decoded_node_info_ok = list( parse_cluster_nodes(RAW_NODE_INFO_DATA_OK.decode('utf-8'), encoding='utf-8')) manager = ClusterNodesManager.create(decoded_node_info_ok) assert manager.all_slots_covered manager = ClusterNodesManager.create(NODE_INFO_DATA_FAIL) assert not manager.all_slots_covered decoded_node_info_ok[2]['slots'] = list(decoded_node_info_ok[2]['slots']) del decoded_node_info_ok[2]['slots'][0] manager = ClusterNodesManager.create(decoded_node_info_ok) assert not manager.all_slots_covered
def test_get_node_by_address(): manager = ClusterNodesManager.create(NODE_INFO_DATA_FAIL) node = manager.get_node_by_address(('127.0.0.1', 30004)) assert node.id == '07c37dfeb235213a872192d90877d0cd55635b91' no_node = manager.get_node_by_address('xxx') assert no_node is None
def test_in_range(): manager = ClusterNodesManager.create(NODE_INFO_DATA_FAIL) master = manager.nodes[5] assert master.in_range(0) assert master.in_range(5460) assert not master.in_range(5461) master.slots = tuple() assert not master.in_range(0)
def test_cluster_node(): manager = ClusterNodesManager.create(NODE_INFO_DATA_FAIL) node1 = manager.nodes[0] assert not node1.is_master assert node1.is_slave assert node1.address == ('127.0.0.1', 30004) assert not node1.is_alive node2 = manager.nodes[2] assert node2.is_master assert not node2.is_slave assert node2.is_alive assert node1 == manager.get_node_by_id(node1.id)
def test_determine_slot_multiple(): manager = ClusterNodesManager.create(NODE_INFO_DATA_OK) assert manager.determine_slot('{key}:1', '{key}:2') == 12539
def test_determine_slot(): manager = ClusterNodesManager.create(NODE_INFO_DATA_OK) assert manager.determine_slot('key') == 12539 with pytest.raises(TypeError): manager.determine_slot(None)
def test_node_count(): manager = ClusterNodesManager.create(NODE_INFO_DATA_FAIL) assert manager.nodes_count == 4 assert manager.masters_count == 2 assert manager.slaves_count == 2
def test_alive_nodes(): manager = ClusterNodesManager.create(NODE_INFO_DATA_FAIL) assert manager.alive_nodes == manager.nodes[2:]
def test_create(): manager = ClusterNodesManager.create(NODE_INFO_DATA_FAIL) assert len(manager.nodes) == 6 assert all(isinstance(node, ClusterNode) for node in manager.nodes)
def test_determine_slot_multiple_different(): manager = ClusterNodesManager.create(NODE_INFO_DATA_OK) with pytest.raises(RedisClusterError): manager.determine_slot('key:1', 'key:2')
def test_key_slot(): assert ClusterNodesManager.key_slot(SLOT_ZERO_KEY) == 0 assert ClusterNodesManager.key_slot('key') == KEY_KEY_SLOT assert ClusterNodesManager.key_slot(b'key') == KEY_KEY_SLOT