Skip to content

Commit

Permalink
add test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Technoboy- committed Oct 12, 2022
1 parent 9cd7dc1 commit 9a44a73
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3324,10 +3324,6 @@ long getNumberOfEntries(Range<PositionImpl> range) {
* @return the new position that is n entries ahead
*/
public PositionImpl getPositionAfterN(final PositionImpl startPosition, long n, PositionBound startRange) {
final PositionImpl nextValidPosition = getNextValidPosition(startPosition);
if (startPosition.compareTo(nextValidPosition) >= 0) {
return nextValidPosition;
}
final LedgerHandle curLedger = currentLedger;
long entriesToSkip = n;
long currentLedgerId;
Expand All @@ -3336,6 +3332,7 @@ public PositionImpl getPositionAfterN(final PositionImpl startPosition, long n,
currentLedgerId = startPosition.getLedgerId();
currentEntryId = startPosition.getEntryId();
} else {
PositionImpl nextValidPosition = getNextValidPosition(startPosition);
currentLedgerId = nextValidPosition.getLedgerId();
currentEntryId = nextValidPosition.getEntryId();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2478,6 +2478,23 @@ public void testGetPositionAfterN() throws Exception {
log.info("Target position is {}", targetPosition);
assertEquals(targetPosition.getLedgerId(), secondLedger);
assertEquals(targetPosition.getEntryId(), 4);

// test for n > NumberOfEntriesInStorage
searchPosition = new PositionImpl(secondLedger, 0);
targetPosition = managedLedger.getPositionAfterN(searchPosition, 100, ManagedLedgerImpl.PositionBound.startIncluded);
assertEquals(targetPosition.getLedgerId(), secondLedger);
assertEquals(targetPosition.getEntryId(), 4);

// test for startPosition > current ledger
searchPosition = new PositionImpl(999, 0);
targetPosition = managedLedger.getPositionAfterN(searchPosition, 0, ManagedLedgerImpl.PositionBound.startIncluded);
assertEquals(targetPosition.getLedgerId(), secondLedger);
assertEquals(targetPosition.getEntryId(), 4);

searchPosition = new PositionImpl(999, 0);
targetPosition = managedLedger.getPositionAfterN(searchPosition, 10, ManagedLedgerImpl.PositionBound.startExcluded);
assertEquals(targetPosition.getLedgerId(), secondLedger);
assertEquals(targetPosition.getEntryId(), 4);
}

@Test
Expand Down

0 comments on commit 9a44a73

Please sign in to comment.