Skip to content

Commit 491d9b3

Browse files
authored
[Test] Stabilize table DDL HA tests for async DROP TABLE (#18852)
1 parent a78f5a7 commit 491d9b3

1 file changed

Lines changed: 32 additions & 5 deletions

File tree

‎integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBTableDDLHAIT.java‎

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
import org.apache.iotdb.it.framework.IoTDBTestRunner;
2828
import org.apache.iotdb.itbase.category.TableClusterIT;
2929
import org.apache.iotdb.itbase.env.BaseEnv;
30+
import org.apache.iotdb.itbase.exception.InconsistentDataException;
3031

32+
import org.awaitility.Awaitility;
3133
import org.junit.Assert;
3234
import org.junit.Test;
3335
import org.junit.experimental.categories.Category;
@@ -41,6 +43,7 @@
4143
import java.sql.Statement;
4244
import java.util.Collections;
4345
import java.util.concurrent.Callable;
46+
import java.util.concurrent.TimeUnit;
4447

4548
import static org.junit.Assert.assertTrue;
4649

@@ -228,11 +231,11 @@ public void executeSpecificSql(
228231
"DELETE DEVICES must succeed with one DataNode down");
229232

230233
LOGGER.info("6. start to test high availability of dropping table procedure");
231-
assertStatementEffect(
232-
statement,
233-
"DROP TABLE " + tableName,
234-
() -> !tableExists(statement, tableName),
235-
"DROP TABLE must succeed with one DataNode down");
234+
statement.execute("DROP TABLE " + tableName);
235+
// DROP TABLE acknowledges submission before the table has been fully removed.
236+
awaitDropTableProcedure(statement, databaseName, tableName);
237+
assertTrue(
238+
"DROP TABLE must succeed with one DataNode down", !tableExists(statement, tableName));
236239

237240
LOGGER.info("7. start to test high availability of dropping database procedure");
238241
assertStatementEffect(
@@ -274,6 +277,30 @@ private void assertStatementEffect(
274277
assertTrue(message, effect.call());
275278
}
276279

280+
private void awaitDropTableProcedure(
281+
final Statement statement, final String databaseName, final String tableName)
282+
throws Exception {
283+
Awaitility.await()
284+
.atMost(60, TimeUnit.SECONDS)
285+
.pollInSameThread()
286+
// Progress snapshots can differ between cluster nodes while deletion is running.
287+
.ignoreException(InconsistentDataException.class)
288+
.untilAsserted(
289+
() -> {
290+
try (final ResultSet resultSet =
291+
statement.executeQuery(
292+
"SELECT state, error_message FROM information_schema.drop_table_procedures "
293+
+ "WHERE database = '"
294+
+ databaseName
295+
+ "' AND table_name = '"
296+
+ tableName
297+
+ "' ORDER BY procedure_id DESC LIMIT 1")) {
298+
assertTrue("DROP TABLE procedure should be visible", resultSet.next());
299+
Assert.assertEquals(resultSet.getString(2), "SUCCESS", resultSet.getString(1));
300+
}
301+
});
302+
}
303+
277304
private boolean tableExists(final Statement statement, final String tableName) throws Exception {
278305
try (final ResultSet resultSet = statement.executeQuery("SHOW TABLES")) {
279306
while (resultSet.next()) {

0 commit comments

Comments
 (0)