From 9f7ecc2b02817eda8642fd0c8a5dc3e25be8d520 Mon Sep 17 00:00:00 2001 From: Michael Stack Date: Sat, 29 May 2010 17:21:18 +0000 Subject: [PATCH] HBASE-2625 Make testDynamicBloom()'s randomness deterministic git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@949423 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 2 ++ .../hbase/util/TestByteBloomFilter.java | 22 +++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index f36384f7de6..52b6dc2c359 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1260,6 +1260,8 @@ Release 0.20.0 - Tue Sep 8 12:53:05 PDT 2009 HBASE-1743 [debug tool] Add regionsInTransition list to ClusterStatus detailed output HBASE-1772 Up the default ZK session timeout from 30seconds to 60seconds + HBASE-2625 Make testDynamicBloom()'s "randomness" deterministic + (Nicolas Spiegelberg via Stack) OPTIMIZATIONS HBASE-1412 Change values for delete column and column family in KeyValue diff --git a/src/test/java/org/apache/hadoop/hbase/util/TestByteBloomFilter.java b/src/test/java/org/apache/hadoop/hbase/util/TestByteBloomFilter.java index 77e9e3ecc5d..a082af68779 100644 --- a/src/test/java/org/apache/hadoop/hbase/util/TestByteBloomFilter.java +++ b/src/test/java/org/apache/hadoop/hbase/util/TestByteBloomFilter.java @@ -26,6 +26,7 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.nio.ByteBuffer; import java.util.BitSet; +import java.util.Random; import junit.framework.TestCase; @@ -150,13 +151,23 @@ public class TestByteBloomFilter extends TestCase { Hash.MURMUR_HASH); bf1.allocBloom(); + long seed = System.currentTimeMillis(); + Random r = new Random(seed); + System.out.println("seed = " + seed); + for (int i = 0; i < keyInterval*4; ++i) { // add - if (Math.random() > 0.5) { + if (r.nextBoolean()) { bf1.add(Bytes.toBytes(i)); valid.set(i); + + // we assume only 2 blooms in this test, so exit before a 3rd is made + if (bf1.getKeyCount() == 2000) { + break; + } } } - assertTrue(2 <= bf1.bloomCount() && bf1.bloomCount() <= 3); + assertTrue(2 <= bf1.bloomCount()); + System.out.println("keys added = " + bf1.getKeyCount()); // test serialization/deserialization ByteArrayOutputStream metaOut = new ByteArrayOutputStream(); @@ -178,8 +189,11 @@ public class TestByteBloomFilter extends TestCase { } } - // note that actualErr = err * bloomCount - // error rate should be roughly: (keyInterval*2)*(err*2), allow some tolerance + // Dynamic Blooms are a little sneaky. The error rate currently isn't + // 'err', it's err * bloomCount. bloomCount == 2000/1000 == 2 in this case + // So, the actual error rate should be roughly: + // (keyInterval*2) * err * bloomCount + // allow some tolerance System.out.println("False positives: " + falsePositives); assertTrue(falsePositives <= (keyInterval*5)*err); }