[test](regression) Add backup/restore DB case (#26312)
This commit is contained in:
@ -56,7 +56,7 @@ suite("test_backup_restore", "backup_restore") {
|
||||
Thread.sleep(3000)
|
||||
}
|
||||
|
||||
snapshot = syncer.getSnapshotTimestamp(repoName, snapshotName)
|
||||
def snapshot = syncer.getSnapshotTimestamp(repoName, snapshotName)
|
||||
assertTrue(snapshot != null)
|
||||
|
||||
sql "TRUNCATE TABLE ${dbName}.${tableName}"
|
||||
|
||||
@ -57,7 +57,7 @@ suite("test_backup_restore_alias", "backup_restore") {
|
||||
Thread.sleep(3000)
|
||||
}
|
||||
|
||||
snapshot = syncer.getSnapshotTimestamp(repoName, snapshotName)
|
||||
def snapshot = syncer.getSnapshotTimestamp(repoName, snapshotName)
|
||||
assertTrue(snapshot != null)
|
||||
|
||||
sql "INSERT INTO ${dbName}.${tableName} VALUES (20, 21), (123, 341)"
|
||||
|
||||
@ -0,0 +1,96 @@
|
||||
// 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_backup_restore_db", "backup_restore") {
|
||||
String dbName = "backup_restore_db_1"
|
||||
String suiteName = "test_backup_restore_db"
|
||||
String repoName = "${suiteName}_repo"
|
||||
String snapshotName = "${suiteName}_snapshot"
|
||||
String tableNamePrefix = "${suiteName}_tables"
|
||||
|
||||
def syncer = getSyncer()
|
||||
syncer.createS3Repository(repoName)
|
||||
sql "CREATE DATABASE IF NOT EXISTS ${dbName}"
|
||||
|
||||
int numTables = 10;
|
||||
int numRows = 10;
|
||||
List<String> tables = []
|
||||
for (int i = 0; i < numTables; ++i) {
|
||||
String tableName = "${tableNamePrefix}_${i}"
|
||||
tables.add(tableName)
|
||||
sql "DROP TABLE IF EXISTS ${dbName}.${tableName}"
|
||||
sql """
|
||||
CREATE TABLE ${dbName}.${tableName} (
|
||||
`id` LARGEINT NOT NULL,
|
||||
`count` LARGEINT SUM DEFAULT "0"
|
||||
)
|
||||
AGGREGATE KEY(`id`)
|
||||
DISTRIBUTED BY HASH(`id`) BUCKETS 2
|
||||
PROPERTIES
|
||||
(
|
||||
"replication_num" = "1"
|
||||
)
|
||||
"""
|
||||
List<String> values = []
|
||||
for (int j = 1; j <= numRows; ++j) {
|
||||
values.add("(${j}, ${j})")
|
||||
}
|
||||
sql "INSERT INTO ${dbName}.${tableName} VALUES ${values.join(",")}"
|
||||
def result = sql "SELECT * FROM ${dbName}.${tableName}"
|
||||
assertEquals(result.size(), numRows);
|
||||
}
|
||||
|
||||
sql """
|
||||
BACKUP SNAPSHOT ${dbName}.${snapshotName}
|
||||
TO `${repoName}`
|
||||
"""
|
||||
|
||||
while (!syncer.checkSnapshotFinish(dbName)) {
|
||||
Thread.sleep(3000)
|
||||
}
|
||||
|
||||
def snapshot = syncer.getSnapshotTimestamp(repoName, snapshotName)
|
||||
assertTrue(snapshot != null)
|
||||
|
||||
for (def tableName in tables) {
|
||||
sql "TRUNCATE TABLE ${dbName}.${tableName}"
|
||||
}
|
||||
|
||||
sql """
|
||||
RESTORE SNAPSHOT ${dbName}.${snapshotName}
|
||||
FROM `${repoName}`
|
||||
PROPERTIES
|
||||
(
|
||||
"backup_timestamp" = "${snapshot}",
|
||||
"replication_num" = "1"
|
||||
)
|
||||
"""
|
||||
|
||||
while (!syncer.checkAllRestoreFinish(dbName)) {
|
||||
Thread.sleep(3000)
|
||||
}
|
||||
|
||||
for (def tableName in tables) {
|
||||
result = sql "SELECT * FROM ${dbName}.${tableName}"
|
||||
assertEquals(result.size(), numRows);
|
||||
sql "DROP TABLE ${dbName}.${tableName} FORCE"
|
||||
}
|
||||
|
||||
sql "DROP DATABASE ${dbName} FORCE"
|
||||
sql "DROP REPOSITORY `${repoName}`"
|
||||
}
|
||||
|
||||
@ -65,7 +65,7 @@ suite("test_backup_restore_exclude", "backup_restore") {
|
||||
Thread.sleep(3000)
|
||||
}
|
||||
|
||||
snapshot = syncer.getSnapshotTimestamp(repoName, snapshotName)
|
||||
def snapshot = syncer.getSnapshotTimestamp(repoName, snapshotName)
|
||||
assertTrue(snapshot != null)
|
||||
|
||||
// Overwrite exists table.
|
||||
|
||||
@ -65,7 +65,7 @@ suite("test_backup_restore_multi_tables", "backup_restore") {
|
||||
Thread.sleep(3000)
|
||||
}
|
||||
|
||||
snapshot = syncer.getSnapshotTimestamp(repoName, snapshotName)
|
||||
def snapshot = syncer.getSnapshotTimestamp(repoName, snapshotName)
|
||||
assertTrue(snapshot != null)
|
||||
|
||||
for (def tableName in backupTables) {
|
||||
|
||||
@ -65,7 +65,7 @@ suite("test_backup_restore_multi_tables_overwrite", "backup_restore") {
|
||||
Thread.sleep(3000)
|
||||
}
|
||||
|
||||
snapshot = syncer.getSnapshotTimestamp(repoName, snapshotName)
|
||||
def snapshot = syncer.getSnapshotTimestamp(repoName, snapshotName)
|
||||
assertTrue(snapshot != null)
|
||||
|
||||
// Overwrite exists table.
|
||||
|
||||
@ -64,7 +64,7 @@ suite("test_restore_mix_exists_and_new_table", "backup_restore") {
|
||||
Thread.sleep(3000)
|
||||
}
|
||||
|
||||
snapshot = syncer.getSnapshotTimestamp(repoName, snapshotName)
|
||||
def snapshot = syncer.getSnapshotTimestamp(repoName, snapshotName)
|
||||
assertTrue(snapshot != null)
|
||||
|
||||
def dropTables = tables[0..5]
|
||||
|
||||
@ -56,7 +56,7 @@ suite("test_restore_to_new_table", "backup_restore") {
|
||||
Thread.sleep(3000)
|
||||
}
|
||||
|
||||
snapshot = syncer.getSnapshotTimestamp(repoName, snapshotName)
|
||||
def snapshot = syncer.getSnapshotTimestamp(repoName, snapshotName)
|
||||
assertTrue(snapshot != null)
|
||||
|
||||
sql "DROP TABLE ${dbName}.${tableName} FORCE"
|
||||
|
||||
Reference in New Issue
Block a user