From 92a936e99448a82d9845f1a158d36fe4cf432e83 Mon Sep 17 00:00:00 2001 From: crazycs Date: Thu, 29 Dec 2022 15:38:19 +0800 Subject: [PATCH] dumpling: add foreign key e2e test (#40133) close pingcap/tidb#40227 --- .../e2e_foreign_key/conf/diff_config.toml | 29 ++++++++++++++++++ .../tests/e2e_foreign_key/conf/lightning.toml | 20 +++++++++++++ .../e2e_foreign_key/data/e2e_foreign_key.sql | 8 +++++ dumpling/tests/e2e_foreign_key/run.sh | 30 +++++++++++++++++++ 4 files changed, 87 insertions(+) create mode 100644 dumpling/tests/e2e_foreign_key/conf/diff_config.toml create mode 100644 dumpling/tests/e2e_foreign_key/conf/lightning.toml create mode 100644 dumpling/tests/e2e_foreign_key/data/e2e_foreign_key.sql create mode 100644 dumpling/tests/e2e_foreign_key/run.sh diff --git a/dumpling/tests/e2e_foreign_key/conf/diff_config.toml b/dumpling/tests/e2e_foreign_key/conf/diff_config.toml new file mode 100644 index 0000000000000..634c8416891eb --- /dev/null +++ b/dumpling/tests/e2e_foreign_key/conf/diff_config.toml @@ -0,0 +1,29 @@ +# diff Configuration. + +check-thread-count = 4 + +export-fix-sql = true + +check-struct-only = false + +[task] + output-dir = "./output" + + source-instances = ["mysql1"] + + target-instance = "tidb0" + + target-check-tables = ["e2e_foreign_key.parent", "e2e_foreign_key.child"] + +[data-sources] +[data-sources.mysql1] +host = "127.0.0.1" +port = 3306 +user = "root" +password = "" + +[data-sources.tidb0] +host = "127.0.0.1" +port = 4000 +user = "root" +password = "" diff --git a/dumpling/tests/e2e_foreign_key/conf/lightning.toml b/dumpling/tests/e2e_foreign_key/conf/lightning.toml new file mode 100644 index 0000000000000..e96fdaaf0daeb --- /dev/null +++ b/dumpling/tests/e2e_foreign_key/conf/lightning.toml @@ -0,0 +1,20 @@ +### tidb-lightning config + +[lightning] +server-mode = false +level = "error" +check-requirements = false + +[tikv-importer] +backend = "tidb" +on-duplicate = "error" + +[mydumper] +data-source-dir = "/tmp/dumpling_test_result/sql_res.e2e_foreign_key" + +[tidb] +host = "127.0.0.1" +port = 4000 +user = "root" +password = "" +status-port = 10080 diff --git a/dumpling/tests/e2e_foreign_key/data/e2e_foreign_key.sql b/dumpling/tests/e2e_foreign_key/data/e2e_foreign_key.sql new file mode 100644 index 0000000000000..4b8ff0b1df203 --- /dev/null +++ b/dumpling/tests/e2e_foreign_key/data/e2e_foreign_key.sql @@ -0,0 +1,8 @@ +create database e2e_foreign_key DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; +use e2e_foreign_key; +create table parent (id int key); +create table child (id int key, pid int, constraint fk_1 foreign key (pid) references parent(id)); +insert into parent values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10); +insert into child values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +set foreign_key_checks=0; +insert into child values (100,100); diff --git a/dumpling/tests/e2e_foreign_key/run.sh b/dumpling/tests/e2e_foreign_key/run.sh new file mode 100644 index 0000000000000..99285d627fdf7 --- /dev/null +++ b/dumpling/tests/e2e_foreign_key/run.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# +# Copyright 2020 PingCAP, Inc. Licensed under Apache-2.0. + +set -eu +cur=$(cd `dirname $0`; pwd) + +DB_NAME="e2e_foreign_key" + +# drop database on tidb +export DUMPLING_TEST_PORT=4000 +run_sql "drop database if exists $DB_NAME;" + +# drop database on mysql +export DUMPLING_TEST_PORT=3306 +run_sql "drop database if exists $DB_NAME;" + +# build data on mysql +run_sql_file "$DUMPLING_BASE_NAME/data/e2e_foreign_key.sql" + +# dumping +export DUMPLING_TEST_DATABASE=$DB_NAME +run_dumpling + +cat "$cur/conf/lightning.toml" +# use lightning import data to tidb +run_lightning $cur/conf/lightning.toml + +# check mysql and tidb data +check_sync_diff $cur/conf/diff_config.toml