|
19 | 19 | package org.apache.bookkeeper.mledger.impl; |
20 | 20 |
|
21 | 21 | import static java.nio.charset.StandardCharsets.UTF_8; |
| 22 | +import static org.assertj.core.api.Assertions.assertThat; |
22 | 23 | import static org.mockito.ArgumentMatchers.any; |
23 | 24 | import static org.mockito.ArgumentMatchers.anyInt; |
24 | 25 | import static org.mockito.ArgumentMatchers.anyMap; |
@@ -5165,7 +5166,7 @@ public void testComparePositions() throws Exception { |
5165 | 5166 | ml.delete(); |
5166 | 5167 | } |
5167 | 5168 |
|
5168 | | - @Test |
| 5169 | + @Test(invocationCount = 100) |
5169 | 5170 | public void testTrimmerRaceCondition() throws Exception { |
5170 | 5171 | ManagedLedgerConfig config = new ManagedLedgerConfig(); |
5171 | 5172 | config.setMaxEntriesPerLedger(1); |
@@ -5201,18 +5202,19 @@ public void markDeleteFailed(ManagedLedgerException exception, Object ctx) { |
5201 | 5202 | }, null); |
5202 | 5203 |
|
5203 | 5204 | latch.await(); |
5204 | | - assertEquals(cursor.getPersistentMarkDeletedPosition(), lastPosition); |
5205 | | - assertEquals(ledger.getCursors().getSlowestCursorPosition(), lastPosition); |
| 5205 | + assertThat(cursor.getPersistentMarkDeletedPosition()).isGreaterThanOrEqualTo(lastPosition); |
| 5206 | + assertThat(ledger.getCursors().getSlowestCursorPosition()).isGreaterThanOrEqualTo(lastPosition); |
5206 | 5207 | assertEquals(cursor.getProperties(), properties); |
5207 | 5208 |
|
5208 | | - // 3. Add Entry 2. Triggers Rollover. |
| 5209 | + // 3. Add Entry 2. Triggers second rollover process. |
5209 | 5210 | // This implicitly calls maybeUpdateCursorBeforeTrimmingConsumedLedger due to rollover |
5210 | 5211 | Position p = ledger.addEntry("entry-2".getBytes(Encoding)); |
5211 | 5212 |
|
5212 | 5213 | // Wait for background tasks (metadata callback) to complete. |
5213 | 5214 | // We expect at least 2 ledgers (Rollover happened). |
5214 | 5215 | Awaitility.await().atMost(5, TimeUnit.SECONDS).until(() -> ledger.getLedgersInfo().size() >= 2); |
5215 | | - assertEquals(cursor.getPersistentMarkDeletedPosition(), new ImmutablePositionImpl(p.getLedgerId(), -1)); |
| 5216 | + // First ledger is all consumed and trimmed, left current ledger and next empty ledger. |
| 5217 | + assertEquals(cursor.getPersistentMarkDeletedPosition(), PositionFactory.create(p.getLedgerId(), -1)); |
5216 | 5218 |
|
5217 | 5219 | // Verify properties are preserved after cursor reset |
5218 | 5220 | assertEquals(cursor.getProperties(), properties); |
|
0 commit comments