yifan-c commented on code in PR #151:
URL: 
https://github.com/apache/cassandra-analytics/pull/151#discussion_r2475160318


##########
cassandra-analytics-core/src/test/java/org/apache/cassandra/spark/data/PartitionedDataLayerTests.java:
##########
@@ -392,4 +392,45 @@ private static void testSplitReplicas(CassandraRing ring,
             assertThat(replicaSet.primary().size() + 
replicaSet.backup().size()).isEqualTo(replicas.size());
         }
     }
+
+
+    /**
+     * Tests that the AvailabilityHint comparator correctly orders Cassandra 
nodes by availability priority:
+     * UP nodes first, then MOVING/LEAVING nodes, and finally 
DOWN/UNKNOWN/JOINING nodes last.
+     */
+    @Test
+    public void testSortingByAvailabilityHintComparator()
+    {
+        List<PartitionedDataLayer.AvailabilityHint> hints = Arrays.asList(UP, 
MOVING, LEAVING, UNKNOWN, JOINING, DOWN);
+
+        for (int i = 0; i < 5; i++)
+        {
+            validateHintsSequence(hints, 1, 3);
+        }
+
+        hints = Arrays.asList(UP, UP, UP, MOVING, MOVING, LEAVING, UNKNOWN, 
UNKNOWN, UNKNOWN, JOINING, DOWN, DOWN, DOWN, DOWN, DOWN, DOWN);
+
+        for (int i = 0; i < 5; i++)
+        {
+            validateHintsSequence(hints, 3, 6);
+        }
+    }
+
+    private static void 
validateHintsSequence(List<PartitionedDataLayer.AvailabilityHint> hints, int 
index1, int index2)
+    {
+        List<PartitionedDataLayer.AvailabilityHint> shuffledHints = new 
ArrayList<>(hints);
+        Collections.shuffle(shuffledHints);
+        // Test expected ordering: UP > MOVING/LEAVING > UNKNOWN/JOINING/DOWN
+        List<PartitionedDataLayer.AvailabilityHint> sorted = new 
ArrayList<>(shuffledHints);
+        sorted.sort(AVAILABILITY_HINT_COMPARATOR);
+
+        // Verify UP comes first (highest priority)
+        assertThat(sorted.subList(0, 
index1)).contains(UP).doesNotContain(MOVING, LEAVING, UNKNOWN, JOINING, DOWN);
+
+        // Verify MOVING, LEAVING are in the middle
+        assertThat(sorted.subList(index1, index2)).contains(MOVING, 
LEAVING).doesNotContain(UP, DOWN, UNKNOWN, JOINING);
+
+        // Verify DOWN, UNKNOWN, JOINING come last (lowest priority)
+        assertThat(sorted.subList(index2, sorted.size())).contains(DOWN, 
UNKNOWN, JOINING).doesNotContain(UP, MOVING, LEAVING);
+    }

Review Comment:
   nit: let's assign descriptive names for the index. Or, why not just 
comparing the shuffled list equals to the original list after sorting? So you 
can just have `assertThat(sorted).isEqualTo(hints);`
    
   ```suggestion
       private static void 
validateHintsSequence(List<PartitionedDataLayer.AvailabilityHint> hints, int 
upCounts, int movingOrLeavingCounts)
       {
           List<PartitionedDataLayer.AvailabilityHint> shuffledHints = new 
ArrayList<>(hints);
           Collections.shuffle(shuffledHints);
           // Test expected ordering: UP > MOVING/LEAVING > UNKNOWN/JOINING/DOWN
           List<PartitionedDataLayer.AvailabilityHint> sorted = new 
ArrayList<>(shuffledHints);
           sorted.sort(AVAILABILITY_HINT_COMPARATOR);
   
           // Verify UP comes first (highest priority)
           assertThat(sorted.subList(0, 
upCounts)).contains(UP).doesNotContain(MOVING, LEAVING, UNKNOWN, JOINING, DOWN);
   
           // Verify MOVING, LEAVING are in the middle
           assertThat(sorted.subList(upCounts, 
movingOrLeavingCounts)).contains(MOVING, LEAVING).doesNotContain(UP, DOWN, 
UNKNOWN, JOINING);
   
           // Verify DOWN, UNKNOWN, JOINING come last (lowest priority)
           assertThat(sorted.subList(movingOrLeavingCounts, 
sorted.size())).contains(DOWN, UNKNOWN, JOINING).doesNotContain(UP, MOVING, 
LEAVING);
       }
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to