|
2 | 2 |
|
3 | 3 | from mock import Mock, ANY |
4 | 4 |
|
| 5 | +from futures import ThreadPoolExecutor |
| 6 | + |
5 | 7 | from cassandra.decoder import ResultMessage |
6 | 8 | from cassandra.cluster import ControlConnection, Cluster, _Scheduler |
7 | 9 | from cassandra.pool import Host |
@@ -42,6 +44,7 @@ def __init__(self): |
42 | 44 | self.added_hosts = [] |
43 | 45 | self.removed_hosts = [] |
44 | 46 | self.scheduler = Mock(spec=_Scheduler) |
| 47 | + self.executor = Mock(spec=ThreadPoolExecutor) |
45 | 48 |
|
46 | 49 | def add_host(self, address, signal=False): |
47 | 50 | host = Host(address, SimpleConvictionPolicy) |
@@ -257,3 +260,30 @@ def test_handle_status_change(self): |
257 | 260 | self.control_connection._handle_status_change(event) |
258 | 261 | host = self.cluster.metadata.hosts['192.168.1.0'] |
259 | 262 | self.cluster.scheduler.schedule.assert_called_with(ANY, host.monitor.set_down) |
| 263 | + |
| 264 | + def test_handle_schema_change(self): |
| 265 | + |
| 266 | + for change_type in ('CREATED', 'DROPPED'): |
| 267 | + event = { |
| 268 | + 'change_type': change_type, |
| 269 | + 'keyspace': 'ks1', |
| 270 | + 'table': 'table1' |
| 271 | + } |
| 272 | + self.control_connection._handle_schema_change(event) |
| 273 | + self.cluster.executor.submit.assert_called_with(self.control_connection.refresh_schema, 'ks1') |
| 274 | + |
| 275 | + event['table'] = None |
| 276 | + self.control_connection._handle_schema_change(event) |
| 277 | + self.cluster.executor.submit.assert_called_with(self.control_connection.refresh_schema, None) |
| 278 | + |
| 279 | + event = { |
| 280 | + 'change_type': 'UPDATED', |
| 281 | + 'keyspace': 'ks1', |
| 282 | + 'table': 'table1' |
| 283 | + } |
| 284 | + self.control_connection._handle_schema_change(event) |
| 285 | + self.cluster.executor.submit.assert_called_with(self.control_connection.refresh_schema, 'ks1', 'table1') |
| 286 | + |
| 287 | + event['table'] = None |
| 288 | + self.control_connection._handle_schema_change(event) |
| 289 | + self.cluster.executor.submit.assert_called_with(self.control_connection.refresh_schema, 'ks1', None) |
0 commit comments