|
27 | 27 | import org.apache.iotdb.it.framework.IoTDBTestRunner; |
28 | 28 | import org.apache.iotdb.itbase.category.TableClusterIT; |
29 | 29 | import org.apache.iotdb.itbase.env.BaseEnv; |
| 30 | +import org.apache.iotdb.itbase.exception.InconsistentDataException; |
30 | 31 |
|
| 32 | +import org.awaitility.Awaitility; |
31 | 33 | import org.junit.Assert; |
32 | 34 | import org.junit.Test; |
33 | 35 | import org.junit.experimental.categories.Category; |
|
41 | 43 | import java.sql.Statement; |
42 | 44 | import java.util.Collections; |
43 | 45 | import java.util.concurrent.Callable; |
| 46 | +import java.util.concurrent.TimeUnit; |
44 | 47 |
|
45 | 48 | import static org.junit.Assert.assertTrue; |
46 | 49 |
|
@@ -228,11 +231,11 @@ public void executeSpecificSql( |
228 | 231 | "DELETE DEVICES must succeed with one DataNode down"); |
229 | 232 |
|
230 | 233 | 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)); |
236 | 239 |
|
237 | 240 | LOGGER.info("7. start to test high availability of dropping database procedure"); |
238 | 241 | assertStatementEffect( |
@@ -274,6 +277,30 @@ private void assertStatementEffect( |
274 | 277 | assertTrue(message, effect.call()); |
275 | 278 | } |
276 | 279 |
|
| 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 | + |
277 | 304 | private boolean tableExists(final Statement statement, final String tableName) throws Exception { |
278 | 305 | try (final ResultSet resultSet = statement.executeQuery("SHOW TABLES")) { |
279 | 306 | while (resultSet.next()) { |
|
0 commit comments