Search in sources :

Example 1 with TreeRangeIterator

use of org.apache.cassandra.utils.MerkleTree.TreeRangeIterator in project cassandra by apache.

the class MerkleTreeTest method testHashRandom.

@Test
public void testHashRandom() {
    int max = 1000000;
    TOKEN_SCALE = new BigInteger("" + max);
    mt = new MerkleTree(partitioner, fullRange(), RECOMMENDED_DEPTH, 32);
    Random random = new Random();
    while (true) {
        if (!mt.split(tok(random.nextInt(max))))
            break;
    }
    // validate the tree
    TreeRangeIterator ranges = mt.rangeIterator();
    for (TreeRange range : ranges) range.addHash(new RowHash(range.right, new byte[0], 0));
    assert mt.hash(new Range<>(tok(-1), tok(-1))) != null : "Could not hash tree " + mt;
}
Also used : RowHash(org.apache.cassandra.utils.MerkleTree.RowHash) TreeRange(org.apache.cassandra.utils.MerkleTree.TreeRange) BigInteger(java.math.BigInteger) Range(org.apache.cassandra.dht.Range) TreeRange(org.apache.cassandra.utils.MerkleTree.TreeRange) TreeRangeIterator(org.apache.cassandra.utils.MerkleTree.TreeRangeIterator) Test(org.junit.Test)

Example 2 with TreeRangeIterator

use of org.apache.cassandra.utils.MerkleTree.TreeRangeIterator in project eiger by wlloyd.

the class MerkleTreeTest method testHashRandom.

@Test
public void testHashRandom() {
    int max = 1000000;
    TOKEN_SCALE = new BigInteger("" + max);
    mt = new MerkleTree(partitioner, fullRange(), RECOMMENDED_DEPTH, 32);
    Random random = new Random();
    while (true) {
        if (!mt.split(tok(random.nextInt(max))))
            break;
    }
    // validate the tree
    TreeRangeIterator ranges = mt.invalids();
    for (TreeRange range : ranges) range.addHash(new RowHash(range.right, new byte[0]));
    assert null != mt.hash(new Range(tok(-1), tok(-1))) : "Could not hash tree " + mt;
}
Also used : RowHash(org.apache.cassandra.utils.MerkleTree.RowHash) Random(java.util.Random) TreeRange(org.apache.cassandra.utils.MerkleTree.TreeRange) BigInteger(java.math.BigInteger) Range(org.apache.cassandra.dht.Range) TreeRange(org.apache.cassandra.utils.MerkleTree.TreeRange) TreeRangeIterator(org.apache.cassandra.utils.MerkleTree.TreeRangeIterator) Test(org.junit.Test)

Aggregations

BigInteger (java.math.BigInteger)2 Range (org.apache.cassandra.dht.Range)2 RowHash (org.apache.cassandra.utils.MerkleTree.RowHash)2 TreeRange (org.apache.cassandra.utils.MerkleTree.TreeRange)2 TreeRangeIterator (org.apache.cassandra.utils.MerkleTree.TreeRangeIterator)2 Test (org.junit.Test)2 Random (java.util.Random)1