This is an automated email from the ASF dual-hosted git repository. penghui pushed a commit to branch branch-2.8 in repository https://gitbox.apache.org/repos/asf/pulsar.git
commit b8d2baf509e98dbf6307cb1a393c2d6b82a62bc7 Author: Yunze Xu <[email protected]> AuthorDate: Thu Nov 25 10:29:41 2021 +0800 Fix wrong isEmpty method of ConcurrentOpenLongPairRangeSet (#12953) (cherry picked from commit 6cc5cff0f051cf50c84edb4bb67034cb978d3646) --- .../util/collections/ConcurrentOpenLongPairRangeSet.java | 12 +++++------- .../collections/ConcurrentOpenLongPairRangeSetTest.java | 13 +++++++++++++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/pulsar-common/src/main/java/org/apache/pulsar/common/util/collections/ConcurrentOpenLongPairRangeSet.java b/pulsar-common/src/main/java/org/apache/pulsar/common/util/collections/ConcurrentOpenLongPairRangeSet.java index 174f318..7ae6c7e 100644 --- a/pulsar-common/src/main/java/org/apache/pulsar/common/util/collections/ConcurrentOpenLongPairRangeSet.java +++ b/pulsar-common/src/main/java/org/apache/pulsar/common/util/collections/ConcurrentOpenLongPairRangeSet.java @@ -152,14 +152,12 @@ public class ConcurrentOpenLongPairRangeSet<T extends Comparable<T>> implements if (rangeBitSetMap.isEmpty()) { return true; } - AtomicBoolean isEmpty = new AtomicBoolean(false); - rangeBitSetMap.forEach((key, val) -> { - if (!isEmpty.get()) { - return; + for (BitSet rangeBitSet : rangeBitSetMap.values()) { + if (!rangeBitSet.isEmpty()) { + return false; } - isEmpty.set(val.isEmpty()); - }); - return isEmpty.get(); + } + return true; } @Override diff --git a/pulsar-common/src/test/java/org/apache/pulsar/common/util/collections/ConcurrentOpenLongPairRangeSetTest.java b/pulsar-common/src/test/java/org/apache/pulsar/common/util/collections/ConcurrentOpenLongPairRangeSetTest.java index f57b75d..90c23ae 100644 --- a/pulsar-common/src/test/java/org/apache/pulsar/common/util/collections/ConcurrentOpenLongPairRangeSetTest.java +++ b/pulsar-common/src/test/java/org/apache/pulsar/common/util/collections/ConcurrentOpenLongPairRangeSetTest.java @@ -19,7 +19,9 @@ package org.apache.pulsar.common.util.collections; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; import java.util.List; import java.util.Set; @@ -38,6 +40,17 @@ public class ConcurrentOpenLongPairRangeSetTest { static final LongPairConsumer<LongPair> consumer = (key, value) -> new LongPair(key, value); @Test + public void testIsEmpty() { + ConcurrentOpenLongPairRangeSet<LongPair> set = new ConcurrentOpenLongPairRangeSet<>(consumer); + assertTrue(set.isEmpty()); + // lowerValueOpen and upperValue are both -1 so that an empty set will be added + set.addOpenClosed(0, -1, 0, -1); + assertTrue(set.isEmpty()); + set.addOpenClosed(1, 1, 1, 5); + assertFalse(set.isEmpty()); + } + + @Test public void testAddForSameKey() { ConcurrentOpenLongPairRangeSet<LongPair> set = new ConcurrentOpenLongPairRangeSet<>(consumer); // add 0 to 5
