diff --git a/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/EntryCountEstimator.java b/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/EntryCountEstimator.java index b95b2c846fa2c..511379a7ae525 100644 --- a/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/EntryCountEstimator.java +++ b/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/EntryCountEstimator.java @@ -73,8 +73,8 @@ static int internalEstimateEntryCountByBytesSize(int maxEntries, long maxSizeByt Long lastLedgerId, long lastLedgerTotalEntries, long lastLedgerTotalSize) { if (maxSizeBytes <= 0) { - // If the specified maximum size is invalid (e.g., non-positive), return 0 - return 0; + // If the specified maximum size is invalid (e.g., non-positive), return 1 + return 1; } // If the maximum size is Long.MAX_VALUE, return the maximum number of entries diff --git a/managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/EntryCountEstimatorTest.java b/managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/EntryCountEstimatorTest.java index 2016c97f1abbc..c1c1b8dd2c133 100644 --- a/managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/EntryCountEstimatorTest.java +++ b/managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/EntryCountEstimatorTest.java @@ -83,7 +83,13 @@ private int estimateEntryCountByBytesSize(long maxSizeBytes) { @Test public void testZeroMaxSize() { int result = estimateEntryCountByBytesSize(0); - assertEquals(result, 0, "Should return 0 when max size is 0"); + assertEquals(result, 1, "Should return 1 when max size is 0"); + } + + @Test + public void testNegativeMaxSize() { + int result = estimateEntryCountByBytesSize(-1); + assertEquals(result, 1, "Should return 1 when max size is negative"); } @Test