You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by zh...@apache.org on 2024/05/18 09:04:48 UTC

(hbase) branch branch-2.5 updated: HBASE-28604 Fix the error message in ReservoirSample's constructor (#5920)

This is an automated email from the ASF dual-hosted git repository.

zhangduo pushed a commit to branch branch-2.5
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/branch-2.5 by this push:
     new e7d0beae1db HBASE-28604 Fix the error message in ReservoirSample's constructor (#5920)
e7d0beae1db is described below

commit e7d0beae1db410c6c32d42a32c43be7f8ad27370
Author: Duo Zhang <zh...@apache.org>
AuthorDate: Sat May 18 16:55:07 2024 +0800

    HBASE-28604 Fix the error message in ReservoirSample's constructor (#5920)
    
    Signed-off-by: Nick Dimiduk <nd...@apache.org>
    (cherry picked from commit 6b7aaed600988f9e9858eb7a9172f9af03b61b5c)
---
 .../main/java/org/apache/hadoop/hbase/util/ReservoirSample.java   | 2 +-
 .../java/org/apache/hadoop/hbase/util/TestReservoirSample.java    | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ReservoirSample.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ReservoirSample.java
index f50b81154e1..aa7a84b1ac2 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ReservoirSample.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ReservoirSample.java
@@ -41,7 +41,7 @@ public class ReservoirSample<T> {
   private int n;
 
   public ReservoirSample(int k) {
-    Preconditions.checkArgument(k > 0, "negative sampling number(%d) is not allowed");
+    Preconditions.checkArgument(k > 0, "negative sampling number(%s) is not allowed", k);
     r = new ArrayList<>(k);
     this.k = k;
   }
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestReservoirSample.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestReservoirSample.java
index 6192edfa036..d7ea0c5ac0c 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestReservoirSample.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestReservoirSample.java
@@ -18,6 +18,7 @@
 package org.apache.hadoop.hbase.util;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 
 import java.util.stream.IntStream;
@@ -89,4 +90,11 @@ public class TestReservoirSample {
     assertTrue(containsOne > round / 10 * 0.95);
     assertTrue(containsOne < round / 10 * 1.05);
   }
+
+  @Test
+  public void testNegativeSamplingNumber() {
+    IllegalArgumentException e =
+      assertThrows(IllegalArgumentException.class, () -> new ReservoirSample<Integer>(-1));
+    assertEquals("negative sampling number(-1) is not allowed", e.getMessage());
+  }
 }