Skip to content

Commit 0255288

Browse files
committed
Add tests for handle_schema_change
1 parent 0682d28 commit 0255288

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

tests/unit/test_control_connection.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from mock import Mock, ANY
44

5+
from futures import ThreadPoolExecutor
6+
57
from cassandra.decoder import ResultMessage
68
from cassandra.cluster import ControlConnection, Cluster, _Scheduler
79
from cassandra.pool import Host
@@ -42,6 +44,7 @@ def __init__(self):
4244
self.added_hosts = []
4345
self.removed_hosts = []
4446
self.scheduler = Mock(spec=_Scheduler)
47+
self.executor = Mock(spec=ThreadPoolExecutor)
4548

4649
def add_host(self, address, signal=False):
4750
host = Host(address, SimpleConvictionPolicy)
@@ -257,3 +260,30 @@ def test_handle_status_change(self):
257260
self.control_connection._handle_status_change(event)
258261
host = self.cluster.metadata.hosts['192.168.1.0']
259262
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

Comments
 (0)