Jackie-Jiang commented on a change in pull request #4220: Adding a simple 
partition function
URL: https://github.com/apache/incubator-pinot/pull/4220#discussion_r285318326
 
 

 ##########
 File path: 
pinot-core/src/test/java/org/apache/pinot/core/data/partition/PartitionFunctionTest.java
 ##########
 @@ -130,4 +130,32 @@ public void testByteArrayPartitioner() {
       }
     }
   }
+
+  @Test
+  public void testHashCodePartitioner() {
+    long seed = System.currentTimeMillis();
+    Random random = new Random(seed);
+
+    for (int i = 0; i < 1000; i++) {
+      int expectedNumPartitions = Math.abs(random.nextInt());
+
+      // Avoid divide-by-zero.
+      if (expectedNumPartitions == 0) {
+        expectedNumPartitions = 1;
+      }
+
+      String functionName = "HaShCoDe";
+      PartitionFunction partitionFunction =
+          PartitionFunctionFactory.getPartitionFunction(functionName, 
expectedNumPartitions);
+      Assert.assertEquals(partitionFunction.toString().toLowerCase(), 
functionName.toLowerCase());
+      Assert.assertEquals(partitionFunction.getNumPartitions(), 
expectedNumPartitions);
+
+      for (int j = 0; j < 1000; j++) {
+        Integer value = random.nextInt();
+        int expectedPartition = Math.abs(value.hashCode()) % 
expectedNumPartitions;
+        Assert.assertEquals(partitionFunction.getPartition(value), 
expectedPartition,
+            "Illegal: " + partitionFunction.getPartition(value) + " " + 
expectedNumPartitions);
 
 Review comment:
   Remove this message, it does not apply to this assert

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to