joao-r-reis commented on code in PR #1948:
URL: 
https://github.com/apache/cassandra-gocql-driver/pull/1948#discussion_r3248681924


##########
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:
   I would also assert that the replica map is correct, not just that it 
doesn't panic



##########
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"},

Review Comment:
   We should add a couple more test cases, at least one with hosts from both 
dcs. Also I'd generate some test UUIDs on any online uuid generator and use 
them as literals here, it's a bit confusing to see the host id strings like 
that even if they don't break anything in this specific test



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