use of org.apache.cassandra.repair.messages.ValidationComplete in project cassandra by apache.
the class ValidatorTest method simpleValidationTest.
/**
* Test for CASSANDRA-5263
* 1. Create N rows
* 2. Run validation compaction
* 3. Expect merkle tree with size 2^(log2(n))
*/
public void simpleValidationTest(int n) throws Exception {
Keyspace ks = Keyspace.open(keyspace);
ColumnFamilyStore cfs = ks.getColumnFamilyStore(columnFamily);
cfs.clearUnsafe();
// disable compaction while flushing
cfs.disableAutoCompaction();
//ttl=3s
CompactionsTest.populate(keyspace, columnFamily, 0, n, 0);
cfs.forceBlockingFlush();
assertEquals(1, cfs.getLiveSSTables().size());
// wait enough to force single compaction
TimeUnit.SECONDS.sleep(5);
SSTableReader sstable = cfs.getLiveSSTables().iterator().next();
UUID repairSessionId = UUIDGen.getTimeUUID();
final RepairJobDesc desc = new RepairJobDesc(repairSessionId, UUIDGen.getTimeUUID(), cfs.keyspace.getName(), cfs.getTableName(), Collections.singletonList(new Range<>(sstable.first.getToken(), sstable.last.getToken())));
ActiveRepairService.instance.registerParentRepairSession(repairSessionId, FBUtilities.getBroadcastAddress(), Collections.singletonList(cfs), desc.ranges, false, ActiveRepairService.UNREPAIRED_SSTABLE, false);
final CompletableFuture<MessageOut> outgoingMessageSink = registerOutgoingMessageSink();
Validator validator = new Validator(desc, FBUtilities.getBroadcastAddress(), 0, true, false);
CompactionManager.instance.submitValidation(cfs, validator);
MessageOut message = outgoingMessageSink.get(TEST_TIMEOUT, TimeUnit.SECONDS);
assertEquals(MessagingService.Verb.REPAIR_MESSAGE, message.verb);
RepairMessage m = (RepairMessage) message.payload;
assertEquals(RepairMessage.Type.VALIDATION_COMPLETE, m.messageType);
assertEquals(desc, m.desc);
assertTrue(((ValidationComplete) m).success());
MerkleTrees trees = ((ValidationComplete) m).trees;
Iterator<Map.Entry<Range<Token>, MerkleTree>> iterator = trees.iterator();
while (iterator.hasNext()) {
assertEquals(Math.pow(2, Math.ceil(Math.log(n) / Math.log(2))), iterator.next().getValue().size(), 0.0);
}
assertEquals(trees.rowCount(), n);
}
Aggregations