use of org.apache.cassandra.db.BufferDecoratedKey in project cassandra by apache.
the class WriteCallbackInfoTest method testShouldHint.
private void testShouldHint(Verb verb, ConsistencyLevel cl, boolean allowHints, boolean expectHint) throws Exception {
Object payload = verb == Verb.PAXOS_COMMIT ? new Commit(UUID.randomUUID(), new PartitionUpdate(MockSchema.newTableMetadata("", ""), ByteBufferUtil.EMPTY_BYTE_BUFFER, RegularAndStaticColumns.NONE, 1)) : new Mutation("", new BufferDecoratedKey(new Murmur3Partitioner.LongToken(0), ByteBufferUtil.EMPTY_BYTE_BUFFER));
WriteCallbackInfo wcbi = new WriteCallbackInfo(InetAddress.getByName("192.168.1.1"), null, new MessageOut(verb, payload, null), null, cl, allowHints);
Assert.assertEquals(expectHint, wcbi.shouldHint());
if (expectHint) {
Assert.assertNotNull(wcbi.mutation());
} else {
boolean fail = false;
try {
wcbi.mutation();
} catch (Throwable t) {
fail = true;
}
Assert.assertTrue(fail);
}
}
use of org.apache.cassandra.db.BufferDecoratedKey in project cassandra by apache.
the class ValidatorTest method testValidatorComplete.
@Test
public void testValidatorComplete() throws Throwable {
Range<Token> range = new Range<>(partitioner.getMinimumToken(), partitioner.getRandomToken());
final RepairJobDesc desc = new RepairJobDesc(UUID.randomUUID(), UUID.randomUUID(), keyspace, columnFamily, Arrays.asList(range));
final CompletableFuture<MessageOut> outgoingMessageSink = registerOutgoingMessageSink();
InetAddress remote = InetAddress.getByName("127.0.0.2");
ColumnFamilyStore cfs = Keyspace.open(keyspace).getColumnFamilyStore(columnFamily);
Validator validator = new Validator(desc, remote, 0);
MerkleTrees tree = new MerkleTrees(partitioner);
tree.addMerkleTrees((int) Math.pow(2, 15), validator.desc.ranges);
validator.prepare(cfs, tree);
// and confirm that the tree was split
assertTrue(tree.size() > 1);
// add a row
Token mid = partitioner.midpoint(range.left, range.right);
validator.add(EmptyIterators.unfilteredRow(cfs.metadata(), new BufferDecoratedKey(mid, ByteBufferUtil.bytes("inconceivable!")), false));
validator.complete();
// confirm that the tree was validated
Token min = tree.partitioner().getMinimumToken();
assertNotNull(tree.hash(new Range<>(min, min)));
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());
assertNotNull(((ValidationComplete) m).trees);
}
use of org.apache.cassandra.db.BufferDecoratedKey in project cassandra by apache.
the class TokenTreeTest method dk.
private static DecoratedKey dk(Long token) {
ByteBuffer buf = ByteBuffer.allocate(8);
buf.putLong(token);
buf.flip();
Long hashed = MurmurHash.hash2_64(buf, buf.position(), buf.remaining(), 0);
return new BufferDecoratedKey(new Murmur3Partitioner.LongToken(hashed), buf);
}
Aggregations