worryg0d commented on code in PR #1948:
URL:
https://github.com/apache/cassandra-gocql-driver/pull/1948#discussion_r3257129967
##########
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 already have tests for this actually:
https://github.com/apache/cassandra-gocql-driver/blob/c65c762b83eccdb6a6a083c123a5935c4302745c/topology_test.go#L78
> it's a bit confusing to see the host id strings like that even if they
don't break anything in this specific test
I use this `hostId` to construct a token in tokenRing on my own. The value
of such approach is that it makes easier for devs to understand in which order
tokens will be ordered. I can update it if you insist, but it won't matter
because ring is manually constructed:
```
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})
```
--
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]