Skip to content

Commit b674fe6

Browse files
committed
HBASE-28604 Fix the error message in ReservoirSample's constructor (#5920)
Signed-off-by: Nick Dimiduk <[email protected]> (cherry picked from commit 6b7aaed)
1 parent 1990cea commit b674fe6

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

hbase-common/src/main/java/org/apache/hadoop/hbase/util/ReservoirSample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class ReservoirSample<T> {
4141
private int n;
4242

4343
public ReservoirSample(int k) {
44-
Preconditions.checkArgument(k > 0, "negative sampling number(%d) is not allowed");
44+
Preconditions.checkArgument(k > 0, "negative sampling number(%s) is not allowed", k);
4545
r = new ArrayList<>(k);
4646
this.k = k;
4747
}

hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestReservoirSample.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.hadoop.hbase.util;
1919

2020
import static org.junit.Assert.assertEquals;
21+
import static org.junit.Assert.assertThrows;
2122
import static org.junit.Assert.assertTrue;
2223

2324
import java.util.stream.IntStream;
@@ -89,4 +90,11 @@ public void testStream() {
8990
assertTrue(containsOne > round / 10 * 0.95);
9091
assertTrue(containsOne < round / 10 * 1.05);
9192
}
93+
94+
@Test
95+
public void testNegativeSamplingNumber() {
96+
IllegalArgumentException e =
97+
assertThrows(IllegalArgumentException.class, () -> new ReservoirSample<Integer>(-1));
98+
assertEquals("negative sampling number(-1) is not allowed", e.getMessage());
99+
}
92100
}

0 commit comments

Comments
 (0)