datastax/java-driver — pull request #137 by davibo (2013-12-04 13:25:31+00:00)
Title: Fix ReplicationStrategy class (affects Metadata.getReplicas and TokenAwarePolicy)

Current implementation of ReplicationStrategy in 2.0 branch is incorrect
(1) does not correctly recognize NetworkTopologyStrategy
(2) SimpleStrategy does not find all replicas when nodes are handling consecutive token segments (e.g. ring looks like node1, node1, node2...)
(3) current implementation (that is actually never used because of (1)) of NetworkTopologyStrategy does not reflect the 2.0.x Cassandra server's implementation: rack placement is not considered. Additionally current implementation always yields replicas from the start of the ring and has the same problem as SimpleStrategy (2)

These issues result in Metadata.getReplicas not returning all replicas or returning incorrect ones and TokenAwarePolicy not always routing to the replica nodes when the keyspace is using NetworkTopologyStrategy (i.e. no optimization happens compared to DCAwareRoundRobinPolicy).

This request fixes the issues listed above and adds unit tests to cover this functionality. Unit tests are using hardcoded ring topologies and do not rely on CCM.

Additionally, the implementation of NetworkTopologyStrategy is essentially a duplication of the logic in org.apache.cassandra.locator.NetworkTopologyStrategy. This is a potential problem, but I'm not aware of any existing ways of sharing server/client code in current codebase.