本文整理汇总了Python中cassandra.cluster.ControlConnection.refresh_schema方法的典型用法代码示例。如果您正苦于以下问题:Python ControlConnection.refresh_schema方法的具体用法?Python ControlConnection.refresh_schema怎么用?Python ControlConnection.refresh_schema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cassandra.cluster.ControlConnection
的用法示例。
在下文中一共展示了ControlConnection.refresh_schema方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ControlConnectionTest
# 需要导入模块: from cassandra.cluster import ControlConnection [as 别名]
# 或者: from cassandra.cluster.ControlConnection import refresh_schema [as 别名]
#.........这里部分代码省略.........
self.connection.local_results[1][0][4] = None
self.control_connection.refresh_node_list_and_token_map()
meta = self.cluster.metadata
self.assertEqual(meta.partitioner, None)
self.assertEqual(meta.token_map, {})
def test_refresh_nodes_and_tokens_add_host(self):
self.connection.peer_results[1].append(
["192.168.1.3", "10.0.0.3", "a", "dc1", "rack1", ["3", "103", "203"]]
)
self.cluster.scheduler.schedule = lambda delay, f, *args, **kwargs: f(*args, **kwargs)
self.control_connection.refresh_node_list_and_token_map()
self.assertEqual(1, len(self.cluster.added_hosts))
self.assertEqual(self.cluster.added_hosts[0].address, "192.168.1.3")
self.assertEqual(self.cluster.added_hosts[0].datacenter, "dc1")
self.assertEqual(self.cluster.added_hosts[0].rack, "rack1")
def test_refresh_nodes_and_tokens_remove_host(self):
del self.connection.peer_results[1][1]
self.control_connection.refresh_node_list_and_token_map()
self.assertEqual(1, len(self.cluster.removed_hosts))
self.assertEqual(self.cluster.removed_hosts[0].address, "192.168.1.2")
def test_refresh_nodes_and_tokens_timeout(self):
def bad_wait_for_responses(*args, **kwargs):
self.assertEqual(kwargs['timeout'], self.control_connection._timeout)
raise OperationTimedOut()
self.connection.wait_for_responses = bad_wait_for_responses
self.control_connection.refresh_node_list_and_token_map()
self.cluster.executor.submit.assert_called_with(self.control_connection._reconnect)
def test_refresh_schema_timeout(self):
def bad_wait_for_responses(*args, **kwargs):
self.assertEqual(kwargs['timeout'], self.control_connection._timeout)
raise OperationTimedOut()
self.connection.wait_for_responses = bad_wait_for_responses
self.control_connection.refresh_schema()
self.cluster.executor.submit.assert_called_with(self.control_connection._reconnect)
def test_handle_topology_change(self):
event = {
'change_type': 'NEW_NODE',
'address': ('1.2.3.4', 9000)
}
self.control_connection._handle_topology_change(event)
self.cluster.scheduler.schedule.assert_called_with(ANY, self.control_connection.refresh_node_list_and_token_map)
event = {
'change_type': 'REMOVED_NODE',
'address': ('1.2.3.4', 9000)
}
self.control_connection._handle_topology_change(event)
self.cluster.scheduler.schedule.assert_called_with(ANY, self.cluster.remove_host, None)
event = {
'change_type': 'MOVED_NODE',
'address': ('1.2.3.4', 9000)
}
self.control_connection._handle_topology_change(event)
self.cluster.scheduler.schedule.assert_called_with(ANY, self.control_connection.refresh_node_list_and_token_map)
def test_handle_status_change(self):
示例2: ControlConnectionTest
# 需要导入模块: from cassandra.cluster import ControlConnection [as 别名]
# 或者: from cassandra.cluster.ControlConnection import refresh_schema [as 别名]
#.........这里部分代码省略.........
self.connection.local_results[1][0][4] = None
self.control_connection.refresh_node_list_and_token_map()
meta = self.cluster.metadata
self.assertEqual(meta.partitioner, None)
self.assertEqual(meta.token_map, {})
def test_refresh_nodes_and_tokens_add_host(self):
self.connection.peer_results[1].append(
["192.168.1.3", "10.0.0.3", "a", "dc1", "rack1", ["3", "103", "203"]]
)
self.cluster.scheduler.schedule = lambda delay, f, *args, **kwargs: f(*args, **kwargs)
self.control_connection.refresh_node_list_and_token_map()
self.assertEqual(1, len(self.cluster.added_hosts))
self.assertEqual(self.cluster.added_hosts[0].address, "192.168.1.3")
self.assertEqual(self.cluster.added_hosts[0].datacenter, "dc1")
self.assertEqual(self.cluster.added_hosts[0].rack, "rack1")
def test_refresh_nodes_and_tokens_remove_host(self):
del self.connection.peer_results[1][1]
self.control_connection.refresh_node_list_and_token_map()
self.assertEqual(1, len(self.cluster.removed_hosts))
self.assertEqual(self.cluster.removed_hosts[0].address, "192.168.1.2")
def test_refresh_nodes_and_tokens_timeout(self):
def bad_wait_for_responses(*args, **kwargs):
self.assertEqual(kwargs['timeout'], self.control_connection._timeout)
raise OperationTimedOut()
self.connection.wait_for_responses = bad_wait_for_responses
self.control_connection.refresh_node_list_and_token_map()
self.cluster.executor.submit.assert_called_with(self.control_connection._reconnect)
def test_refresh_schema_timeout(self):
def bad_wait_for_responses(*args, **kwargs):
self.time.sleep(kwargs['timeout'])
raise OperationTimedOut()
self.connection.wait_for_responses = Mock(side_effect=bad_wait_for_responses)
self.control_connection.refresh_schema()
self.assertEqual(self.connection.wait_for_responses.call_count, self.cluster.max_schema_agreement_wait / self.control_connection._timeout)
self.assertEqual(self.connection.wait_for_responses.call_args[1]['timeout'], self.control_connection._timeout)
def test_handle_topology_change(self):
event = {
'change_type': 'NEW_NODE',
'address': ('1.2.3.4', 9000)
}
self.cluster.scheduler.reset_mock()
self.control_connection._handle_topology_change(event)
self.cluster.scheduler.schedule_unique.assert_called_once_with(ANY, self.control_connection._refresh_nodes_if_not_up, '1.2.3.4')
event = {
'change_type': 'REMOVED_NODE',
'address': ('1.2.3.4', 9000)
}
self.cluster.scheduler.reset_mock()
self.control_connection._handle_topology_change(event)
self.cluster.scheduler.schedule_unique.assert_called_once_with(ANY, self.cluster.remove_host, None)
event = {
'change_type': 'MOVED_NODE',
'address': ('1.2.3.4', 9000)
}
self.cluster.scheduler.reset_mock()