Skip to content

Commit 769181d

Browse files
a-congAlexandra Cong
authored andcommitted
test: add more ddls/dmls to integration test
1 parent fe61fe8 commit 769181d

File tree

2 files changed

+194
-18
lines changed

2 files changed

+194
-18
lines changed
Lines changed: 96 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,31 @@
1-
-- Test DML operations
1+
-- Test mixed DDL and DML operations for sink routing
22
USE source_db;
33

4-
-- Insert more data
4+
-- ============================================
5+
-- DML: INSERT more data
6+
-- ============================================
57
INSERT INTO users VALUES (3, 'Charlie', '[email protected]');
68
INSERT INTO orders VALUES (3, 3, 300.00);
79

8-
-- Update data
10+
-- ============================================
11+
-- DML: UPDATE data
12+
-- ============================================
913
UPDATE users SET email = '[email protected]' WHERE id = 1;
1014
UPDATE orders SET amount = 150.00 WHERE id = 1;
1115

12-
-- Additional DDL: Add a column
16+
-- ============================================
17+
-- DML: DELETE data
18+
-- ============================================
19+
DELETE FROM orders WHERE id = 2;
20+
21+
-- ============================================
22+
-- DDL: ALTER TABLE ADD COLUMN
23+
-- ============================================
1324
ALTER TABLE users ADD COLUMN created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
1425

