use of org.apache.cassandra.utils.MerkleTreesTest in project cassandra by apache.
the class DifferenceHolderTest method testFromMismatchedMerkleTrees.
@Test
public void testFromMismatchedMerkleTrees() throws UnknownHostException {
IPartitioner partitioner = Murmur3Partitioner.instance;
Range<Token> fullRange = new Range<>(partitioner.getMinimumToken(), partitioner.getMinimumToken());
int maxsize = 16;
InetAddressAndPort a1 = InetAddressAndPort.getByName("127.0.0.1");
InetAddressAndPort a2 = InetAddressAndPort.getByName("127.0.0.2");
// merkle tree building stolen from MerkleTreesTest:
MerkleTrees mts1 = new MerkleTrees(partitioner);
MerkleTrees mts2 = new MerkleTrees(partitioner);
mts1.addMerkleTree(32, fullRange);
mts2.addMerkleTree(32, fullRange);
mts1.init();
mts2.init();
// add dummy hashes to both trees
for (MerkleTree.TreeRange range : mts1.rangeIterator()) range.addAll(new MerkleTreesTest.HIterator(range.right));
for (MerkleTree.TreeRange range : mts2.rangeIterator()) range.addAll(new MerkleTreesTest.HIterator(range.right));
MerkleTree.TreeRange leftmost = null;
MerkleTree.TreeRange middle = null;
// give some room for splitting
mts1.maxsize(fullRange, maxsize + 2);
// split the leftmost
Iterator<MerkleTree.TreeRange> ranges = mts1.rangeIterator();
leftmost = ranges.next();
mts1.split(leftmost.right);
// set the hashes for the leaf of the created split
middle = mts1.get(leftmost.right);
middle.hash(digest("arbitrary!"));
mts1.get(partitioner.midpoint(leftmost.left, leftmost.right)).hash(digest("even more arbitrary!"));
TreeResponse tr1 = new TreeResponse(a1, mts1);
TreeResponse tr2 = new TreeResponse(a2, mts2);
DifferenceHolder dh = new DifferenceHolder(Lists.newArrayList(tr1, tr2));
assertTrue(dh.get(a1).get(a2).size() == 1);
assertTrue(dh.hasDifferenceBetween(a1, a2, fullRange));
// only a1 is added as a key - see comment in dh.keyHosts()
assertEquals(Sets.newHashSet(a1), dh.keyHosts());
}
Aggregations