Key Canonical Party's topics by the entity identifier
Every inbound and outbound topic now declares the column producers must key messages by, and the stream tests assert it: a topic has three partitions, and only messages sharing a key share a partition, so without the key two changes to one party can be applied out of order. Verified on digital-core: 65 smoke checks, 100 unit tests. Source-aligned products on the Integration Bus publish to these topics under the same rule. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
dd096ee4dc
commit
5a429ce175
4 files changed
+34
-5
No files matched your search
@@ -43,15 +43,25 @@ def test_record_round_trip(dp):
|
||||
refused = dp.sql_error(f"INSERT INTO {schema}.{table} ({columns}) VALUES ({values})")
|
||||
assert refused is None, f"the ODS would refuse the round-trip record, so it is not published: {refused}"
|
||||
|
||||
inbound = next(t for t in dp.product.topics if t.table == table and t.role == "publish-input")
|
||||
assert inbound.key, f"{inbound.name} declares no key in product.yaml; producers cannot keep changes in order"
|
||||
|
||||
try:
|
||||
# Publish input -> Flink -> ODS
|
||||
dp.publish(dp.topic(table, "publish-input"), [record])
|
||||
# Publish input -> Flink -> ODS, keyed as the contract requires
|
||||
dp.publish(inbound.name, [record], key_field=inbound.key)
|
||||
dp.eventually(lambda: contains(record, (dp.sql(f"SELECT * FROM {schema}.{table} WHERE {where}") or [None])[0]))
|
||||
|
||||
# ODS -> Flink CDC -> subscribe output, and ODS -> pg_duckpipe -> lake
|
||||
dp.eventually(lambda: contains(record, dp.latest(outbound).get(record_key)))
|
||||
dp.eventually(lambda: dp.trino(f"SELECT count(*) AS n FROM {lake} WHERE CAST({key} AS varchar) = '{record_key}'") == [{"n": 1}])
|
||||
|
||||
# Two more, published in order under the same key: one partition, so the last one wins
|
||||
column, value = next(iter(update.items()))
|
||||
ordered = [dict(record, **{column: f"{value} first"}), dict(record, **{column: f"{value} second"})]
|
||||
dp.publish(inbound.name, ordered, key_field=inbound.key)
|
||||
dp.eventually(lambda: (dp.sql(f"SELECT {column} FROM {schema}.{table} WHERE {where}") or [{}])[0].get(column)
|
||||
== f"{value} second")
|
||||
|
||||
# CRUD API update -> subscribe output and lake
|
||||
assignments = ", ".join(f'{camel(c)}: "{v}"' for c, v in update.items())
|
||||
data = dp.graphql(
|
||||
@@ -60,7 +70,6 @@ def test_record_round_trip(dp):
|
||||
)
|
||||
assert data[f"update{pascal(table)}Collection"]["affectedCount"] == 1
|
||||
dp.eventually(lambda: contains(update, dp.latest(outbound).get(record_key)))
|
||||
column, value = next(iter(update.items()))
|
||||
dp.eventually(lambda: dp.trino(f"SELECT CAST({column} AS varchar) AS v FROM {lake} WHERE CAST({key} AS varchar) = '{record_key}'") == [{"v": str(value)}])
|
||||
|
||||
# CRUD API delete -> tombstone on subscribe output, row gone from the lake
|
||||
|
||||
Reference in new issue
Block a user