Skip to content

Commit 55ebb8b

Browse files
committed
Improve metadata bwc test for Logical Replication
1 parent 4781e62 commit 55ebb8b

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tests/bwc/test_rolling_upgrade.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import time
12
import unittest
23
from crate.client import connect
34
from crate.client.exceptions import ProgrammingError
@@ -88,6 +89,10 @@ def _test_rolling_upgrade(self, path, nodes):
8889
}
8990
cluster = self._new_cluster(path.from_version, nodes, settings=settings)
9091
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()
9196
with connect(cluster.node().http_url, error_trace=True) as conn:
9297
c = conn.cursor()
9398
c.execute("create user arthur with (password = 'secret')")
@@ -152,6 +157,19 @@ def _test_rolling_upgrade(self, path, nodes):
152157
# Add the shards of the new partition primaries
153158
expected_active_shards += shards
154159

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+
155173
for idx, node in enumerate(cluster):
156174
# Enforce an old version node be a handler to make sure that an upgraded node can serve 'select *' from an old version node.
157175
# 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):
282300
c.execute("select version['created'] from information_schema.table_partitions where table_name = 't3' and values['a'] = ?", [idx])
283301
self.assertEqual(c.fetchall(), [[partition_version]])
284302

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+
285325
# Finally validate that all shards (primaries and replicas) of all partitions are started
286326
# and writes into the partitioned table while upgrading were successful
287327
with connect(cluster.node().http_url, error_trace=True) as conn:

0 commit comments

Comments
 (0)