maedhroz commented on code in PR #3350:
URL: https://github.com/apache/cassandra/pull/3350#discussion_r1679774423


##########
test/unit/org/apache/cassandra/index/IndexStatusManagerTest.java:
##########
@@ -0,0 +1,393 @@
+/*
+ * 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.index;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+import org.apache.cassandra.exceptions.ReadFailureException;
+import org.apache.cassandra.gms.VersionedValue;
+import org.apache.cassandra.locator.*;
+import org.apache.cassandra.utils.JsonUtils;
+import org.junit.Test;
+
+import org.apache.cassandra.db.ConsistencyLevel;
+import org.apache.cassandra.db.Keyspace;
+import org.apache.cassandra.schema.IndexMetadata;
+import org.mockito.Mockito;
+
+import static org.apache.cassandra.locator.ReplicaUtils.full;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertArrayEquals;
+
+public class IndexStatusManagerTest
+{
+    static class Testcase
+    {
+        String keyspace;
+        int minRequiredNodes;
+        AbstractReplicationStrategy replicationStrategy;
+        Map<InetAddressAndPort, Map<String, Index.Status>> indexStatus;
+        EndpointsForRange expected;
+
+        Testcase(Builder builder)
+        {
+            keyspace = builder.keyspace;
+            minRequiredNodes = builder.minRequiredNodes;
+            replicationStrategy = builder.replicationStrategy;
+            indexStatus = builder.indexStatus;
+            expected = builder.expected;
+        }
+
+        static class Builder
+        {
+            String keyspace;
+            int minRequiredNodes;
+            AbstractReplicationStrategy replicationStrategy;
+            Map<InetAddressAndPort, Map<String, Index.Status>> indexStatus;
+            EndpointsForRange expected;
+
+            Builder keyspace(String kp)
+            {
+                keyspace = kp;
+                return this;
+            }
+
+            Builder minRequiredNodes(int required)
+            {
+                minRequiredNodes = required;
+                return this;
+            }
+
+            Builder replicationStrategy(AbstractReplicationStrategy strategy)
+            {
+                replicationStrategy = strategy;
+                return this;
+            }
+
+            Builder indexStatus(Map<InetAddressAndPort, Map<String, 
Index.Status>> status)
+            {
+                indexStatus = status;
+                return this;
+            }
+
+            Builder expected(EndpointsForRange endpoints)
+            {
+                expected = endpoints;
+                return this;
+            }
+
+            Testcase build()
+            {
+                return new Testcase(this);
+            }
+        }
+    }
+
+    // we have enough BUILD_SUCCEEDED endpoints: filterForQuery should 
prioritize them, even if the other endpoints'
+    // indexes are queryable but not built (like UNKNOWN)
+    @Test
+    public void filterForQuery_ShouldPrioritizeSuccessfulEndpoints()
+    {
+        runTest("exactly enough endpoints with BUILD_SUCCEEDED indexes",
+                new Testcase.Builder()
+                        .keyspace("ks1")
+                        .replicationStrategy(new 
NetworkTopologyStrategy("ks1", Map.of("DC", "5")))
+                        .indexStatus(Map.of(
+                                
InetAddressAndPort.getByNameUnchecked("127.0.0.255"),
+                                Map.of(
+                                        "ks1.idx1", 
Index.Status.BUILD_SUCCEEDED,
+                                        "ks1.idx2", 
Index.Status.BUILD_SUCCEEDED,
+                                        "ks1.idx3", Index.Status.UNKNOWN
+                                ),
+                                
InetAddressAndPort.getByNameUnchecked("127.0.0.254"),
+                                Map.of(
+                                        "ks1.idx1", 
Index.Status.BUILD_SUCCEEDED,
+                                        "ks1.idx2", 
Index.Status.BUILD_SUCCEEDED,
+                                        "ks1.idx3", 
Index.Status.BUILD_SUCCEEDED
+                                ),
+                                
InetAddressAndPort.getByNameUnchecked("127.0.0.253"),
+                                Map.of(
+                                        "ks1.idx1", 
Index.Status.BUILD_SUCCEEDED,
+                                        "ks1.idx2", Index.Status.UNKNOWN,
+                                        "ks1.idx3", 
Index.Status.BUILD_SUCCEEDED
+                                )
+                        ))
+                        .minRequiredNodes(1)
+                        .expected(EndpointsForRange.of(
+                                
full(InetAddressAndPort.getByNameUnchecked("127.0.0.254"))
+                        ))
+                        .build()
+        );
+
+        runTest("more than enough endpoints with BUILD_SUCCEEDED indexes",
+                new Testcase.Builder()
+                        .keyspace("ks1")
+                        .replicationStrategy(new 
NetworkTopologyStrategy("ks1", Map.of("DC", "5")))
+                        .indexStatus(Map.of(
+                                
InetAddressAndPort.getByNameUnchecked("127.0.0.255"),
+                                Map.of(
+                                        "ks1.idx1", 
Index.Status.BUILD_SUCCEEDED,
+                                        "ks1.idx2", 
Index.Status.BUILD_SUCCEEDED,
+                                        "ks1.idx3", Index.Status.UNKNOWN
+                                ),
+                                
InetAddressAndPort.getByNameUnchecked("127.0.0.254"),
+                                Map.of(
+                                        "ks1.idx1", 
Index.Status.BUILD_SUCCEEDED,
+                                        "ks1.idx2", 
Index.Status.BUILD_SUCCEEDED,
+                                        "ks1.idx3", 
Index.Status.BUILD_SUCCEEDED
+                                ),
+                                
InetAddressAndPort.getByNameUnchecked("127.0.0.253"),
+                                Map.of(
+                                        "ks1.idx1", Index.Status.UNKNOWN,
+                                        "ks1.idx2", 
Index.Status.BUILD_SUCCEEDED,
+                                        "ks1.idx3", 
Index.Status.BUILD_SUCCEEDED
+                                ),
+                                
InetAddressAndPort.getByNameUnchecked("127.0.0.252"),
+                                Map.of(
+                                        "ks1.idx1", 
Index.Status.BUILD_SUCCEEDED,
+                                        "ks1.idx2", 
Index.Status.BUILD_SUCCEEDED,
+                                        "ks1.idx3", 
Index.Status.BUILD_SUCCEEDED
+                                ),
+                                
InetAddressAndPort.getByNameUnchecked("127.0.0.251"),
+                                Map.of(
+                                        "ks1.idx1", 
Index.Status.BUILD_SUCCEEDED,
+                                        "ks1.idx2", 
Index.Status.BUILD_SUCCEEDED,
+                                        "ks1.idx3", 
Index.Status.BUILD_SUCCEEDED
+                                )
+                        ))
+                        .minRequiredNodes(2)
+                        .expected(EndpointsForRange.of(
+                                
full(InetAddressAndPort.getByNameUnchecked("127.0.0.254")),
+                                
full(InetAddressAndPort.getByNameUnchecked("127.0.0.252")),
+                                
full(InetAddressAndPort.getByNameUnchecked("127.0.0.251"))
+                        ))
+                        .build()
+        );
+    }
+
+    // we don't have enough BUILD_SUCCEEDED endpoints: filterForQuery should 
return all queryable endpoints
+    @Test
+    public void 
filterForQuery_ReturnAllEndpointsWhenNotEnoughSuccessfulEndpoints()

Review Comment:
   ```suggestion
       public void shouldIncludeUnknownEndpointsWhenNotEnoughSucceeded()
   ```



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