Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -89,4 +90,11 @@ public void testStream() {
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());
}
}