|
33 | 33 | import java.util.concurrent.TimeUnit; |
34 | 34 | import java.util.concurrent.atomic.AtomicBoolean; |
35 | 35 | import java.util.concurrent.atomic.AtomicInteger; |
| 36 | +import org.apache.commons.lang3.reflect.FieldUtils; |
36 | 37 | import org.apache.rocketmq.common.ThreadFactoryImpl; |
37 | 38 | import org.apache.rocketmq.store.logfile.DefaultMappedFile; |
38 | 39 | import org.apache.rocketmq.tieredstore.MessageStoreConfig; |
39 | 40 | import org.apache.rocketmq.tieredstore.common.AppendResult; |
| 41 | +import org.apache.rocketmq.tieredstore.file.FlatAppendFile; |
40 | 42 | import org.apache.rocketmq.tieredstore.file.FlatFileFactory; |
41 | 43 | import org.apache.rocketmq.tieredstore.metadata.DefaultMetadataStore; |
42 | 44 | import org.apache.rocketmq.tieredstore.metadata.MetadataStore; |
43 | 45 | import org.apache.rocketmq.tieredstore.util.MessageStoreUtil; |
44 | 46 | import org.apache.rocketmq.tieredstore.util.MessageStoreUtilTest; |
| 47 | +import org.awaitility.Awaitility; |
45 | 48 | import org.junit.After; |
46 | 49 | import org.junit.Assert; |
47 | 50 | import org.junit.Before; |
@@ -206,6 +209,39 @@ public void runServiceTest() throws InterruptedException { |
206 | 209 | }); |
207 | 210 | } |
208 | 211 |
|
| 212 | + @Test |
| 213 | + public void deleteFileTest() throws InterruptedException, IllegalAccessException { |
| 214 | + indexService = new IndexStoreService(fileAllocator, filePath); |
| 215 | + indexService.start(); |
| 216 | + |
| 217 | + for (int i = 0; i < 2 * 20; i++) { |
| 218 | + AppendResult result = indexService.putKey( |
| 219 | + TOPIC_NAME, TOPIC_ID, QUEUE_ID, Collections.singleton(String.valueOf(i)), |
| 220 | + i * 100L, MESSAGE_SIZE, System.currentTimeMillis()); |
| 221 | + Assert.assertEquals(AppendResult.SUCCESS, result); |
| 222 | + TimeUnit.MILLISECONDS.sleep(1); |
| 223 | + } |
| 224 | + |
| 225 | + indexService.wakeup(); |
| 226 | + Awaitility.await().until(() -> { |
| 227 | + int tableSize = (int) indexService.getTimeStoreTable().entrySet().stream() |
| 228 | + .filter(entry -> IndexFile.IndexStatusEnum.UPLOAD.equals(entry.getValue().getFileStatus())) |
| 229 | + .count(); |
| 230 | + return tableSize == 2; |
| 231 | + }); |
| 232 | + |
| 233 | + long timestamp = indexService.getTimeStoreTable().firstEntry().getValue().getEndTimestamp(); |
| 234 | + FlatAppendFile flatAppendFile = (FlatAppendFile) |
| 235 | + FieldUtils.readField(indexService, "flatAppendFile", true); |
| 236 | + |
| 237 | + indexService.destroyExpiredFile(timestamp); |
| 238 | + Assert.assertEquals(2, flatAppendFile.getFileSegmentList().size()); |
| 239 | + Assert.assertEquals(3, indexService.getTimeStoreTable().size()); |
| 240 | + indexService.destroyExpiredFile(timestamp + 1); |
| 241 | + Assert.assertEquals(1, flatAppendFile.getFileSegmentList().size()); |
| 242 | + Assert.assertEquals(2, indexService.getTimeStoreTable().size()); |
| 243 | + } |
| 244 | + |
209 | 245 | @Test |
210 | 246 | public void restartServiceTest() throws InterruptedException { |
211 | 247 | indexService = new IndexStoreService(fileAllocator, filePath); |
|
0 commit comments