|
| 1 | +import time |
1 | 2 | import unittest
|
2 | 3 | from crate.client import connect
|
3 | 4 | from crate.client.exceptions import ProgrammingError
|
@@ -88,6 +89,10 @@ def _test_rolling_upgrade(self, path, nodes):
|
88 | 89 | }
|
89 | 90 | cluster = self._new_cluster(path.from_version, nodes, settings=settings)
|
90 | 91 | cluster.start()
|
| 92 | + replica_cluster = None |
| 93 | + if int(path.from_version.split('.')[0]) >= 5 and int(path.from_version.split('.')[1]) >= 10: |
| 94 | + replica_cluster = self._new_cluster(path.from_version, 1, settings=settings, explicit_discovery=False) |
| 95 | + replica_cluster.start() |
91 | 96 | with connect(cluster.node().http_url, error_trace=True) as conn:
|
92 | 97 | c = conn.cursor()
|
93 | 98 | c.execute("create user arthur with (password = 'secret')")
|
@@ -152,6 +157,19 @@ def _test_rolling_upgrade(self, path, nodes):
|
152 | 157 | # Add the shards of the new partition primaries
|
153 | 158 | expected_active_shards += shards
|
154 | 159 |
|
| 160 | + # Set up tables for logical replications |
| 161 | + if int(path.from_version.split('.')[0]) >= 5 and int(path.from_version.split('.')[1]) >= 10: |
| 162 | + c.execute("create table doc.x (a int) clustered into 1 shards with (number_of_replicas=0)") |
| 163 | + expected_active_shards += 1 |
| 164 | + c.execute("create publication p for table doc.x") |
| 165 | + with connect(replica_cluster.node().http_url, error_trace=True) as replica_conn: |
| 166 | + rc = replica_conn.cursor() |
| 167 | + rc.execute("create table doc.rx (a int) clustered into 1 shards with (number_of_replicas=0)") |
| 168 | + rc.execute("create publication rp for table doc.rx") |
| 169 | + rc.execute(f"create subscription rs connection 'crate://localhost:{cluster.node().addresses.transport.port}?user=crate&sslmode=sniff' publication p") |
| 170 | + c.execute(f"create subscription s connection 'crate://localhost:{replica_cluster.node().addresses.transport.port}?user=crate&sslmode=sniff' publication rp") |
| 171 | + expected_active_shards += 1 |
| 172 | + |
155 | 173 | for idx, node in enumerate(cluster):
|
156 | 174 | # Enforce an old version node be a handler to make sure that an upgraded node can serve 'select *' from an old version node.
|
157 | 175 | # Otherwise upgraded node simply requests N-1 columns from old version with N columns and it always works.
|
@@ -282,6 +300,28 @@ def _test_rolling_upgrade(self, path, nodes):
|
282 | 300 | c.execute("select version['created'] from information_schema.table_partitions where table_name = 't3' and values['a'] = ?", [idx])
|
283 | 301 | self.assertEqual(c.fetchall(), [[partition_version]])
|
284 | 302 |
|
| 303 | + # Ensure logical replications works |
| 304 | + if int(path.from_version.split('.')[0]) >= 5 and int(path.from_version.split('.')[1]) >= 10: |
| 305 | + with connect(replica_cluster.node().http_url, error_trace=True) as replica_conn: |
| 306 | + rc = replica_conn.cursor() |
| 307 | + #wait_for_active_shards(c) |
| 308 | + #wait_for_active_shards(rc) |
| 309 | + time.sleep(10) |
| 310 | + # Ensure publishing to remote cluster works |
| 311 | + rc.execute("select count(*) from doc.x") |
| 312 | + count = rc.fetchall()[0][0] |
| 313 | + c.execute("insert into doc.x values (1)") |
| 314 | + time.sleep(10) |
| 315 | + rc.execute("select count(*) from doc.x") |
| 316 | + self.assertEqual(rc.fetchall()[0][0], count + 1) |
| 317 | + # Ensure subscription from remote cluster works |
| 318 | + c.execute("select count(*) from doc.rx") |
| 319 | + count = c.fetchall()[0][0] |
| 320 | + rc.execute("insert into doc.rx values (1)") |
| 321 | + time.sleep(10) |
| 322 | + c.execute("select count(*) from doc.rx") |
| 323 | + self.assertEqual(c.fetchall()[0][0], count + 1) |
| 324 | + |
285 | 325 | # Finally validate that all shards (primaries and replicas) of all partitions are started
|
286 | 326 | # and writes into the partitioned table while upgrading were successful
|
287 | 327 | with connect(cluster.node().http_url, error_trace=True) as conn:
|
|
0 commit comments