siddharthteotia commented on code in PR #12223:
URL: https://github.com/apache/pinot/pull/12223#discussion_r1462857587


##########
pinot-common/src/test/java/org/apache/pinot/common/utils/FALFInternerTest.java:
##########
@@ -0,0 +1,168 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.common.utils;
+
+import com.google.common.collect.Interner;
+import com.google.common.collect.Interners;
+import java.util.Objects;
+import java.util.Random;
+import org.apache.pinot.spi.utils.FALFInterner;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+
+public class FALFInternerTest {
+  @Test
+  public void testInterningByteBuffers() {
+    Random random = new Random(1);
+
+    int nUniqueObjs = 1024;
+    int nTotalObjs = 8 * nUniqueObjs;
+
+    String[] allObjs = new String[nTotalObjs];
+
+    // Create an array of objects where each object should have ~8 copies
+    for (int i = 0; i < nTotalObjs; i++) {
+      int next = random.nextInt(nUniqueObjs);
+      allObjs[i] = Integer.toString(next);
+    }
+
+    Interner<String> exactInterner = Interners.newStrongInterner();
+    Interner<String> falfInterner = new FALFInterner(nUniqueObjs);
+    Interner<String> falfInternerCustomHash = new FALFInterner(nUniqueObjs, s 
-> hashCode((String) s), Objects::equals);
+
+    // Go over all objects and intern them using both exact and FALF interners
+    int nHits1 = runInterning(allObjs, exactInterner, true);
+    int nHits2 = runInterning(allObjs, falfInterner, true);
+    int nHits3 = runInterning(allObjs, falfInternerCustomHash, true);
+
+    System.out.println(nHits1);
+    System.out.println(nHits2);
+    System.out.println(nHits3);
+
+    // For the exact interner, we should get a hit for each object except the
+    // first nUniqueObjs.
+    Assert.assertEquals(nHits1, nTotalObjs - nUniqueObjs);
+
+    // For the FALF interner, due to its fixed size and thus almost inevitable 
hash
+    // collisions, the number of hits is smaller. Let's verify that it's not 
too small, though.
+    Assert.assertTrue(nHits2 > (nTotalObjs - nUniqueObjs) * 0.4);
+
+    // With the better hash function, FALF interner should have more hits
+    Assert.assertTrue(nHits3 > (nTotalObjs - nUniqueObjs) * 0.6);
+
+    // Ad hoc benchmarking code. Disabled to avoid test slowdown.

Review Comment:
   Suggest removing this commented code alltogether or we can put this one in a 
different test case at the end and use the annotation to disable the test



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to