forked from selectdb/ccr-syncer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add table sync alias case (selectdb#177)
- Loading branch information
Showing
1 changed file
with
97 additions
and
0 deletions.
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
regression-test/suites/table-sync-with-alias/test_lightning_schema_change.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// 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_lightning_schema_change") { | ||
def helper = new GroovyShell(new Binding(['suite': delegate])) | ||
.evaluate(new File("${context.config.suitePath}/../common", "helper.groovy")) | ||
|
||
def tableName = "test_add_column_" + UUID.randomUUID().toString().replace("-", "") | ||
def test_num = 0 | ||
def insert_num = 5 | ||
|
||
def exist = { res -> Boolean | ||
return res.size() != 0 | ||
} | ||
|
||
def has_count = { count -> | ||
return { res -> Boolean | ||
res.size() == count | ||
} | ||
} | ||
|
||
sql "DROP TABLE IF EXISTS ${tableName}" | ||
sql """ | ||
CREATE TABLE if NOT EXISTS ${tableName} | ||
( | ||
`test` INT, | ||
`id` INT, | ||
`value` INT | ||
) | ||
ENGINE=OLAP | ||
UNIQUE KEY(`test`, `id`) | ||
DISTRIBUTED BY HASH(id) BUCKETS 1 | ||
PROPERTIES ( | ||
"replication_allocation" = "tag.location.default: 1", | ||
"binlog.enable" = "true" | ||
) | ||
""" | ||
|
||
def values = []; | ||
for (int index = 0; index < insert_num; index++) { | ||
values.add("(${test_num}, ${index}, ${index})") | ||
} | ||
sql """ | ||
INSERT INTO ${tableName} VALUES ${values.join(",")} | ||
""" | ||
sql "sync" | ||
|
||
helper.ccrJobCreate(tableName) | ||
|
||
assertTrue(helper.checkRestoreFinishTimesOf("${tableName}", 30)) | ||
|
||
logger.info("=== Test 1: add value column after last key ===") | ||
// binlog type: MODIFY_TABLE_ADD_OR_DROP_COLUMNS, binlog data: | ||
// { | ||
// "dbId": 11049, | ||
// "tableId": 11058, | ||
// "indexSchemaMap": { | ||
// "11101": [...] | ||
// }, | ||
// "indexes": [], | ||
// "jobId": 11117, | ||
// "rawSql": "ALTER TABLE `regression_test_schema_change`.`tbl_add_column6ab3b514b63c4368aa0a0149da0acabd` ADD COLUMN `first_value` int NULL DEFAULT \"0\" COMMENT \"\" AFTER `last`" | ||
// } | ||
sql """ | ||
ALTER TABLE ${tableName} | ||
ADD COLUMN `first_value` INT DEFAULT "0" AFTER `id` | ||
""" | ||
sql "sync" | ||
|
||
assertTrue(helper.checkShowTimesOf(""" | ||
SHOW ALTER TABLE COLUMN | ||
FROM ${context.dbName} | ||
WHERE TableName = "${tableName}" AND State = "FINISHED" | ||
""", | ||
has_count(1), 30)) | ||
|
||
def has_column_first_value = { res -> Boolean | ||
// Field == 'first_value' && 'Key' == 'NO' | ||
return res[2][0] == 'first_value' && (res[2][3] == 'NO' || res[2][3] == 'false') | ||
} | ||
|
||
assertTrue(helper.checkShowTimesOf("SHOW COLUMNS FROM `${tableName}`", has_column_first_value, 60, "target_sql")) | ||
} | ||
|