@@ -4766,6 +4766,53 @@ public void readEntriesFailed(ManagedLedgerException exception, Object ctx) {
47664766 && cursorReadPosition .getEntryId () == expectReadPosition .getEntryId ());
47674767 }
47684768
4769+ @ Test
4770+ public void testSkipNonRecoverableEntries () throws ManagedLedgerException , InterruptedException {
4771+ ManagedLedgerConfig managedLedgerConfig = new ManagedLedgerConfig ();
4772+ int maxMessagePerLedger = 10 ;
4773+ managedLedgerConfig .setMaxEntriesPerLedger (maxMessagePerLedger );
4774+ ManagedLedger ledger = factory .open ("testSkipNonRecoverableEntries" , managedLedgerConfig );
4775+ ManagedCursorImpl cursor = (ManagedCursorImpl ) ledger .openCursor ("my-cursor" );
4776+
4777+ Position lacPosition = ledger .getLastConfirmedEntry ();
4778+ long ledgerId = lacPosition .getLedgerId ();
4779+ assertEquals (PositionFactory .create (ledgerId , -1 ), cursor .getMarkDeletedPosition ());
4780+
4781+ // Mock add 10 entry
4782+ for (int i = 0 ; i < 10 ; i ++) {
4783+ ledger .addEntry (String .valueOf (i ).getBytes ());
4784+ }
4785+
4786+ // read 2 entry and delete these entries, MarkDeletedPosition move forward
4787+ List <Entry > entries = cursor .readEntries (2 );
4788+ for (Entry entry : entries ) {
4789+ cursor .delete (entry .getPosition ());
4790+ }
4791+ assertEquals (PositionFactory .create (ledgerId , 1 ), cursor .getMarkDeletedPosition ());
4792+
4793+ // read the next 6 entry and not delete, MarkDeletedPosition not move forward
4794+ entries = cursor .readEntries (6 );
4795+ assertEquals (PositionFactory .create (ledgerId , 1 ), cursor .getMarkDeletedPosition ());
4796+
4797+ // delete last read entry, MarkDeletedPosition not move forward
4798+ Entry lastEntry = entries .get (entries .size () - 1 );
4799+ cursor .delete (lastEntry .getPosition ());
4800+ assertEquals (PositionFactory .create (ledgerId , 1 ), cursor .getMarkDeletedPosition ());
4801+
4802+ // call skip entries, MarkDeletedPosition move forward
4803+ cursor .skipNonRecoverableEntries (cursor .getMarkDeletedPosition (),
4804+ PositionFactory .create (ledgerId , lastEntry .getEntryId ()));
4805+ assertEquals (PositionFactory .create (ledgerId , lastEntry .getEntryId ()), cursor .getMarkDeletedPosition ());
4806+
4807+ // repeat call skip entries, MarkDeletedPosition not change
4808+ cursor .skipNonRecoverableEntries (cursor .getMarkDeletedPosition (),
4809+ PositionFactory .create (ledgerId , lastEntry .getEntryId ()));
4810+ assertEquals (PositionFactory .create (ledgerId , lastEntry .getEntryId ()), cursor .getMarkDeletedPosition ());
4811+
4812+ cursor .close ();
4813+ ledger .close ();
4814+ }
4815+
47694816 @ Test
47704817 public void testRecoverCursorWithTerminateManagedLedger () throws Exception {
47714818 String mlName = "my_test_ledger" ;
0 commit comments