本文整理汇总了Python中cassandra.cluster.ControlConnection._handle_status_change方法的典型用法代码示例。如果您正苦于以下问题:Python ControlConnection._handle_status_change方法的具体用法?Python ControlConnection._handle_status_change怎么用?Python ControlConnection._handle_status_change使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cassandra.cluster.ControlConnection
的用法示例。
在下文中一共展示了ControlConnection._handle_status_change方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_refresh_disabled
# 需要导入模块: from cassandra.cluster import ControlConnection [as 别名]
# 或者: from cassandra.cluster.ControlConnection import _handle_status_change [as 别名]
def test_refresh_disabled(self):
cluster = MockCluster()
schema_event = {"change_type": "CREATED", "keyspace": "ks1", "table": "table1"}
status_event = {"change_type": "UP", "address": ("1.2.3.4", 9000)}
topo_event = {"change_type": "MOVED_NODE", "address": ("1.2.3.4", 9000)}
cc_no_schema_refresh = ControlConnection(cluster, 1, -1, 0)
cluster.scheduler.reset_mock()
# no call on schema refresh
cc_no_schema_refresh._handle_schema_change(schema_event)
self.assertFalse(cluster.scheduler.schedule.called)
self.assertFalse(cluster.scheduler.schedule_unique.called)
# topo and status changes as normal
cc_no_schema_refresh._handle_status_change(status_event)
cc_no_schema_refresh._handle_topology_change(topo_event)
cluster.scheduler.schedule_unique.assert_has_calls(
[
call(ANY, cc_no_schema_refresh.refresh_node_list_and_token_map),
call(ANY, cc_no_schema_refresh.refresh_node_list_and_token_map),
]
)
cc_no_topo_refresh = ControlConnection(cluster, 1, 0, -1)
cluster.scheduler.reset_mock()
# no call on topo refresh
cc_no_topo_refresh._handle_topology_change(topo_event)
self.assertFalse(cluster.scheduler.schedule.called)
self.assertFalse(cluster.scheduler.schedule_unique.called)
# schema and status change refresh as normal
cc_no_topo_refresh._handle_status_change(status_event)
cc_no_topo_refresh._handle_schema_change(schema_event)
cluster.scheduler.schedule_unique.assert_has_calls(
[
call(ANY, cc_no_topo_refresh.refresh_node_list_and_token_map),
call(
0.0,
cc_no_topo_refresh.refresh_schema,
schema_event["keyspace"],
schema_event["table"],
None,
None,
None,
),
]
)
示例2: test_refresh_disabled
# 需要导入模块: from cassandra.cluster import ControlConnection [as 别名]
# 或者: from cassandra.cluster.ControlConnection import _handle_status_change [as 别名]
def test_refresh_disabled(self):
cluster = MockCluster()
schema_event = {
'target_type': SchemaTargetType.TABLE,
'change_type': SchemaChangeType.CREATED,
'keyspace': 'ks1',
'table': 'table1'
}
status_event = {
'change_type': 'UP',
'address': ('1.2.3.4', 9000)
}
topo_event = {
'change_type': 'MOVED_NODE',
'address': ('1.2.3.4', 9000)
}
cc_no_schema_refresh = ControlConnection(cluster, 1, -1, 0, 0)
cluster.scheduler.reset_mock()
# no call on schema refresh
cc_no_schema_refresh._handle_schema_change(schema_event)
self.assertFalse(cluster.scheduler.schedule.called)
self.assertFalse(cluster.scheduler.schedule_unique.called)
# topo and status changes as normal
cc_no_schema_refresh._handle_status_change(status_event)
cc_no_schema_refresh._handle_topology_change(topo_event)
cluster.scheduler.schedule_unique.assert_has_calls([call(ANY, cc_no_schema_refresh.refresh_node_list_and_token_map),
call(ANY, cc_no_schema_refresh._refresh_nodes_if_not_up, '1.2.3.4')])
cc_no_topo_refresh = ControlConnection(cluster, 1, 0, -1, 0)
cluster.scheduler.reset_mock()
# no call on topo refresh
cc_no_topo_refresh._handle_topology_change(topo_event)
self.assertFalse(cluster.scheduler.schedule.called)
self.assertFalse(cluster.scheduler.schedule_unique.called)
# schema and status change refresh as normal
cc_no_topo_refresh._handle_status_change(status_event)
cc_no_topo_refresh._handle_schema_change(schema_event)
cluster.scheduler.schedule_unique.assert_has_calls([call(ANY, cc_no_topo_refresh.refresh_node_list_and_token_map),
call(0.0, cc_no_topo_refresh.refresh_schema,
**schema_event)])
示例3: ControlConnectionTest
# 需要导入模块: from cassandra.cluster import ControlConnection [as 别名]
# 或者: from cassandra.cluster.ControlConnection import _handle_status_change [as 别名]
#.........这里部分代码省略.........
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):
event = {
'change_type': 'UP',
'address': ('1.2.3.4', 9000)
}
self.control_connection._handle_status_change(event)
self.cluster.scheduler.schedule.assert_called_with(ANY, self.control_connection.refresh_node_list_and_token_map)
# do the same with a known Host
event = {
'change_type': 'UP',
'address': ('192.168.1.0', 9000)
}
self.control_connection._handle_status_change(event)
host = self.cluster.metadata.hosts['192.168.1.0']
self.cluster.scheduler.schedule.assert_called_with(ANY, self.cluster.on_up, host)
self.cluster.scheduler.schedule.reset_mock()
event = {
'change_type': 'DOWN',
'address': ('1.2.3.4', 9000)
}
self.control_connection._handle_status_change(event)
self.assertFalse(self.cluster.scheduler.schedule.called)
# do the same with a known Host
event = {
'change_type': 'DOWN',
'address': ('192.168.1.0', 9000)
}
self.control_connection._handle_status_change(event)
host = self.cluster.metadata.hosts['192.168.1.0']
self.assertIs(host, self.cluster.down_host)
def test_handle_schema_change(self):
for change_type in ('CREATED', 'DROPPED'):
event = {
'change_type': change_type,
'keyspace': 'ks1',
'table': 'table1'
}
self.control_connection._handle_schema_change(event)
self.cluster.executor.submit.assert_called_with(self.control_connection.refresh_schema, 'ks1')
event['table'] = None
self.control_connection._handle_schema_change(event)
self.cluster.executor.submit.assert_called_with(self.control_connection.refresh_schema, None)
event = {
'change_type': 'UPDATED',
'keyspace': 'ks1',
'table': 'table1'
}
self.control_connection._handle_schema_change(event)
self.cluster.executor.submit.assert_called_with(self.control_connection.refresh_schema, 'ks1', 'table1')
event['table'] = None
self.control_connection._handle_schema_change(event)
self.cluster.executor.submit.assert_called_with(self.control_connection.refresh_schema, 'ks1', None)
示例4: ControlConnectionTest
# 需要导入模块: from cassandra.cluster import ControlConnection [as 别名]
# 或者: from cassandra.cluster.ControlConnection import _handle_status_change [as 别名]
#.........这里部分代码省略.........
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()
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')
def test_handle_status_change(self):
event = {
'change_type': 'UP',
'address': ('1.2.3.4', 9000)
}
self.cluster.scheduler.reset_mock()
self.control_connection._handle_status_change(event)
self.cluster.scheduler.schedule_unique.assert_called_once_with(ANY, self.control_connection.refresh_node_list_and_token_map)
# do the same with a known Host
event = {
'change_type': 'UP',
'address': ('192.168.1.0', 9000)
}
self.cluster.scheduler.reset_mock()
self.control_connection._handle_status_change(event)
host = self.cluster.metadata.hosts['192.168.1.0']
self.cluster.scheduler.schedule_unique.assert_called_once_with(ANY, self.cluster.on_up, host)
self.cluster.scheduler.schedule.reset_mock()
event = {
'change_type': 'DOWN',
'address': ('1.2.3.4', 9000)
}
self.control_connection._handle_status_change(event)
self.assertFalse(self.cluster.scheduler.schedule.called)
# do the same with a known Host
event = {
'change_type': 'DOWN',
'address': ('192.168.1.0', 9000)
}
self.control_connection._handle_status_change(event)