@Test public void testGetTokenRangeToReplica() throws Exception { LongTokenRange range1 = new LongTokenRange(1, 2); LongTokenRange range2 = new LongTokenRange(2, 3); TableReference tableReference = new TableReference("ks", "tb"); TokenRange tokenRange1 = TokenUtil.getRange(1, 2); TokenRange tokenRange2 = TokenUtil.getRange(2, 3); doReturn(Sets.newHashSet(tokenRange1, tokenRange2)).when(mockMetadata).getTokenRanges(eq("ks"), eq(mockReplica1)); doReturn(Sets.newHashSet(mockReplica1, mockReplica2)).when(mockMetadata).getReplicas(eq("ks"), eq(tokenRange1)); doReturn(Sets.newHashSet(mockReplica1, mockReplica3)).when(mockMetadata).getReplicas(eq("ks"), eq(tokenRange2)); ReplicationState replicationState = new ReplicationState(mockMetadata, mockReplica1); Map<LongTokenRange, ImmutableSet<Host>> tokenRangeToReplicas = replicationState.getTokenRangeToReplicas(tableReference); assertThat(tokenRangeToReplicas.keySet()).containsExactlyInAnyOrder(range1, range2); assertThat(tokenRangeToReplicas.get(range1)).containsExactlyInAnyOrder(mockReplica1, mockReplica2); assertThat(tokenRangeToReplicas.get(range2)).containsExactlyInAnyOrder(mockReplica1, mockReplica3); }
public Map<LongTokenRange, ImmutableSet<Host>> getTokenRangeToReplicas(TableReference tableReference) { String keyspace = tableReference.getKeyspace(); ImmutableMap<LongTokenRange, ImmutableSet<Host>> replication = buildTokenMap(keyspace); return keyspaceReplicationCache.compute(keyspace, (k, v) -> !replication.equals(v) ? replication : v); }
ReplicationState { public Map<LongTokenRange, ImmutableSet<Host>> getTokenRangeToReplicas(TableReference tableReference) { String keyspace = tableReference.getKeyspace(); ImmutableMap<LongTokenRange, ImmutableSet<Host>> replication = buildTokenMap(keyspace); return keyspaceReplicationCache.compute(keyspace, (k, v) -> !replication.equals(v) ? replication : v); } }
ReplicationState { public Map<LongTokenRange, ImmutableSet<Host>> getTokenRangeToReplicas(TableReference tableReference) { String keyspace = tableReference.getKeyspace(); ImmutableMap<LongTokenRange, ImmutableSet<Host>> replication = buildTokenMap(keyspace); return keyspaceReplicationCache.compute(keyspace, (k, v) -> !replication.equals(v) ? replication : v); } ReplicationState(Metadata metadata, Host localhost); }
ReplicationState { public Map<LongTokenRange, ImmutableSet<Host>> getTokenRangeToReplicas(TableReference tableReference) { String keyspace = tableReference.getKeyspace(); ImmutableMap<LongTokenRange, ImmutableSet<Host>> replication = buildTokenMap(keyspace); return keyspaceReplicationCache.compute(keyspace, (k, v) -> !replication.equals(v) ? replication : v); } ReplicationState(Metadata metadata, Host localhost); Map<LongTokenRange, ImmutableSet<Host>> getTokenRangeToReplicas(TableReference tableReference); }
ReplicationState { public Map<LongTokenRange, ImmutableSet<Host>> getTokenRangeToReplicas(TableReference tableReference) { String keyspace = tableReference.getKeyspace(); ImmutableMap<LongTokenRange, ImmutableSet<Host>> replication = buildTokenMap(keyspace); return keyspaceReplicationCache.compute(keyspace, (k, v) -> !replication.equals(v) ? replication : v); } ReplicationState(Metadata metadata, Host localhost); Map<LongTokenRange, ImmutableSet<Host>> getTokenRangeToReplicas(TableReference tableReference);  }