diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBTtlIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBTtlIT.java index a0ad94a99444..d2dd50ebcf5c 100644 --- a/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBTtlIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBTtlIT.java @@ -102,12 +102,12 @@ public void testTTL() throws SQLException, InterruptedException { for (int i = 0; i < 100; i++) { statement.execute( String.format( - "INSERT INTO root.TTL_SG1(timestamp, s1) VALUES (%d, %d)", now - 100 + i, i)); + "INSERT INTO root.TTL_SG1(timestamp, s1) VALUES (%d, %d)", now - 1000000 + i, i)); } for (int i = 0; i < 100; i++) { statement.execute( String.format( - "INSERT INTO root.TTL_SG1(timestamp, s1) VALUES (%d, %d)", now - 100000 + i, i)); + "INSERT INTO root.TTL_SG1(timestamp, s1) VALUES (%d, %d)", now - 10000000 + i, i)); } try (ResultSet resultSet = statement.executeQuery("SELECT s1 FROM root.TTL_SG1")) { @@ -118,7 +118,7 @@ public void testTTL() throws SQLException, InterruptedException { assertEquals(200, cnt); } - statement.execute("SET TTL TO root.TTL_SG1 10000"); + statement.execute("SET TTL TO root.TTL_SG1 5000000"); try (ResultSet resultSet = statement.executeQuery("SELECT s1 FROM root.TTL_SG1")) { int cnt = 0; while (resultSet.next()) { @@ -132,7 +132,7 @@ public void testTTL() throws SQLException, InterruptedException { try { statement.execute( String.format( - "INSERT INTO root.TTL_SG1(timestamp, s1) VALUES (%d, %d)", now - 500000 + i, i)); + "INSERT INTO root.TTL_SG1(timestamp, s1) VALUES (%d, %d)", now - 8000000 + i, i)); } catch (SQLException e) { assertEquals(TSStatusCode.OUT_OF_TTL.getStatusCode(), e.getErrorCode()); } @@ -148,12 +148,12 @@ public void testTTL() throws SQLException, InterruptedException { } statement.execute("UNSET TTL TO root.TTL_SG1"); - // make sure other nodes have applied UNSET TTL - Thread.sleep(1000); + // UNSET TTL waits for the procedure to update all DataNode TTL caches. + // Stay outside the previous TTL so these inserts verify that UNSET TTL took effect. for (int i = 0; i < 100; i++) { statement.execute( String.format( - "INSERT INTO root.TTL_SG1(timestamp, s1) VALUES (%d, %d)", now - 30000 + i, i)); + "INSERT INTO root.TTL_SG1(timestamp, s1) VALUES (%d, %d)", now - 8000000 + i, i)); } try (ResultSet resultSet = statement.executeQuery("SELECT s1 FROM root.TTL_SG1")) { @@ -169,13 +169,14 @@ public void testTTL() throws SQLException, InterruptedException { for (int i = 0; i < 100; i++) { statement.execute( String.format( - "INSERT INTO root.sg.TTL_SG3(timestamp, s1) VALUES (%d, %d)", now - 100 + i, i)); + "INSERT INTO root.sg.TTL_SG3(timestamp, s1) VALUES (%d, %d)", + now - 10000000 + i, i)); } for (int i = 100; i < 200; i++) { statement.execute( String.format( "INSERT INTO root.sg.TTL_SG3(timestamp, s1) VALUES (%d, %d)", - now - 10000000 + i, i)); + now - 100000000 + i, i)); } try (ResultSet resultSet = statement.executeQuery("SELECT s1 FROM root.sg.TTL_SG3")) { @@ -189,13 +190,14 @@ public void testTTL() throws SQLException, InterruptedException { for (int i = 200; i < 300; i++) { statement.execute( String.format( - "INSERT INTO root.sg.TTL_SG4(timestamp, s1) VALUES (%d, %d)", now - 100 + i, i)); + "INSERT INTO root.sg.TTL_SG4(timestamp, s1) VALUES (%d, %d)", + now - 10000000 + i, i)); } for (int i = 300; i < 400; i++) { statement.execute( String.format( "INSERT INTO root.sg.TTL_SG4(timestamp, s1) VALUES (%d, %d)", - now - 10000000 + i, i)); + now - 100000000 + i, i)); } try (ResultSet resultSet = statement.executeQuery("SELECT s1 FROM root.sg.TTL_SG4")) { @@ -206,7 +208,7 @@ public void testTTL() throws SQLException, InterruptedException { assertEquals(200, cnt); } - statement.execute("SET TTL TO root.sg.** 100000"); + statement.execute("SET TTL TO root.sg.** 50000000"); try (ResultSet resultSet = statement.executeQuery("SELECT * FROM root.sg.**")) { int cnt = 0; while (resultSet.next()) { @@ -220,7 +222,7 @@ public void testTTL() throws SQLException, InterruptedException { statement.execute( String.format( "INSERT INTO root.sg.TTL_SG3(timestamp, s1) VALUES (%d, %d)", - now - 5000000 + i, i)); + now - 80000000 + i, i)); } catch (SQLException e) { assertEquals(TSStatusCode.OUT_OF_TTL.getStatusCode(), e.getErrorCode()); } @@ -231,7 +233,7 @@ public void testTTL() throws SQLException, InterruptedException { statement.execute( String.format( "INSERT INTO root.sg.TTL_SG4(timestamp, s1) VALUES (%d, %d)", - now - 5000000 + i, i)); + now - 80000000 + i, i)); } catch (SQLException e) { assertEquals(TSStatusCode.OUT_OF_TTL.getStatusCode(), e.getErrorCode()); } @@ -246,17 +248,19 @@ public void testTTL() throws SQLException, InterruptedException { } statement.execute("UNSET TTL TO root.sg.**"); - // make sure other nodes have applied UNSET TTL - Thread.sleep(1000); + // UNSET TTL waits for the procedure to update all DataNode TTL caches. + // Check wildcard UNSET TTL with data that the previous TTL would reject. for (int i = 0; i < 100; i++) { statement.execute( String.format( - "INSERT INTO root.sg.TTL_SG3(timestamp, s1) VALUES (%d, %d)", now - 30000 + i, i)); + "INSERT INTO root.sg.TTL_SG3(timestamp, s1) VALUES (%d, %d)", + now - 80000000 + i, i)); } for (int i = 100; i < 200; i++) { statement.execute( String.format( - "INSERT INTO root.sg.TTL_SG4(timestamp, s1) VALUES (%d, %d)", now - 30000 + i, i)); + "INSERT INTO root.sg.TTL_SG4(timestamp, s1) VALUES (%d, %d)", + now - 80000000 + i, i)); } try (ResultSet resultSet = statement.executeQuery("SELECT s1 FROM root.sg.**")) { int cnt = 0;