use of com.datastax.oss.driver.api.core.metadata.token.TokenRange in project dsbulk by datastax.
the class TableReadEndToEndCCMITBase method insertIntoSinglePkTable.
private void insertIntoSinglePkTable(String keyspace, Map<TokenRange, Integer> ranges, Map<Node, Integer> nodes, Metadata metadata, int i, int j) {
ByteBuffer bb1 = TypeCodecs.INT.encode(i, V4);
TokenMap tokenMap = metadata.getTokenMap().get();
Set<Node> replicas = tokenMap.getReplicas(keyspace, bb1);
for (Node replica : replicas) {
nodes.compute(replica, (r, t) -> t == null ? 1 : t + 1);
}
Token token = tokenMap.newToken(bb1);
TokenRange range = tokenMap.getTokenRanges().stream().filter(r -> r.contains(token)).findFirst().orElse(null);
ranges.compute(range, (r, t) -> t == null ? 1 : t + 1);
session.execute(String.format("INSERT INTO \"%s\".\"SINGLE_PK\" (pk, cc, v) VALUES (%d,%d,42)", keyspace, i, j));
}
use of com.datastax.oss.driver.api.core.metadata.token.TokenRange in project dsbulk by datastax.
the class TableReadEndToEndCCMITBase method populateSinglePkTable.
private void populateSinglePkTable(String keyspace) {
Map<TokenRange, Integer> ranges = new HashMap<>();
Map<Node, Integer> nodes = new HashMap<>();
Metadata metadata = session.getMetadata();
expectedTotal = 0;
for (int pk = 0; pk < 100; pk++) {
for (int cc = 0; cc < 100; cc++) {
insertIntoSinglePkTable(keyspace, ranges, nodes, metadata, pk, cc);
expectedTotal++;
}
}
Map<String, Integer> biggestPartitions = new TreeMap<>();
for (int pk = 100; pk < 110; pk++) {
int cc = 0;
for (; cc < pk + 1; cc++) {
insertIntoSinglePkTable(keyspace, ranges, nodes, metadata, pk, cc);
expectedTotal++;
}
biggestPartitions.put(Integer.toString(pk), cc);
}
allBiggestPartitions.computeIfAbsent(keyspace, k -> new HashMap<>()).put("SINGLE_PK", biggestPartitions);
allRanges.computeIfAbsent(keyspace, k -> new HashMap<>()).put("SINGLE_PK", ranges);
allNodes.computeIfAbsent(keyspace, k -> new HashMap<>()).put("SINGLE_PK", nodes);
}
use of com.datastax.oss.driver.api.core.metadata.token.TokenRange in project dsbulk by datastax.
the class TableReadEndToEndCCMITBase method assertCount.
private void assertCount(String keyspace, String table, Set<String> modes) {
assertThat(logs).hasMessageContaining(String.format("Reads: total: %,d", expectedTotal));
assertThat(stderr.getStreamAsStringPlain()).contains("completed successfully");
List<String> lines = stdout.getStreamLines();
if (modes.contains("global")) {
assertThat(lines).contains(Integer.toString(expectedTotal));
}
if (modes.contains("ranges")) {
Map<TokenRange, Integer> ranges = allRanges.get(keyspace).get(table);
for (Map.Entry<TokenRange, Integer> entry : ranges.entrySet()) {
assertThat(lines).anyMatch(line -> line.startsWith(String.format("%s %s %s", TokenUtils.getTokenValue(entry.getKey().getStart()), TokenUtils.getTokenValue(entry.getKey().getEnd()), entry.getValue())));
}
}
if (modes.contains("hosts")) {
Map<Node, Integer> hosts = allNodes.get(keyspace).get(table);
for (Map.Entry<Node, Integer> entry : hosts.entrySet()) {
assertThat(lines).anyMatch(line -> {
EndPoint endPoint = entry.getKey().getEndPoint();
InetSocketAddress addr = (InetSocketAddress) endPoint.resolve();
String ip = addr.getAddress().getHostAddress();
int port = addr.getPort();
// as just "/127.0.0.2:9042"
return line.contains(String.format("%s:%d %s", ip, port, entry.getValue()));
});
}
}
if (modes.contains("partitions")) {
Map<String, Integer> biggestPartitions = allBiggestPartitions.get(keyspace).get(table);
for (Map.Entry<String, Integer> entry : biggestPartitions.entrySet()) {
assertThat(lines).anyMatch(line -> line.startsWith(String.format("%s %s", entry.getKey(), entry.getValue())));
}
}
}
Aggregations