|
45 | 45 | @Category({ClusterIT.class}) |
46 | 46 | public class IoTDBPartitionTableAutoCleanIT { |
47 | 47 |
|
| 48 | + private static final String TREE_DATABASE_PREFIX = "root.db.g_"; |
| 49 | + |
48 | 50 | private static final int TEST_REPLICATION_FACTOR = 1; |
49 | 51 | private static final long TEST_TIME_PARTITION_INTERVAL = 604800000; |
50 | 52 | private static final long TEST_TTL_CHECK_INTERVAL = 5_000; |
@@ -73,46 +75,41 @@ public void tearDown() { |
73 | 75 | } |
74 | 76 |
|
75 | 77 | @Test |
76 | | - public void testAutoCleanPartitionTable() throws Exception { |
| 78 | + public void testAutoCleanPartitionTableForTreeModel() throws Exception { |
77 | 79 | try (Connection connection = EnvFactory.getEnv().getConnection(); |
78 | 80 | Statement statement = connection.createStatement()) { |
79 | | - // Create db1 |
80 | | - statement.execute("CREATE DATABASE root.db1"); |
81 | | - statement.execute("CREATE TIMESERIES root.db1.s WITH DATATYPE=INT64,ENCODING=PLAIN"); |
82 | | - // Insert expired data |
83 | | - statement.execute( |
84 | | - String.format( |
85 | | - "INSERT INTO root.db1(timestamp, s) VALUES (%d, %d)", |
86 | | - TEST_CURRENT_TIME_SLOT.getStartTime() - TEST_TTL * 2, -1)); |
87 | | - // Insert existed data |
88 | | - statement.execute( |
89 | | - String.format( |
90 | | - "INSERT INTO root.db1(timestamp, s) VALUES (%d, %d)", |
91 | | - TEST_CURRENT_TIME_SLOT.getStartTime(), 1)); |
92 | | - // Let db.TTL > device.TTL, the valid TTL should be the bigger one |
93 | | - statement.execute("SET TTL TO root.db1 " + TEST_TTL); |
94 | | - statement.execute("SET TTL TO root.db1.s " + 10); |
95 | | - // Create db2 |
96 | | - statement.execute("CREATE DATABASE root.db2"); |
97 | | - statement.execute("CREATE TIMESERIES root.db2.s WITH DATATYPE=INT64,ENCODING=PLAIN"); |
98 | | - // Insert expired data |
99 | | - statement.execute( |
100 | | - String.format( |
101 | | - "INSERT INTO root.db2(timestamp, s) VALUES (%d, %d)", |
102 | | - TEST_CURRENT_TIME_SLOT.getStartTime() - TEST_TTL * 2, -1)); |
103 | | - // Insert existed data |
104 | | - statement.execute( |
105 | | - String.format( |
106 | | - "INSERT INTO root.db2(timestamp, s) VALUES (%d, %d)", |
107 | | - TEST_CURRENT_TIME_SLOT.getStartTime(), 1)); |
108 | | - // Let db.TTL < device.TTL, the valid TTL should be the bigger one |
109 | | - statement.execute("SET TTL TO root.db2 " + 10); |
110 | | - statement.execute("SET TTL TO root.db2.s " + TEST_TTL); |
| 81 | + // Create databases and insert test data |
| 82 | + for (int i = 0; i < 3; i++) { |
| 83 | + String databaseName = String.format("%s%d", TREE_DATABASE_PREFIX, i); |
| 84 | + statement.execute(String.format("CREATE DATABASE %s", databaseName)); |
| 85 | + statement.execute( |
| 86 | + String.format( |
| 87 | + "CREATE TIMESERIES %s.s WITH DATATYPE=INT64,ENCODING=PLAIN", databaseName)); |
| 88 | + // Insert expired data |
| 89 | + statement.execute( |
| 90 | + String.format( |
| 91 | + "INSERT INTO %s(timestamp, s) VALUES (%d, %d)", |
| 92 | + databaseName, TEST_CURRENT_TIME_SLOT.getStartTime() - TEST_TTL * 2, -1)); |
| 93 | + // Insert existed data |
| 94 | + statement.execute( |
| 95 | + String.format( |
| 96 | + "INSERT INTO %s(timestamp, s) VALUES (%d, %d)", |
| 97 | + databaseName, TEST_CURRENT_TIME_SLOT.getStartTime(), 1)); |
| 98 | + } |
| 99 | + // Let db0.TTL > device.TTL, the valid TTL should be the bigger one |
| 100 | + statement.execute(String.format("SET TTL TO %s0 %d", TREE_DATABASE_PREFIX, TEST_TTL)); |
| 101 | + statement.execute(String.format("SET TTL TO %s0.s %d", TREE_DATABASE_PREFIX, 10)); |
| 102 | + // Let db1.TTL < device.TTL, the valid TTL should be the bigger one |
| 103 | + statement.execute(String.format("SET TTL TO %s1 %d", TREE_DATABASE_PREFIX, 10)); |
| 104 | + statement.execute(String.format("SET TTL TO %s1.s %d", TREE_DATABASE_PREFIX, TEST_TTL)); |
| 105 | + // Set TTL to path db2.** |
| 106 | + statement.execute(String.format("SET TTL TO %s2.** %d", TREE_DATABASE_PREFIX, TEST_TTL)); |
111 | 107 | } |
112 | 108 |
|
113 | 109 | TDataPartitionReq req = new TDataPartitionReq(); |
114 | | - req.putToPartitionSlotsMap("root.db1", new TreeMap<>()); |
115 | | - req.putToPartitionSlotsMap("root.db2", new TreeMap<>()); |
| 110 | + for (int i = 0; i < 3; i++) { |
| 111 | + req.putToPartitionSlotsMap(String.format("%s%d", TREE_DATABASE_PREFIX, i), new TreeMap<>()); |
| 112 | + } |
116 | 113 | try (SyncConfigNodeIServiceClient client = |
117 | 114 | (SyncConfigNodeIServiceClient) EnvFactory.getEnv().getLeaderConfigNodeConnection()) { |
118 | 115 | for (int retry = 0; retry < 120; retry++) { |
|
0 commit comments