Skip to content

Commit

Permalink
[fix](test) fix unstable jdbc ddl case (apache#46697)
Browse files Browse the repository at this point in the history
### What problem does this PR solve?

When `use_meta_cache = false`, we should wait for database sync.
  • Loading branch information
morningman authored Jan 10, 2025
1 parent 66dddc2 commit fb5e555
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !database --
DORIS
Doris
doris
doris_test
information_schema
init_db
mysql
show_test_do_not_modify

-- !ex_tb0_where --
111
Expand All @@ -20,25 +13,9 @@ show_test_do_not_modify
115 abg

-- !preceding_create_external_database --
DORIS
Doris
doris
doris_test
information_schema
init_db
mysql
show_test_do_not_modify

-- !subsequent_create_external_database --
DORIS
Doris
doris
doris_test
information_schema
init_db
mysql
new_mysql_db
show_test_do_not_modify

-- !sql_show_tables --

Expand Down Expand Up @@ -76,23 +53,7 @@ new_mysql_table2 CREATE TABLE `new_mysql_table2` (\n `id` int NULL,\n `name` v
new_mysql_table2 CREATE TABLE `new_mysql_table2` (\n `id` int NULL,\n `name` varchar(20) NULL,\n `new_column` int NULL,\n `new_column_1` int NULL,\n `new_column_2` int NULL\n) ENGINE=JDBC_EXTERNAL_TABLE;

-- !preceding_drop_external_database --
DORIS
Doris
doris
doris_test
information_schema
init_db
mysql
new_mysql_db
show_test_do_not_modify

-- !subsequent_drop_external_database --
DORIS
Doris
doris
doris_test
information_schema
init_db
mysql
show_test_do_not_modify

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
// specific language governing permissions and limitations
// under the License.

import java.util.concurrent.TimeUnit;
import org.awaitility.Awaitility;

suite("test_jdbc_catalog_ddl", "p0,external,mysql,external_docker,external_docker_mysql") {

String enabled = context.config.otherConfigs.get("enableJdbcTest")
Expand All @@ -23,6 +26,18 @@ suite("test_jdbc_catalog_ddl", "p0,external,mysql,external_docker,external_docke
String bucket = getS3BucketName()
String driver_url = "https://${bucket}.${s3_endpoint}/regression/jdbc_driver/mysql-connector-java-5.1.49.jar"
String mysql_port = context.config.otherConfigs.get("mysql_57_port");

def wait_db_sync = { String ctl ->
Awaitility.await().atMost(10, TimeUnit.SECONDS).pollInterval(1, TimeUnit.SECONDS).until{
try {
def res = sql "show databases from ${ctl}"
return res.size() > 0;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
}
// String driver_url = "mysql-connector-java-5.1.49.jar"
if (enabled != null && enabled.equalsIgnoreCase("true")) {
String catalog_name = "test_jdbc_catalog_ddl";
Expand All @@ -38,6 +53,11 @@ suite("test_jdbc_catalog_ddl", "p0,external,mysql,external_docker,external_docke
"driver_class" = "com.mysql.jdbc.Driver",
"use_meta_cache" = "${useMetaCache}"
);"""

if (useMetaCache.equals("false")) {
wait_db_sync("${catalog_name}")
}

def res = sql(""" show databases from ${catalog_name}; """).collect {x -> x[0] as String}
println("show databases result " + res);
def containedDb = ['mysql', 'doris_test', 'information_schema']
Expand Down Expand Up @@ -68,6 +88,7 @@ suite("test_jdbc_catalog_ddl", "p0,external,mysql,external_docker,external_docke

if (useMetaCache.equals("false")) {
sql """refresh catalog ${catalog_name}"""
wait_db_sync("${catalog_name}")
}
sql "use ${catalog_name}.temp_database"
qt_sql01 """select * from temp_table"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ suite("test_nereids_refresh_catalog", "p0,external,mysql,external_docker,externa
sql """CALL EXECUTE_STMT("${catalog_name}", "drop database if exists ${new_mysql_db}");"""
sql """switch ${catalog_name}"""

qt_database """show databases;"""
qt_database """show databases like "%doris_test%";"""
sql """ use ${ex_db_name}"""

qt_ex_tb0_where """select id from ${ex_tb0} where id = 111;"""
order_qt_ex_tb0 """ select id, name from ${ex_tb0} order by id; """
// create database in mysql
sql """CALL EXECUTE_STMT("${catalog_name}", "create database ${new_mysql_db} ;");"""
qt_preceding_create_external_database """show databases;"""
qt_preceding_create_external_database """show databases like "%${new_mysql_db}%";"""
checkNereidsExecute("refresh catalog ${catalog_name} ;")
qt_subsequent_create_external_database """show databases;"""
qt_subsequent_create_external_database """show databases like "%${new_mysql_db}%";"""

checkNereidsExecute("refresh catalog ${catalog_name} properties ('invalid_cache'='true');")
sql """use ${new_mysql_db}"""
Expand Down Expand Up @@ -94,10 +94,10 @@ suite("test_nereids_refresh_catalog", "p0,external,mysql,external_docker,externa
qt_subsequent_refresh_table """show create table ${new_mysql_db}.${new_mysql_table2};"""

sql """CALL EXECUTE_STMT("${catalog_name}", "drop database if exists ${new_mysql_db} ;");"""
qt_preceding_drop_external_database """show databases;"""
qt_preceding_drop_external_database """show databases like "%${new_mysql_db}%";"""

checkNereidsExecute("refresh catalog ${catalog_name} properties ('invalid_cache'='true');")
qt_subsequent_drop_external_database """show databases;"""
qt_subsequent_drop_external_database """show databases like "%${new_mysql_db}%";"""

sql """ drop catalog if exists ${catalog_name} ;"""
}
Expand Down

0 comments on commit fb5e555

Please sign in to comment.