From 2fd86b3959e355906560884221181fb361c1244a Mon Sep 17 00:00:00 2001 From: wyxxxcat <1520358997@qq.com> Date: Wed, 6 Nov 2024 22:31:41 +0800 Subject: [PATCH] 1 --- regression-test/common/helper.groovy | 20 ++-- .../test_db_sync_create_table_relay.groovy | 95 +++++++++++++++++++ 2 files changed, 105 insertions(+), 10 deletions(-) create mode 100644 regression-test/suites/db_sync_create_table_relay/test_db_sync_create_table_relay.groovy diff --git a/regression-test/common/helper.groovy b/regression-test/common/helper.groovy index 32692d6a..6bf74208 100644 --- a/regression-test/common/helper.groovy +++ b/regression-test/common/helper.groovy @@ -34,8 +34,8 @@ class Helper { return UUID.randomUUID().toString().replace("-", "") } - void ccrJobDelete(table = "") { - def bodyJson = suite.get_ccr_body "${table}" + void ccrJobDelete(table = "", db = "") { + def bodyJson = suite.get_ccr_body(table, db) suite.httpTest { uri "/delete" endpoint syncerAddress @@ -44,8 +44,8 @@ class Helper { } } - void ccrJobCreate(table = "") { - def bodyJson = suite.get_ccr_body "${table}" + void ccrJobCreate(table = "", db = "") { + def bodyJson = suite.get_ccr_body(table, db) suite.httpTest { uri "/create_ccr" endpoint syncerAddress @@ -70,8 +70,8 @@ class Helper { } } - void ccrJobPause(table = "") { - def bodyJson = suite.get_ccr_body "${table}" + void ccrJobPause(table = "", db = "") { + def bodyJson = suite.get_ccr_body(table, db) suite.httpTest { uri "/pause" endpoint syncerAddress @@ -80,8 +80,8 @@ class Helper { } } - void ccrJobResume(table = "") { - def bodyJson = suite.get_ccr_body "${table}" + void ccrJobResume(table = "", db = "") { + def bodyJson = suite.get_ccr_body(table, db) suite.httpTest { uri "/resume" endpoint syncerAddress @@ -90,8 +90,8 @@ class Helper { } } - void ccrJobDesync(table = "") { - def bodyJson = suite.get_ccr_body "${table}" + void ccrJobDesync(table = "", db = "") { + def bodyJson = suite.get_ccr_body(table, db) suite.httpTest { uri "/desync" endpoint syncerAddress diff --git a/regression-test/suites/db_sync_create_table_relay/test_db_sync_create_table_relay.groovy b/regression-test/suites/db_sync_create_table_relay/test_db_sync_create_table_relay.groovy new file mode 100644 index 00000000..90150b1a --- /dev/null +++ b/regression-test/suites/db_sync_create_table_relay/test_db_sync_create_table_relay.groovy @@ -0,0 +1,95 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +suite("test_db_sync_create_table_relay") { + def helper = new GroovyShell(new Binding(['suite': delegate])) + .evaluate(new File("${context.config.suitePath}/../common", "helper.groovy")) + + def tableName = "test_db_sync_create_table_relay_table_1" + + def dbNameOrigin = context.dbName + def dbNameRelay = "TEST_" + context.dbName + + def test_num = 0 + def insert_num = 10 + + def exist = { res -> Boolean + return res.size() != 0 + } + + helper.enableDbBinlog() + + sql "DROP TABLE IF EXISTS ${dbNameOrigin}.${tableName}" + sql "DROP TABLE IF EXISTS ${dbNameRelay}.${tableName}" + + sql """ + CREATE TABLE if NOT EXISTS ${tableName} + ( + `test` INT, + `id` INT + ) + UNIQUE KEY(`test`, `id`) + DISTRIBUTED BY HASH(id) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "binlog.enable" = "true" + ) + """ + + helper.ccrJobDelete(tableName, dbNameOrigin) + helper.ccrJobCreate(tableName, dbNameOrigin) + + assertTrue(helper.checkRestoreFinishTimesOf("${tableName}", 60)) + + for (int index = 0; index < insert_num; index++) { + sql """ + INSERT INTO ${tableName} VALUES (${test_num}, ${index}) + """ + } + + sql "sync" + + logger.info("=== Test 1: Resume and check table ===") + + helper.ccrJobResume(tableName, dbNameOrigin) + + assertTrue(helper.checkShowTimesOf(""" SHOW TABLES LIKE "${tableName}" """, exist, 60, "target")) + + helper.ccrJobPause() + + logger.info("=== Test 2: Delete old job and create new job ===") + + helper.ccrJobDelete(tableName, dbNameOrigin) + + helper.ccrJobCreate(tableName, dbNameRelay) + + assertTrue(helper.checkRestoreFinishTimesOf("${tableName}", 60)) + + sql "sync" + + helper.ccrJobPause() + + logger.info("=== Test 3: Resume and Check new table ===") + + helper.ccrJobResume(tableName, dbNameRelay) + + assertTrue(helper.checkShowTimesOf(""" SHOW TABLES LIKE "${tableName}" """, exist, 60, "target")) + + result = sql "select * from ${dbNameRelay}.${tableName}" + + assertEquals(insert_num, result.size()) +} \ No newline at end of file