From d8cdd6e968d7642c5f9fda03c5674e9c6096c89b Mon Sep 17 00:00:00 2001 From: Baodi Shi Date: Fri, 26 Apr 2024 15:08:58 +0800 Subject: [PATCH 1/2] [fix][test] Flaky-test: ManagedLedgerTest.testTimestampOnWorkingLedger --- .../mledger/impl/ManagedLedgerTest.java | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerTest.java b/managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerTest.java index 22cf4d8b7a7ca..a753136267d7c 100644 --- a/managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerTest.java +++ b/managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerTest.java @@ -2446,7 +2446,7 @@ public void testRetentionSize() throws Exception { }); } - @Test(groups = "flaky") + @Test public void testTimestampOnWorkingLedger() throws Exception { ManagedLedgerConfig conf = new ManagedLedgerConfig(); conf.setMaxEntriesPerLedger(1); @@ -2473,19 +2473,17 @@ public void testTimestampOnWorkingLedger() throws Exception { ml.addEntry("msg02".getBytes()); + // reopen a new ml2 ml.close(); - // Thread.sleep(1000); - iter = ml.getLedgersInfoAsList().iterator(); - ts = -1; - while (iter.hasNext()) { - LedgerInfo i = iter.next(); - if (iter.hasNext()) { - assertTrue(ts <= i.getTimestamp(), i.toString()); - ts = i.getTimestamp(); - } else { - assertTrue(i.getTimestamp() > 0, "well closed LedgerInfo should set a timestamp > 0"); - } - } + ManagedLedgerImpl ml2 = (ManagedLedgerImpl) factory.open("my_test_ledger", conf); + + List ledgers = ml2.getLedgersInfoAsList(); + // after reopen ledgers will be 2 + 1(new open, not contain any entries) + assertEquals(ledgers.size(), 3); + + // the last closed ledger should be the penultimate one. + LedgerInfo lastClosedLeger = ledgers.get(ledgers.size() - 2); + assertTrue(lastClosedLeger.getTimestamp() > 0, "well closed LedgerInfo should set a timestamp > 0"); } @Test From 7c33c8a0a40ea2ec9b1b4c0f495e34f3a925f91b Mon Sep 17 00:00:00 2001 From: Baodi Shi Date: Fri, 26 Apr 2024 19:09:36 +0800 Subject: [PATCH 2/2] Close ml2 --- .../org/apache/bookkeeper/mledger/impl/ManagedLedgerTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerTest.java b/managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerTest.java index a753136267d7c..e983523c1b62e 100644 --- a/managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerTest.java +++ b/managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerTest.java @@ -2484,6 +2484,7 @@ public void testTimestampOnWorkingLedger() throws Exception { // the last closed ledger should be the penultimate one. LedgerInfo lastClosedLeger = ledgers.get(ledgers.size() - 2); assertTrue(lastClosedLeger.getTimestamp() > 0, "well closed LedgerInfo should set a timestamp > 0"); + ml2.close(); } @Test