|
36 | 36 | from cassandra.policies import SimpleConvictionPolicy |
37 | 37 | from cassandra.pool import Host |
38 | 38 | from cassandra.protocol import QueryMessage |
| 39 | +from cassandra.tablets import Tablet |
39 | 40 | from tests.util import assertCountEqual |
40 | 41 | import pytest |
41 | 42 |
|
@@ -441,6 +442,32 @@ def test_bytes_tokens(self): |
441 | 442 | self._get_replicas(BytesToken) |
442 | 443 |
|
443 | 444 |
|
| 445 | +class DropTableMetadataTest(unittest.TestCase): |
| 446 | + """Metadata._drop_table should invalidate tablets for the dropped table.""" |
| 447 | + |
| 448 | + def setUp(self): |
| 449 | + """Set up metadata containing a table with a tablet record.""" |
| 450 | + self.metadata = Metadata() |
| 451 | + keyspace = KeyspaceMetadata("ks", True, "NetworkTopologyStrategy", {"dc1": "1"}) |
| 452 | + keyspace.tables["tb"] = TableMetadata("ks", "tb") |
| 453 | + self.metadata.keyspaces["ks"] = keyspace |
| 454 | + self.metadata._tablets.add_tablet("ks", "tb", Tablet(0, 100, [("host1", 0)])) |
| 455 | + |
| 456 | + def test_drop_table_invalidates_tablets(self): |
| 457 | + """Dropping a known table removes its tablet and table metadata.""" |
| 458 | + self.metadata._drop_table("ks", "tb") |
| 459 | + |
| 460 | + assert self.metadata._tablets.table_has_tablets("ks", "tb") is False |
| 461 | + assert "tb" not in self.metadata.keyspaces["ks"].tables |
| 462 | + |
| 463 | + def test_drop_table_invalidates_tablets_for_unknown_keyspace(self): |
| 464 | + """Dropping a table in an unknown keyspace still removes its tablet metadata.""" |
| 465 | + self.metadata._tablets.add_tablet("unknown", "tb", Tablet(0, 100, [("host1", 0)])) |
| 466 | + self.metadata._drop_table("unknown", "tb") |
| 467 | + |
| 468 | + assert self.metadata._tablets.table_has_tablets("unknown", "tb") is False |
| 469 | + |
| 470 | + |
444 | 471 | class Murmur3TokensTest(unittest.TestCase): |
445 | 472 |
|
446 | 473 | def test_murmur3_init(self): |
|
0 commit comments