Search in sources :

Example 1 with CassandraRing

use of org.apache.cassandra.spark.data.partitioner.CassandraRing in project spark-cassandra-bulkreader by jberragan.

the class KryoSerializationTests method testCassandraRing.

@Test
public void testCassandraRing() {
    qt().forAll(TestUtils.partitioners()).checkAssert(partitioner -> {
        final CassandraRing ring = TestUtils.createRing(partitioner, ImmutableMap.of("DC1", 3, "DC2", 3));
        final Output out = KryoSerializationTests.serialize(ring);
        final CassandraRing deserialized = KryoSerializationTests.deserialize(out, CassandraRing.class);
        assertNotNull(deserialized);
        assertEquals(ring, deserialized);
        assertEquals(partitioner, deserialized.partitioner());
    });
}
Also used : CassandraRing(org.apache.cassandra.spark.data.partitioner.CassandraRing) Output(com.esotericsoftware.kryo.io.Output) Test(org.junit.Test)

Example 2 with CassandraRing

use of org.apache.cassandra.spark.data.partitioner.CassandraRing in project spark-cassandra-bulkreader by jberragan.

the class KryoSerializationTests method testTokenPartitioner.

@Test
public void testTokenPartitioner() {
    qt().forAll(TestUtils.partitioners(), arbitrary().pick(Arrays.asList(3, 16, 128)), arbitrary().pick(Arrays.asList(1, 4, 16)), arbitrary().pick(Arrays.asList(4, 16, 64))).checkAssert((partitioner, numInstances, defaultParallelism, numCores) -> {
        final CassandraRing ring = TestUtils.createRing(partitioner, numInstances);
        final TokenPartitioner tokenPartitioner = new TokenPartitioner(ring, defaultParallelism, numCores);
        final Output out = KryoSerializationTests.serialize(tokenPartitioner);
        final TokenPartitioner deserialized = KryoSerializationTests.deserialize(out, TokenPartitioner.class);
        assertNotNull(deserialized);
        assertEquals(tokenPartitioner.numPartitions(), deserialized.numPartitions());
        assertEquals(tokenPartitioner.subRanges().size(), deserialized.subRanges().size());
        for (int i = 0; i < tokenPartitioner.subRanges().size(); i++) {
            assertEquals(tokenPartitioner.subRanges().get(i), deserialized.subRanges().get(i));
        }
        assertEquals(tokenPartitioner.ring(), deserialized.ring());
    });
}
Also used : CassandraRing(org.apache.cassandra.spark.data.partitioner.CassandraRing) Output(com.esotericsoftware.kryo.io.Output) TokenPartitioner(org.apache.cassandra.spark.data.partitioner.TokenPartitioner) Test(org.junit.Test)

Example 3 with CassandraRing

use of org.apache.cassandra.spark.data.partitioner.CassandraRing in project spark-cassandra-bulkreader by jberragan.

the class PartitionKeyFilterTests method testTokenRing.

@Test
public void testTokenRing() {
    qt().forAll(TestUtils.partitioners(), arbitrary().pick(Arrays.asList(1, 3, 6, 12, 128))).checkAssert((partitioner, numInstances) -> {
        final CassandraRing ring = TestUtils.createRing(partitioner, numInstances);
        final TokenPartitioner tokenPartitioner = new TokenPartitioner(ring, 24, 24);
        final List<BigInteger> boundaryTokens = IntStream.range(0, tokenPartitioner.numPartitions()).mapToObj(tokenPartitioner::getTokenRange).map(r -> Arrays.asList(r.lowerEndpoint(), midPoint(r), r.upperEndpoint())).flatMap(Collection::stream).collect(Collectors.toList());
        for (final BigInteger token : boundaryTokens) {
            // check boundary tokens only match 1 Spark token range
            final PartitionKeyFilter filter = PartitionKeyFilter.create(Int32Type.instance.fromString("11"), token);
            assertEquals(1, tokenPartitioner.subRanges().stream().filter(filter::overlaps).count());
        }
    });
}
Also used : CassandraRing(org.apache.cassandra.spark.data.partitioner.CassandraRing) BigInteger(java.math.BigInteger) TokenPartitioner(org.apache.cassandra.spark.data.partitioner.TokenPartitioner) PartitionKeyFilter(org.apache.cassandra.spark.sparksql.filters.PartitionKeyFilter) Test(org.junit.Test)

Example 4 with CassandraRing

use of org.apache.cassandra.spark.data.partitioner.CassandraRing in project spark-cassandra-bulkreader by jberragan.

the class PartitionedDataLayerTests method testSSTableSupplierWithNonMatchingFilters.

