forked from apache/cassandra-dtest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepared_statements_test.py
49 lines (36 loc) · 1.52 KB
/
prepared_statements_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import logging
from cassandra import InvalidRequest
from dtest import Tester
logger = logging.getLogger(__name__)
KEYSPACE = "foo"
class TestPreparedStatements(Tester):
"""
Tests for pushed native protocol notification from Cassandra.
"""
def test_dropped_index(self):
"""
Prepared statements using dropped indexes should be handled correctly
"""
self.cluster.populate(1).start()
node = list(self.cluster.nodes.values())[0]
session = self.patient_cql_connection(node)
session.execute("""
CREATE KEYSPACE IF NOT EXISTS %s
WITH replication = { 'class': 'SimpleStrategy', 'replication_factor': '1' }
""" % KEYSPACE)
session.set_keyspace(KEYSPACE)
session.execute("CREATE TABLE IF NOT EXISTS mytable (a int PRIMARY KEY, b int)")
session.execute("CREATE INDEX IF NOT EXISTS bindex ON mytable(b)")
insert_statement = session.prepare("INSERT INTO mytable (a, b) VALUES (?, ?)")
for i in range(10):
session.execute(insert_statement, (i, 0))
query_statement = session.prepare("SELECT * FROM mytable WHERE b=?")
print("Number of matching rows:", len(list(session.execute(query_statement, (0,)))))
session.execute("DROP INDEX bindex")
try:
print("Executing prepared statement with dropped index...")
session.execute(query_statement, (0,))
except InvalidRequest as ir:
print(ir)
except Exception:
raise