Skip to content
Browse files

* added bloom filter test

  • Loading branch information...
1 parent 6d1f0ab commit 58b1d82bdba61769f30f597c5f5b7f683e3b04bc @pruivo pruivo committed Sep 12, 2012
Showing with 49 additions and 0 deletions.
  1. +49 −0 core/src/test/java/org/infinispan/dataplacement/BloomFilterTest.java
View
49 core/src/test/java/org/infinispan/dataplacement/BloomFilterTest.java
@@ -0,0 +1,49 @@
+package org.infinispan.dataplacement;
+
+import org.infinispan.dataplacement.c50.lookup.BloomFilter;
+import org.infinispan.util.logging.Log;
+import org.infinispan.util.logging.LogFactory;
+import org.testng.annotations.Test;
+
+/**
+ * // TODO: Document this
+ *
+ * @author Pedro Ruivo
+ * @since 5.2
+ */
+@Test(groups = "functional", testName = "dataplacement.BloomFilterTest")
+public class BloomFilterTest {
+
+ private static final Log log = LogFactory.getLog(BloomFilterTest.class);
+
+ private static final int START = 10;
+ private static final int END = 10000000;
+ private static final double PROB = 0.001;
+
+ public void testBloomFilter() {
+
+ for (int iteration = START; iteration <= END; iteration *= 10) {
+ BloomFilter bloomFilter = new BloomFilter(PROB, iteration);
+ for (int key = 0; key < iteration; ++key) {
+ bloomFilter.add(getKey(key));
+ }
+
+ log.infof("=== Iterator with %s objects ===", iteration);
+ log.infof("Bloom filter size = %s", bloomFilter.size());
+
+ long begin = System.currentTimeMillis();
+ for (int key = 0; key < iteration; ++key) {
+ assert bloomFilter.contains(getKey(key)) : "False Negative should not happen!";
+ }
+ long end = System.currentTimeMillis();
+
+ log.infof("Query duration:\n\ttotal=%s ms\n\tper-key=%s ms", end - begin, (end - begin) / iteration);
+ }
+
+ }
+
+ private String getKey(int index) {
+ return "KEY_" + index;
+ }
+
+}

0 comments on commit 58b1d82

Please sign in to comment.
Something went wrong with that request. Please try again.