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());
});
}
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());
});
}
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());
}
});
}
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));
}
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)));
}
}
});
}
Aggregations