Skip to content

Commit

Permalink
Reduce flakiness in ManagedLedgerTest.testInvalidateReadHandleWhenCon…
Browse files Browse the repository at this point in the history
…sumed
  • Loading branch information
lhotari committed Jan 29, 2025
1 parent e62ce48 commit 853e1e5
Showing 1 changed file with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3804,10 +3804,16 @@ public void testInvalidateReadHandleWhenConsumed() throws Exception {
for (int i = 0; i < entries; i++) {
ledger.addEntry(String.valueOf(i).getBytes(Encoding));
}
List<Entry> entryList = cursor.readEntries(3);
assertEquals(entryList.size(), 3);
assertEquals(ledger.ledgers.size(), 4);
assertEquals(ledger.ledgerCache.size(), 3);

// clear the cache to avoid flakiness
factory.getEntryCacheManager().clear();

final List<Entry> entryList = cursor.readEntries(3);
Awaitility.await().untilAsserted(() -> {
assertEquals(entryList.size(), 3);
assertEquals(ledger.ledgers.size(), 4);
assertEquals(ledger.ledgerCache.size(), 3);
});
cursor.clearBacklog();
cursor2.clearBacklog();
ledger.trimConsumedLedgersInBackground(Futures.NULL_PROMISE);
Expand All @@ -3816,19 +3822,24 @@ public void testInvalidateReadHandleWhenConsumed() throws Exception {
assertEquals(ledger.ledgerCache.size(), 0);
});

// clear the cache to avoid flakiness
factory.getEntryCacheManager().clear();

// Verify the ReadHandle can be reopened.
ManagedCursor cursor3 = ledger.openCursor("test-cursor3", InitialPosition.Earliest);
entryList = cursor3.readEntries(3);
assertEquals(entryList.size(), 3);
assertEquals(ledger.ledgerCache.size(), 3);
final List<Entry> entryList2 = cursor3.readEntries(3);
Awaitility.await().untilAsserted(() -> {
assertEquals(entryList2.size(), 3);
assertEquals(ledger.ledgerCache.size(), 3);
});

cursor3.clearBacklog();
ledger.trimConsumedLedgersInBackground(Futures.NULL_PROMISE);
Awaitility.await().untilAsserted(() -> {
assertEquals(ledger.ledgers.size(), 4);
assertEquals(ledger.ledgerCache.size(), 0);
});


cursor.close();
cursor2.close();
cursor3.close();
Expand Down

0 comments on commit 853e1e5

Please sign in to comment.