@Test(expected = NotEnoughReplicasException.class)
public void testSSTableSupplierWithNonMatchingFilters() {
    final CassandraRing ring = TestUtils.createRing(Partitioner.Murmur3Partitioner, 3);
    final CqlSchema schema = TestSchema.basic(bridge).buildSchema();
    final JDKSerializationTests.TestPartitionedDataLayer dataLayer = new JDKSerializationTests.TestPartitionedDataLayer(4, 32, null, ring, schema);
    final PartitionKeyFilter filter = PartitionKeyFilter.create(ByteBuffer.wrap(RandomUtils.nextBytes(10)), BigInteger.valueOf(6917529027641081853L));
    final SSTablesSupplier supplier = dataLayer.sstables(Collections.singletonList(filter));
}
Also used : CassandraRing(org.apache.cassandra.spark.data.partitioner.CassandraRing) JDKSerializationTests(org.apache.cassandra.spark.data.partitioner.JDKSerializationTests) PartitionKeyFilter(org.apache.cassandra.spark.sparksql.filters.PartitionKeyFilter) Test(org.junit.Test)

Example 5 with CassandraRing

use of org.apache.cassandra.spark.data.partitioner.CassandraRing in project spark-cassandra-bulkreader by jberragan.

the class PartitionedDataLayerTests method runSplitTests.

@SuppressWarnings("UnstableApiUsage")
private static void runSplitTests(final int minReplicas, final PartitionedDataLayer.AvailabilityHint... availabilityHint) {
    final int numInstances = availabilityHint.length;
    TestUtils.runTest((partitioner, dir, bridge) -> {
        final CassandraRing ring = TestUtils.createRing(partitioner, numInstances);
        final List<CassandraInstance> instances = new ArrayList<>(ring.instances());
        instances.sort(Comparator.comparing(CassandraInstance::nodeName));
        final TokenPartitioner tokenPartitioner = new TokenPartitioner(ring, 1, 32);
        final Map<CassandraInstance, PartitionedDataLayer.AvailabilityHint> availableMap = new HashMap<>(numInstances);
        for (int i = 0; i < numInstances; i++) {
            availableMap.put(instances.get(i), availabilityHint[i]);
        }
        final Map<Range<BigInteger>, List<CassandraInstance>> ranges = ring.getSubRanges(tokenPartitioner.getTokenRange(0)).asMapOfRanges();
        final PartitionedDataLayer.ReplicaSet replicaSet = PartitionedDataLayer.splitReplicas(instances, ranges, availableMap::get, minReplicas, 0);
        assertEquals(minReplicas, replicaSet.primary().size());
        assertEquals(numInstances - minReplicas, replicaSet.backup().size());
        final List<CassandraInstance> sortedInstances = new ArrayList<>(instances);
        sortedInstances.sort(Comparator.comparing(availableMap::get));
        for (int i = 0; i < sortedInstances.size(); i++) {
            if (i < minReplicas) {
                assertTrue(replicaSet.primary().contains(sortedInstances.get(i)));
            } else {
                assertTrue(replicaSet.backup().contains(sortedInstances.get(i)));
            }
        }
    });
}
Also used : CassandraRing(org.apache.cassandra.spark.data.partitioner.CassandraRing) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Range(com.google.common.collect.Range) CassandraInstance(org.apache.cassandra.spark.data.partitioner.CassandraInstance) List(java.util.List) ArrayList(java.util.ArrayList) TokenPartitioner(org.apache.cassandra.spark.data.partitioner.TokenPartitioner)

Aggregations

CassandraRing (org.apache.cassandra.spark.data.partitioner.CassandraRing)11 Test (org.junit.Test)7 TokenPartitioner (org.apache.cassandra.spark.data.partitioner.TokenPartitioner)6 BigInteger (java.math.BigInteger)5 Range (com.google.common.collect.Range)4 List (java.util.List)4 CassandraInstance (org.apache.cassandra.spark.data.partitioner.CassandraInstance)4 JDKSerializationTests (org.apache.cassandra.spark.data.partitioner.JDKSerializationTests)4 PartitionKeyFilter (org.apache.cassandra.spark.sparksql.filters.PartitionKeyFilter)4 ByteBuffer (java.nio.ByteBuffer)3 ArrayList (java.util.ArrayList)3 Comparator (java.util.Comparator)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Set (java.util.Set)3 MultipleReplicasTests (org.apache.cassandra.spark.data.partitioner.MultipleReplicasTests)3 Partitioner (org.apache.cassandra.spark.data.partitioner.Partitioner)3 Output (com.esotericsoftware.kryo.io.Output)2 Preconditions (com.google.common.base.Preconditions)2 ImmutableMap (com.google.common.collect.ImmutableMap)2