This is an automated email from the ASF dual-hosted git repository.
lhotari pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/master by this push:
new 82d3902120d [fix][ml] Return 1 when bytes size is 0 or negative for
entry count estimation (#24131)
82d3902120d is described below
commit 82d3902120da67107d98d66ea95f8706dc0562be
Author: Lari Hotari <[email protected]>
AuthorDate: Wed Mar 26 18:19:01 2025 +0200
[fix][ml] Return 1 when bytes size is 0 or negative for entry count
estimation (#24131)
---
.../org/apache/bookkeeper/mledger/impl/EntryCountEstimator.java | 4 ++--
.../apache/bookkeeper/mledger/impl/EntryCountEstimatorTest.java | 8 +++++++-
2 files changed, 9 insertions(+), 3 deletions(-)
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 b95b2c846fa..511379a7ae5 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 @@ class EntryCountEstimator {
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 2016c97f1ab..c1c1b8dd2c1 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 @@ public class EntryCountEstimatorTest {
@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