15-
-- Create a new table (should also be routed)
26+
-- ============================================
27+
-- DDL: CREATE TABLE (new table should be routed)
28+
-- ============================================
1629
CREATE TABLE products (
1730
id INT PRIMARY KEY,
1831
name VARCHAR(100),
@@ -22,6 +35,84 @@ CREATE TABLE products (
2235
INSERT INTO products VALUES (1, 'Widget', 9.99);
2336
INSERT INTO products VALUES (2, 'Gadget', 19.99);
2437

38+
-- ============================================
39+
-- DDL: CREATE TABLE LIKE
40+
-- ============================================
41+
CREATE TABLE products_backup LIKE products;
42+
43+
INSERT INTO products_backup VALUES (1, 'Widget', 9.99);
44+
45+
-- ============================================
46+
-- DDL: ALTER TABLE DROP COLUMN
47+
-- ============================================
48+
ALTER TABLE users DROP COLUMN created_at;
49+
50+
-- ============================================
51+
-- DDL: ALTER TABLE ADD INDEX
52+
-- ============================================
53+
ALTER TABLE orders ADD INDEX idx_user_id (user_id);
54+
55+
-- ============================================
56+
-- DDL: RENAME TABLE
57+
-- ============================================
58+
CREATE TABLE temp_table (
59+
id INT PRIMARY KEY,
60+
value VARCHAR(50)
61+
);
62+
INSERT INTO temp_table VALUES (1, 'test');
63+
64+
RENAME TABLE temp_table TO renamed_table;
65+
66+
-- Verify renamed table works with DML
67+
INSERT INTO renamed_table VALUES (2, 'test2');
68+
UPDATE renamed_table SET value = 'updated' WHERE id = 1;
69+
70+
-- ============================================
71+
-- DDL: TRUNCATE TABLE
72+
-- ============================================
73+
CREATE TABLE truncate_test (
74+
id INT PRIMARY KEY,
75+
data VARCHAR(100)
76+
);
77+
INSERT INTO truncate_test VALUES (1, 'will be truncated');
78+
INSERT INTO truncate_test VALUES (2, 'also truncated');
79+
80+
TRUNCATE TABLE truncate_test;
81+
82+
-- Insert new data after truncate
83+
INSERT INTO truncate_test VALUES (10, 'after truncate');
84+
85+
-- ============================================
86+
-- DDL: DROP TABLE
87+
-- ============================================
88+
CREATE TABLE to_be_dropped (
89+
id INT PRIMARY KEY
90+
);
91+
INSERT INTO to_be_dropped VALUES (1);
92+
93+
DROP TABLE to_be_dropped;
94+
95+
-- ============================================
96+
-- Mixed operations on existing tables
97+
-- ============================================
98+
-- More inserts
99+
INSERT INTO users VALUES (4, 'Diana', '[email protected]');
100+
INSERT INTO users VALUES (5, 'Eve', '[email protected]');
101+
102+
-- Batch update
103+
UPDATE users SET name = CONCAT(name, '_v2') WHERE id IN (3, 4);
104+
105+
-- More deletes
106+
DELETE FROM users WHERE id = 5;
107+
108+
-- Update with multiple columns
109+
UPDATE products SET name = 'Super Widget', price = 12.99 WHERE id = 1;
110+
111+
-- Delete with condition
112+
DELETE FROM products WHERE price < 15.00;
113+
114+
-- ============================================
25115
-- Create finish marker table
116+
-- ============================================
26117
CREATE TABLE finish_mark (id INT PRIMARY KEY);
27118
INSERT INTO finish_mark VALUES (1);

tests/integration_tests/sink_routing/run.sh

Lines changed: 98 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ function run() {
4545
echo "Waiting for routing to complete..."
4646
check_table_exists target_db.finish_mark_routed ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
4747

48+
# ============================================
4849
# Verify schema routing: tables should be in target_db, not source_db
50+
# ============================================
4951
echo "Verifying schema routing..."
5052
check_table_exists target_db.users_routed ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
5153
check_table_exists target_db.orders_routed ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
@@ -55,29 +57,112 @@ function run() {
5557
check_table_not_exists source_db.users ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
5658
check_table_not_exists source_db.orders ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
5759

58-
# Verify data was replicated correctly
59-
echo "Verifying data replication..."
60+
# ============================================
61+
# Verify DDL: CREATE TABLE
62+
# ============================================
63+
echo "Verifying CREATE TABLE routing..."
64+
check_table_exists target_db.products_routed ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
6065

61-
# Check users table data
66+
# ============================================
67+
# Verify DDL: CREATE TABLE LIKE
68+
# ============================================
69+
echo "Verifying CREATE TABLE LIKE routing..."
70+
check_table_exists target_db.products_backup_routed ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
71+
run_sql "SELECT COUNT(*) as cnt FROM target_db.products_backup_routed" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
72+
check_contains "cnt: 1"
73+
74+
# ============================================
75+
# Verify DDL: RENAME TABLE
76+
# ============================================
77+
echo "Verifying RENAME TABLE routing..."
78+
# temp_table was renamed to renamed_table, so only renamed_table_routed should exist
79+
check_table_not_exists target_db.temp_table_routed ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
80+
check_table_exists target_db.renamed_table_routed ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
81+
# Verify DML on renamed table worked
82+
run_sql "SELECT COUNT(*) as cnt FROM target_db.renamed_table_routed" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
83+
check_contains "cnt: 2"
84+
run_sql "SELECT value FROM target_db.renamed_table_routed WHERE id = 1" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
85+
check_contains "updated"
86+
87+
# ============================================
88+
# Verify DDL: TRUNCATE TABLE
89+
# ============================================
90+
echo "Verifying TRUNCATE TABLE routing..."
91+
check_table_exists target_db.truncate_test_routed ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
92+
# After truncate, only 1 row should exist (inserted after truncate)
93+
run_sql "SELECT COUNT(*) as cnt FROM target_db.truncate_test_routed" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
94+
check_contains "cnt: 1"
95+
run_sql "SELECT id FROM target_db.truncate_test_routed" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
96+
check_contains "id: 10"
97+
98+
# ============================================
99+
# Verify DDL: ALTER TABLE ADD/DROP COLUMN
100+
# ============================================
101+
echo "Verifying ALTER TABLE routing..."
102+
# created_at column was added then dropped, so it should NOT exist
103+
run_sql "SHOW COLUMNS FROM target_db.users_routed LIKE 'created_at'" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
104+
check_not_contains "created_at"
105+
106+
# ============================================
107+
# Verify DDL: ALTER TABLE ADD INDEX
108+
# ============================================
109+
echo "Verifying ADD INDEX routing..."
110+
run_sql "SHOW INDEX FROM target_db.orders_routed WHERE Key_name = 'idx_user_id'" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
111+
check_contains "idx_user_id"
112+
113+
# ============================================
114+
# Verify DDL: DROP TABLE
115+
# ============================================
116+
echo "Verifying DROP TABLE routing..."
117+
check_table_not_exists target_db.to_be_dropped_routed ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
118+
119+
# ============================================
120+
# Verify DML: INSERT, UPDATE, DELETE on users
121+
# ============================================
122+
echo "Verifying DML operations on users table..."
123+
# After all operations:
124+
# - Started with id 1,2 from prepare.sql
125+
# - Added id 3,4,5 in test.sql
126+
# - Deleted id 5
127+
# Final count should be 4 (ids: 1, 2, 3, 4)
62128
run_sql "SELECT COUNT(*) as cnt FROM target_db.users_routed" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
63-
check_contains "cnt: 3"
129+
check_contains "cnt: 4"
64130

65-
# Check the updated email
131+
# Check UPDATE worked (email updated for id=1)
66132
run_sql "SELECT email FROM target_db.users_routed WHERE id = 1" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
67133
check_contains "[email protected]"
68134

69-
# Check orders table data
135+
# Check batch UPDATE worked (names updated for ids 3,4)
136+
run_sql "SELECT name FROM target_db.users_routed WHERE id = 3" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
137+
check_contains "Charlie_v2"
138+
run_sql "SELECT name FROM target_db.users_routed WHERE id = 4" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
139+
check_contains "Diana_v2"
140+
141+
# ============================================
142+
# Verify DML: INSERT, UPDATE, DELETE on orders
143+
# ============================================
144+
echo "Verifying DML operations on orders table..."
145+
# Started with id 1,2, added id 3, deleted id 2
146+
# Final count should be 2 (ids: 1, 3)
70147
run_sql "SELECT COUNT(*) as cnt FROM target_db.orders_routed" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
71-
check_contains "cnt: 3"
148+
check_contains "cnt: 2"
72149

73-
# Check products table data
150+
# Check UPDATE worked (amount updated for id=1)
151+
run_sql "SELECT amount FROM target_db.orders_routed WHERE id = 1" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
152+
check_contains "150.00"
153+
154+
# ============================================
155+
# Verify DML: INSERT, UPDATE, DELETE on products
156+
# ============================================
157+
echo "Verifying DML operations on products table..."
158+
# Started with ids 1,2 (prices 9.99 and 19.99)
159+
# Updated id 1 (price to 12.99)
160+
# Deleted where price < 15.00 (deletes id=1 with 12.99, keeps id=2 with 19.99)
161+
# Final count should be 1
74162
run_sql "SELECT COUNT(*) as cnt FROM target_db.products_routed" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
75-
check_contains "cnt: 2"
163+
check_contains "cnt: 1"
76164

77-
# Verify DDL was applied correctly (the ALTER TABLE ADD COLUMN)
78-
echo "Verifying DDL routing..."
79-
run_sql "SHOW COLUMNS FROM target_db.users_routed LIKE 'created_at'" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
80-
check_contains "created_at"
165+
echo "All routing verifications passed!"
81166

82167
cleanup_process $CDC_BINARY
83168
}

0 commit comments

Comments
 (0)