|
17 | 17 | */ |
18 | 18 | package org.apache.hadoop.hbase.master.region; |
19 | 19 |
|
| 20 | +import static org.awaitility.Awaitility.await; |
20 | 21 | import static org.junit.jupiter.api.Assertions.assertEquals; |
21 | 22 | import static org.junit.jupiter.api.Assertions.assertFalse; |
22 | 23 | import static org.junit.jupiter.api.Assertions.assertTrue; |
23 | 24 |
|
24 | 25 | import java.io.IOException; |
| 26 | +import java.time.Duration; |
25 | 27 | import org.apache.hadoop.conf.Configuration; |
26 | 28 | import org.apache.hadoop.fs.FileStatus; |
27 | 29 | import org.apache.hadoop.fs.FileSystem; |
@@ -82,14 +84,24 @@ public void test() throws IOException, InterruptedException { |
82 | 84 | assertFalse(fs.exists(globalWALArchiveDir)); |
83 | 85 | region.requestRollAll(); |
84 | 86 | region.waitUntilWalRollFinished(); |
85 | | - // should have one |
| 87 | + // archiving wal is called in a background thread when rolling WALs, so it is possible that when |
| 88 | + // waitUntilWalRollFinished returns, the archived WAL files have not been moved to the global |
| 89 | + // archive directory yet, so here we need to wait for the directory to be created and the files |
| 90 | + // to be moved. |
| 91 | + await().atMost(Duration.ofSeconds(15)).untilAsserted(() -> { |
| 92 | + assertTrue(fs.exists(globalWALArchiveDir)); |
| 93 | + assertEquals(1, fs.listStatus(globalWALArchiveDir).length); |
| 94 | + }); |
86 | 95 | FileStatus[] files = fs.listStatus(globalWALArchiveDir); |
87 | 96 | assertEquals(1, files.length); |
| 97 | + // Rebase the WAL mtime so the following timing assertions are not affected by the wait above. |
| 98 | + // Cleaner TTL is based on file mtime. |
| 99 | + fs.setTimes(files[0].getPath(), System.currentTimeMillis(), -1); |
88 | 100 | Thread.sleep(2000); |
89 | 101 | // should still be there |
90 | 102 | assertTrue(fs.exists(files[0].getPath())); |
91 | | - Thread.sleep(6000); |
92 | 103 | // should have been cleaned |
93 | | - assertEquals(0, fs.listStatus(globalWALArchiveDir).length); |
| 104 | + await().atMost(Duration.ofSeconds(15)) |
| 105 | + .untilAsserted(() -> assertEquals(0, fs.listStatus(globalWALArchiveDir).length)); |
94 | 106 | } |
95 | 107 | } |
0 commit comments