Search in sources :

Example 21 with TokenRange

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));
}
Also used : Node(com.datastax.oss.driver.api.core.metadata.Node) Token(com.datastax.oss.driver.api.core.metadata.token.Token) TokenRange(com.datastax.oss.driver.api.core.metadata.token.TokenRange) TokenMap(com.datastax.oss.driver.api.core.metadata.TokenMap) ByteBuffer(java.nio.ByteBuffer)

Example 22 with TokenRange

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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BeforeEach(org.junit.jupiter.api.BeforeEach) CCMRequirements(com.datastax.oss.dsbulk.tests.ccm.annotations.CCMRequirements) MockConnector(com.datastax.oss.dsbulk.runner.tests.MockConnector) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) ByteBuffer(java.nio.ByteBuffer) AfterAll(org.junit.jupiter.api.AfterAll) Lists(com.datastax.oss.driver.shaded.guava.common.collect.Lists) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) ConsistencyLevel(com.datastax.oss.driver.api.core.ConsistencyLevel) ONE_MINUTE(org.awaitility.Durations.ONE_MINUTE) LogInterceptor(com.datastax.oss.dsbulk.tests.logging.LogInterceptor) StreamInterceptor(com.datastax.oss.dsbulk.tests.logging.StreamInterceptor) Awaitility.await(org.awaitility.Awaitility.await) TestAssertions.assertThat(com.datastax.oss.dsbulk.tests.assertions.TestAssertions.assertThat) StringUtils(com.datastax.oss.dsbulk.tests.utils.StringUtils) Set(java.util.Set) Arguments(org.junit.jupiter.params.provider.Arguments) InetSocketAddress(java.net.InetSocketAddress) STATUS_OK(com.datastax.oss.dsbulk.runner.ExitStatus.STATUS_OK) List(java.util.List) Type(com.datastax.oss.dsbulk.tests.ccm.CCMCluster.Type) Stream(java.util.stream.Stream) ExitStatus(com.datastax.oss.dsbulk.runner.ExitStatus) EndPoint(com.datastax.oss.driver.api.core.metadata.EndPoint) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource) Node(com.datastax.oss.driver.api.core.metadata.Node) CsvSource(org.junit.jupiter.params.provider.CsvSource) CQLUtils(com.datastax.oss.dsbulk.tests.utils.CQLUtils) ImmutableSet(com.datastax.oss.driver.shaded.guava.common.collect.ImmutableSet) TokenRange(com.datastax.oss.driver.api.core.metadata.token.TokenRange) TokenMap(com.datastax.oss.driver.api.core.metadata.TokenMap) HashMap(java.util.HashMap) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) ArrayList(java.util.ArrayList) Version(com.datastax.oss.driver.api.core.Version) CqlSession(com.datastax.oss.driver.api.core.CqlSession) V4(com.datastax.oss.driver.api.core.DefaultProtocolVersion.V4) Assumptions.assumeTrue(org.junit.jupiter.api.Assumptions.assumeTrue) EndToEndUtils.assertStatus(com.datastax.oss.dsbulk.runner.tests.EndToEndUtils.assertStatus) CCMCluster(com.datastax.oss.dsbulk.tests.ccm.CCMCluster) Metadata(com.datastax.oss.driver.api.core.metadata.Metadata) ArgumentsProvider(org.junit.jupiter.params.provider.ArgumentsProvider) RoutingKey.compose(com.datastax.oss.driver.internal.core.util.RoutingKey.compose) Token(com.datastax.oss.driver.api.core.metadata.token.Token) DataStaxBulkLoader(com.datastax.oss.dsbulk.runner.DataStaxBulkLoader) CCMVersionRequirement(com.datastax.oss.dsbulk.tests.ccm.annotations.CCMVersionRequirement) TokenUtils(com.datastax.oss.dsbulk.partitioner.utils.TokenUtils) TypeCodecs(com.datastax.oss.driver.api.core.type.codec.TypeCodecs) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) TreeMap(java.util.TreeMap) Collections(java.util.Collections) HashMap(java.util.HashMap) Node(com.datastax.oss.driver.api.core.metadata.Node) Metadata(com.datastax.oss.driver.api.core.metadata.Metadata) TokenRange(com.datastax.oss.driver.api.core.metadata.token.TokenRange) TreeMap(java.util.TreeMap) EndPoint(com.datastax.oss.driver.api.core.metadata.EndPoint)

Example 23 with TokenRange

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())));
        }
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Node(com.datastax.oss.driver.api.core.metadata.Node) EndPoint(com.datastax.oss.driver.api.core.metadata.EndPoint) EndPoint(com.datastax.oss.driver.api.core.metadata.EndPoint) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TokenRange(com.datastax.oss.driver.api.core.metadata.token.TokenRange) Map(java.util.Map) TokenMap(com.datastax.oss.driver.api.core.metadata.TokenMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Aggregations

TokenRange (com.datastax.oss.driver.api.core.metadata.token.TokenRange)23 Node (com.datastax.oss.driver.api.core.metadata.Node)11 TokenMap (com.datastax.oss.driver.api.core.metadata.TokenMap)10 Token (com.datastax.oss.driver.api.core.metadata.token.Token)10 Test (org.junit.Test)6 ByteBuffer (java.nio.ByteBuffer)5 ArrayList (java.util.ArrayList)5 CqlSession (com.datastax.oss.driver.api.core.CqlSession)4 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)3 EndPoint (com.datastax.oss.driver.api.core.metadata.EndPoint)3 ImmutableSet (com.datastax.oss.driver.shaded.guava.common.collect.ImmutableSet)3 NonNull (edu.umd.cs.findbugs.annotations.NonNull)3 Map (java.util.Map)3 ConsistencyLevel (com.datastax.oss.driver.api.core.ConsistencyLevel)2 V4 (com.datastax.oss.driver.api.core.DefaultProtocolVersion.V4)2 Version (com.datastax.oss.driver.api.core.Version)2 Row (com.datastax.oss.driver.api.core.cql.Row)2 Metadata (com.datastax.oss.driver.api.core.metadata.Metadata)2 TypeCodecs (com.datastax.oss.driver.api.core.type.codec.TypeCodecs)2 ChannelPool (com.datastax.oss.driver.internal.core.pool.ChannelPool)2