Source:
private RangeStreamer testSourceTargetComputation(String keyspaceName, int numOldNodes, int replicationFactor) throws UnknownHostException { StorageService ss = StorageService.instance; TokenMetadata tmd = ss.getTokenMetadata(); generateFakeEndpoints(numOldNodes); Token myToken = tmd.partitioner.getRandomToken(); InetAddressAndPort myEndpoint = InetAddressAndPort.getByName("127.0.0.1"); assertEquals(numOldNodes, tmd.sortedTokens().size()); RangeStreamer s = new RangeStreamer(tmd, null, myEndpoint, StreamOperation.BOOTSTRAP, true, DatabaseDescriptor.getEndpointSnitch(), new StreamStateStore(), false, 1); IFailureDetector mockFailureDetector = new IFailureDetector() { public boolean isAlive(InetAddressAndPort ep) { return true; } public void interpret(InetAddressAndPort ep) { throw new UnsupportedOperationException(); } public void report(InetAddressAndPort ep) { throw new UnsupportedOperationException(); } public void registerFailureDetectionEventListener(IFailureDetectionEventListener listener) { throw new UnsupportedOperationException(); } public void unregisterFailureDetectionEventListener(IFailureDetectionEventListener listener) { throw new UnsupportedOperationException(); } public void remove(InetAddressAndPort ep) { throw new UnsupportedOperationException(); } public void forceConviction(InetAddressAndPort ep) { throw new UnsupportedOperationException(); } }; s.addSourceFilter(new RangeStreamer.FailureDetectorSourceFilter(mockFailureDetector)); assertNotNull(Keyspace.open(keyspaceName)); s.addRanges(keyspaceName, Keyspace.open(keyspaceName).getReplicationStrategy().getPendingAddressRanges(tmd, myToken, myEndpoint)); Multimap<InetAddressAndPort, FetchReplica> toFetch = s.toFetch().get(keyspaceName); long rangesCount = toFetch.values().stream() .map(f -> f.remote) .map(Replica::range) .count(); assertEquals(replicationFactor, rangesCount); assert toFetch.values().size() > 0; assert toFetch.keys().stream().noneMatch(myEndpoint::equals); return s; }

Target:
private RangeStreamer testSourceTargetComputation(String keyspaceName, int numOldNodes, int replicationFactor) throws UnknownHostException { StorageService ss = StorageService.instance; TokenMetadata tmd = ss.getTokenMetadata(); generateFakeEndpoints(numOldNodes); Token myToken = tmd.partitioner.getRandomToken(); InetAddressAndPort myEndpoint = InetAddressAndPort.getByName("127.0.0.1"); assertEquals(numOldNodes, tmd.sortedTokens().size()); IFailureDetector mockFailureDetector = new IFailureDetector() { public boolean isAlive(InetAddressAndPort ep) { return true; } public void interpret(InetAddressAndPort ep) { throw new UnsupportedOperationException(); } public void report(InetAddressAndPort ep) { throw new UnsupportedOperationException(); } public void registerFailureDetectionEventListener(IFailureDetectionEventListener listener) { throw new UnsupportedOperationException(); } public void unregisterFailureDetectionEventListener(IFailureDetectionEventListener listener) { throw new UnsupportedOperationException(); } public void remove(InetAddressAndPort ep) { throw new UnsupportedOperationException(); } public void forceConviction(InetAddressAndPort ep) { throw new UnsupportedOperationException(); } }; RangeStreamer s = new RangeStreamer(tmd, null, myEndpoint, StreamOperation.BOOTSTRAP, true, DatabaseDescriptor.getEndpointSnitch(), new StreamStateStore(), mockFailureDetector, false, 1); assertNotNull(Keyspace.open(keyspaceName)); s.addRanges(keyspaceName, Keyspace.open(keyspaceName).getReplicationStrategy().getPendingAddressRanges(tmd, myToken, myEndpoint)); Multimap<InetAddressAndPort, FetchReplica> toFetch = s.toFetch().get(keyspaceName); assertEquals(replicationFactor, toFetch.size()); assert toFetch.values().size() > 0; assert toFetch.keys().stream().noneMatch(myEndpoint::equals); return s; }