@Override public Set<Host> getReplicas(String caseSensitiveSchemaName, TokenRange tokenRange) { requireNonNull(caseSensitiveSchemaName, "keyspace is null"); requireNonNull(tokenRange, "tokenRange is null"); return executeWithSession(session -> session.getCluster().getMetadata().getReplicas(validSchemaName(caseSensitiveSchemaName), tokenRange)); }
@Override public Set<Host> getReplicas(String caseSensitiveSchemaName, ByteBuffer partitionKey) { requireNonNull(caseSensitiveSchemaName, "keyspace is null"); requireNonNull(partitionKey, "partitionKey is null"); return executeWithSession(session -> session.getCluster().getMetadata().getReplicas(validSchemaName(caseSensitiveSchemaName), partitionKey)); }
private Map<TokenRange, Set<Host>> getRangeMap() { Metadata metadata = this.session.metadata(); return metadata.getTokenRanges().stream().collect(Collectors.toMap( p -> p, p -> metadata.getReplicas('"' + this.keyspace + '"', p))); }
return childPolicy.newQueryPlan(keyspace, statement); final Set<Host> replicas = clusterMetadata.getReplicas(Metadata.quote(keyspace), partitionKey); if (replicas.isEmpty()) return childPolicy.newQueryPlan(loggedKeyspace, statement);
@BeforeMethod(groups = "unit") public void initMocks() { CodecRegistry codecRegistry = new CodecRegistry(); cluster = mock(Cluster.class); Configuration configuration = mock(Configuration.class); ProtocolOptions protocolOptions = mock(ProtocolOptions.class); Metadata metadata = mock(Metadata.class); childPolicy = mock(LoadBalancingPolicy.class); when(cluster.getConfiguration()).thenReturn(configuration); when(configuration.getCodecRegistry()).thenReturn(codecRegistry); when(configuration.getProtocolOptions()).thenReturn(protocolOptions); when(protocolOptions.getProtocolVersion()).thenReturn(ProtocolVersion.NEWEST_SUPPORTED); when(cluster.getMetadata()).thenReturn(metadata); when(metadata.getReplicas(Metadata.quote("keyspace"), routingKey)) .thenReturn(Sets.newLinkedHashSet(host1, host2)); when(childPolicy.newQueryPlan("keyspace", statement)) .thenReturn(Sets.newLinkedHashSet(host4, host3, host2, host1).iterator()); when(childPolicy.distance(any(Host.class))).thenReturn(HostDistance.LOCAL); when(host1.isUp()).thenReturn(true); when(host2.isUp()).thenReturn(true); when(host3.isUp()).thenReturn(true); when(host4.isUp()).thenReturn(true); }
@Test(groups = "short", dataProvider = "newKeyspaceName") public void should_notify_of_keyspace_drop(String keyspace) throws InterruptedException { execute(CREATE_KEYSPACE, keyspace); for (SchemaChangeListener listener : listeners) { ArgumentCaptor<KeyspaceMetadata> added = ArgumentCaptor.forClass(KeyspaceMetadata.class); verify(listener, timeout(NOTIF_TIMEOUT_MS).times(1)).onKeyspaceAdded(added.capture()); assertThat(added.getValue()).hasName(handleId(keyspace)); } for (Metadata m : metadatas()) assertThat(m.getReplicas(keyspace, Bytes.fromHexString("0xCAFEBABE"))).isNotEmpty(); execute(CREATE_TABLE, keyspace); // to test table drop notifications execute(DROP_KEYSPACE, keyspace); for (SchemaChangeListener listener : listeners) { ArgumentCaptor<TableMetadata> table = ArgumentCaptor.forClass(TableMetadata.class); verify(listener, timeout(NOTIF_TIMEOUT_MS).times(1)).onTableRemoved(table.capture()); assertThat(table.getValue()).hasName("table1").isInKeyspace(handleId(keyspace)); ArgumentCaptor<KeyspaceMetadata> ks = ArgumentCaptor.forClass(KeyspaceMetadata.class); verify(listener, timeout(NOTIF_TIMEOUT_MS).times(1)).onKeyspaceRemoved(ks.capture()); assertThat(ks.getValue()).hasName(handleId(keyspace)); } for (Metadata m : metadatas()) { assertThat(m.getKeyspace(keyspace)).isNull(); assertThat(m.getReplicas(keyspace, Bytes.fromHexString("0xCAFEBABE"))).isEmpty(); } }
private Map<TokenRange, Set<Host>> getRangeMap(String keyspace, Metadata metadata) { return metadata.getTokenRanges() .stream() .collect(toMap(p -> p, p -> metadata.getReplicas('"' + keyspace + '"', p))); }
private Map<TokenRange, Set<Host>> getRangeMap(String keyspace, Metadata metadata) { return metadata.getTokenRanges() .stream() .collect(toMap(p -> p, p -> metadata.getReplicas('"' + keyspace + '"', p))); }
private Map<TokenRange, Set<Host>> getRangeMap(String keyspace, Metadata metadata) { return metadata.getTokenRanges() .stream() .collect(toMap(p -> p, p -> metadata.getReplicas('"' + keyspace + '"', p))); }
/** JAVA-684: Empty TokenRange returned in a one token cluster */ @Test(groups = "short") public void should_return_single_non_empty_range_when_cluster_has_one_single_token() { cluster().manager.controlConnection.refreshNodeListAndTokenMap(); Metadata metadata = cluster().getMetadata(); Set<TokenRange> tokenRanges = metadata.getTokenRanges(); assertThat(tokenRanges).hasSize(1); TokenRange tokenRange = tokenRanges.iterator().next(); assertThat(tokenRange) .startsWith(Token.M3PToken.FACTORY.minToken()) .endsWith(Token.M3PToken.FACTORY.minToken()) .isNotEmpty() .isNotWrappedAround(); Set<Host> hostsForRange = metadata.getReplicas(keyspace, tokenRange); Host host1 = TestUtils.findHost(cluster(), 1); assertThat(hostsForRange).containsOnly(host1); ByteBuffer randomPartitionKey = Bytes.fromHexString("0xCAFEBABE"); Set<Host> hostsForKey = metadata.getReplicas(keyspace, randomPartitionKey); assertThat(hostsForKey).containsOnly(host1); Set<TokenRange> rangesForHost = metadata.getTokenRanges(keyspace, host1); assertThat(rangesForHost).containsOnly(tokenRange); } }
metadata.getReplicas( ks1, TypeCodec.cint() foundRange = range; assertThat(metadata.getReplicas(ks1, range)).contains(replica);
private Map<TokenRange, Set<Host>> getRangeMap() { Metadata metadata = this.session.metadata(); return metadata.getTokenRanges().stream().collect(Collectors.toMap( p -> p, p -> metadata.getReplicas('"' + this.keyspace + '"', p))); }
public NativeRingCache(Configuration conf, Metadata metadata) { this.partitioner = ConfigHelper.getOutputPartitioner(conf); this.metadata = metadata; String keyspace = ConfigHelper.getOutputKeyspace(conf); this.rangeMap = metadata.getTokenRanges() .stream() .collect(toMap(p -> p, p -> metadata.getReplicas('"' + keyspace + '"', p))); }
public NativeRingCache(Configuration conf, Metadata metadata) { this.partitioner = ConfigHelper.getOutputPartitioner(conf); this.metadata = metadata; String keyspace = ConfigHelper.getOutputKeyspace(conf); this.rangeMap = metadata.getTokenRanges() .stream() .collect(toMap(p -> p, p -> metadata.getReplicas('"' + keyspace + '"', p))); }
public NativeRingCache(Configuration conf, Metadata metadata) { this.partitioner = ConfigHelper.getOutputPartitioner(conf); this.metadata = metadata; String keyspace = ConfigHelper.getOutputKeyspace(conf); this.rangeMap = metadata.getTokenRanges() .stream() .collect(toMap(p -> p, p -> metadata.getReplicas('"' + keyspace + '"', p))); }
@Override public Set<Host> getReplicas(String caseSensitiveSchemaName, ByteBuffer partitionKey) { requireNonNull(caseSensitiveSchemaName, "keyspace is null"); requireNonNull(partitionKey, "partitionKey is null"); return executeWithSession(session -> session.getCluster().getMetadata().getReplicas(validSchemaName(caseSensitiveSchemaName), partitionKey)); }
@Override public Set<Host> getReplicas(String caseSensitiveSchemaName, ByteBuffer partitionKey) { requireNonNull(caseSensitiveSchemaName, "keyspace is null"); requireNonNull(partitionKey, "partitionKey is null"); return executeWithSession(session -> session.getCluster().getMetadata().getReplicas(validSchemaName(caseSensitiveSchemaName), partitionKey)); }
@Override public Set<Host> getReplicas(String caseSensitiveSchemaName, TokenRange tokenRange) { requireNonNull(caseSensitiveSchemaName, "keyspace is null"); requireNonNull(tokenRange, "tokenRange is null"); return executeWithSession(session -> session.getCluster().getMetadata().getReplicas(validSchemaName(caseSensitiveSchemaName), tokenRange)); }
@Override public Set<Host> getReplicas(String caseSensitiveSchemaName, TokenRange tokenRange) { requireNonNull(caseSensitiveSchemaName, "keyspace is null"); requireNonNull(tokenRange, "tokenRange is null"); return executeWithSession(session -> session.getCluster().getMetadata().getReplicas(validSchemaName(caseSensitiveSchemaName), tokenRange)); }
Lists.newArrayList(cluster.getMetadata().getReplicas("keyspace", routingKey)); assertThat(replicas) .containsExactly(