worryg0d commented on code in PR #1948:
URL: 
https://github.com/apache/cassandra-gocql-driver/pull/1948#discussion_r3268615093


##########
topology_test.go:
##########
@@ -224,3 +226,33 @@ func TestPlacementStrategy_NetworkStrategy(t *testing.T) {
                })
        }
 }
+
+// Regression test for CASSGO-122:
+// when the token ring only contains hosts from a DC that has RF=0/unspecified 
for a keyspace,
+// networkTopology.replicaMap should not panic; it should return an empty 
replica map.
+func TestPlacementStrategy_NetworkStrategy_DoNotPanicWhenNoReplicasInRing(t 
*testing.T) {
+       strat := newNetworkTopology(map[string]int{
+               "dc1": 3, // replicated only in dc1
+       })
+
+       // Hosts in ring only from dc2, so no replicas should be returned.
+       hosts := []*HostInfo{
+               {hostId: "dc2:rack1:0", dataCenter: "dc2", rack: "rack1"},
+               {hostId: "dc2:rack2:1", dataCenter: "dc2", rack: "rack2"},
+               {hostId: "dc2:rack3:2", dataCenter: "dc2", rack: "rack3"},
+       }
+
+       tokens := make([]hostToken, 0, len(hosts))
+       for _, h := range hosts {
+               tokens = append(tokens, hostToken{
+                       token: orderedToken(h.hostId),
+                       host:  h,
+               })
+       }
+       sort.Sort(&tokenRing{tokens: tokens})
+
+       require.NotPanics(t, func() {
+               replicas := strat.replicaMap(&tokenRing{hosts: hosts, tokens: 
tokens})
+               require.Empty(t, replicas, "expected no replicas, got %d", 
len(replicas))
+       })

Review Comment:
   There is require.Empty assertion:
   ```
   require.Empty(t, replicas, "expected no replicas, got %d", len(replicas))
   ```



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