arjunashok commented on code in PR #58:
URL: https://github.com/apache/cassandra-sidecar/pull/58#discussion_r1312463547


##########
adapters/base/src/test/java/org/apache/cassandra/sidecar/adapters/base/TokenRangeReplicasTest.java:
##########
@@ -0,0 +1,824 @@
+/*
+ * 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.cassandra.sidecar.adapters.base;
+
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Tests for TokenRangeReplicas
+ */
+public class TokenRangeReplicasTest
+{
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(TokenRangeReplicasTest.class);
+
+    private boolean hasOverlaps(List<TokenRangeReplicas> rangeList)
+    {
+        Collections.sort(rangeList);
+        for (int c = 0, i = 1; i < rangeList.size(); i++)
+        {
+            if (rangeList.get(c++).end().compareTo(rangeList.get(i).start()) > 
0) return true;
+        }
+        return false;
+    }
+
+    private boolean checkContains(List<TokenRangeReplicas> resultList, 
TokenRangeReplicas expected)
+    {
+        return resultList.stream()
+                         .map(TokenRangeReplicas::toString)
+                         .anyMatch(r -> r.equals(expected.toString()));
+    }
+
+    // non-overlapping ranges
+    @Test
+    public void simpleTest()
+    {
+        List<TokenRangeReplicas> simpleList = 
createSimpleTokenRangeReplicaList();
+        LOGGER.info("Input:" + simpleList);
+        List<TokenRangeReplicas> rangeList = 
TokenRangeReplicas.normalize(simpleList);

Review Comment:
   Yep, will add validation for input/output lists match.
   
   The intention behind the current check is that `normalize` does not do 
anything bad when there are no overlaps as the simplest case of the test, with 
other test cases covering the overlapping/sub-set etc. scenarios.



-- 
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