Skip to content

Commit

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

When `use_meta_cache=false`, should wait table list to be synced
  • Loading branch information
morningman committed Feb 25, 2025
1 parent 2bd0ed6 commit 5e6897c
Showing 1 changed file with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,22 @@ suite("test_jdbc_catalog_ddl", "p0,external,mysql,external_docker,external_docke
}
}
}

def wait_table_sync = { String db ->
Awaitility.await().atMost(10, TimeUnit.SECONDS).pollInterval(1, TimeUnit.SECONDS).until{
try {
def res = sql "show tables from ${db}"
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";
String temp_db = "test_jdbc_catalog_ddl_tmp_db"

for (String useMetaCache : ["true", "false"]) {
sql """drop catalog if exists ${catalog_name} """
Expand Down Expand Up @@ -79,19 +92,26 @@ suite("test_jdbc_catalog_ddl", "p0,external,mysql,external_docker,external_docke
}

// create a database in mysql
sql """CALL EXECUTE_STMT("${catalog_name}", "drop database if exists temp_database")"""
sql """CALL EXECUTE_STMT("${catalog_name}", "create database temp_database")"""
sql """CALL EXECUTE_STMT("${catalog_name}", "drop table if exists temp_database.temp_table")"""
sql """CALL EXECUTE_STMT("${catalog_name}", "create table temp_database.temp_table (k1 int)")"""
sql """CALL EXECUTE_STMT("${catalog_name}", "insert into temp_database.temp_table values(12345)")"""
sql """CALL EXECUTE_STMT("${catalog_name}", "drop database if exists ${temp_db}")"""
sql """CALL EXECUTE_STMT("${catalog_name}", "create database ${temp_db}")"""
sql """CALL EXECUTE_STMT("${catalog_name}", "drop table if exists ${temp_db}.temp_table")"""
sql """CALL EXECUTE_STMT("${catalog_name}", "create table ${temp_db}.temp_table (k1 int)")"""
sql """CALL EXECUTE_STMT("${catalog_name}", "insert into ${temp_db}.temp_table values(12345)")"""

if (useMetaCache.equals("false")) {
sql """refresh catalog ${catalog_name}"""
// if use_meta_cache is false, there is a bug that refresh catalog is not able to see newly created database.
// but `alter catalog` can uninitialize entire catalog and get newly created database.
// so here we use `alter catalog` to let this case pass,
// no plan to fix it, because in new Doris version, use_meta_cache is true
sql """ALTER CATALOG `${catalog_name}` SET PROPERTIES ('password'='123456')"""
wait_db_sync("${catalog_name}")
}
sql "use ${catalog_name}.temp_database"
sql "use ${catalog_name}.${temp_db}"
if (useMetaCache.equals("false")) {
wait_table_sync("${catalog_name}.${temp_db}")
}
qt_sql01 """select * from temp_table"""
sql """CALL EXECUTE_STMT("${catalog_name}", "drop database if exists temp_database")"""
sql """CALL EXECUTE_STMT("${catalog_name}", "drop database if exists ${temp_db}")"""
}
}
}
Expand Down

0 comments on commit 5e6897c

Please sign in to comment.