Package org.apache.cassandra.utils

Examples of org.apache.cassandra.utils.MerkleTree$MerkleTreeSerializer


        // generate a tree
        Validator validator = new Validator(request);
        validator.prepare(store);
        validator.completeTree();
        MerkleTree ltree = validator.tree;

        // and a clone
        validator = new Validator(request);
        validator.prepare(store);
        validator.completeTree();
        MerkleTree rtree = validator.tree;

        // change a range in one of the trees
        Token ltoken = StorageService.getPartitioner().midpoint(local_range.left, local_range.right);
        ltree.invalidate(ltoken);
        MerkleTree.TreeRange changed = ltree.get(ltoken);
View Full Code Here


   
    private void testTreeResponseWrite() throws IOException
    {
        AntiEntropyService.Validator v0 = new AntiEntropyService.Validator(Statics.req);
        IPartitioner part = new RandomPartitioner();
        MerkleTree mt = new MerkleTree(part, FULL_RANGE, MerkleTree.RECOMMENDED_DEPTH, Integer.MAX_VALUE);
        List<Token> tokens = new ArrayList<Token>();
        for (int i = 0; i < 10; i++)
        {
            Token t = part.getRandomToken();
            tokens.add(t);
            mt.split(t);
        }
        AntiEntropyService.Validator v1 = new AntiEntropyService.Validator(Statics.req, mt);
        DataOutputStream out = getOutput("service.TreeResponse.bin");
        AntiEntropyService.TreeResponseVerbHandler.SERIALIZER.serialize(v0, out, getVersion());
        AntiEntropyService.TreeResponseVerbHandler.SERIALIZER.serialize(v1, out, getVersion());
View Full Code Here

    @Before
    public void clear()
    {
        TOKEN_SCALE = new BigInteger("8");
        partitioner = new RandomPartitioner();
        mt = new MerkleTree(partitioner, RECOMMENDED_DEPTH, Integer.MAX_VALUE);
    }
View Full Code Here

    }

    @Test
    public void testSplitLimitDepth()
    {
        mt = new MerkleTree(partitioner, (byte)2, Integer.MAX_VALUE);

        assertTrue(mt.split(tok(4)));
        assertTrue(mt.split(tok(2)));
        assertEquals(3, mt.size());
       
View Full Code Here

    }

    @Test
    public void testSplitLimitSize()
    {
        mt = new MerkleTree(partitioner, RECOMMENDED_DEPTH, 2);

        assertTrue(mt.split(tok(4)));
        assertEquals(2, mt.size());
       
        // should fail to split above maxsize
View Full Code Here

        byte[] fullval = hashed(val, 5, 5, 4, 3, 2, 1);
        Range childfull = new Range(tok(0), tok(4));
        Range full = new Range(tok(0), tok(0));
        Range invalid = new Range(tok(4), tok(0));

        mt = new MerkleTree(partitioner, RECOMMENDED_DEPTH, Integer.MAX_VALUE);
        mt.split(tok(16));
        mt.split(tok(8));
        mt.split(tok(4));
        mt.split(tok(2));
        mt.split(tok(1));
View Full Code Here

    public void testHashRandom()
    {
        int max = 1000000;
        TOKEN_SCALE = new BigInteger("" + max);

        mt = new MerkleTree(partitioner, RECOMMENDED_DEPTH, 32);
        Random random = new Random();
        while (true)
        {
            if (!mt.split(tok(random.nextInt(max))))
                break;
View Full Code Here

    {
        TOKEN_SCALE = new BigInteger("16"); // this test needs slightly more resolution

        Range full = new Range(tok(0), tok(0));
        Iterator<TreeRange> ranges;
        MerkleTree mt2 = new MerkleTree(partitioner, RECOMMENDED_DEPTH, Integer.MAX_VALUE);

        mt.split(tok(8));
        mt.split(tok(4));
        mt.split(tok(12));
        mt.split(tok(6));
        mt.split(tok(10));
       
        ranges = mt.invalids(full);
        ranges.next().addAll(new HIterator(2, 4)); // (0,4]: depth 2
        ranges.next().addAll(new HIterator(6)); // (4,6]
        ranges.next().addAll(new HIterator(8)); // (6,8]
        ranges.next().addAll(new HIterator(/*empty*/ new int[0])); // (8,10]
        ranges.next().addAll(new HIterator(12)); // (10,12]
        ranges.next().addAll(new HIterator(14, 0)); // (12,0]: depth 2


        mt2.split(tok(8));
        mt2.split(tok(4));
        mt2.split(tok(12));
        mt2.split(tok(2));
        mt2.split(tok(10));
        mt2.split(tok(9));
        mt2.split(tok(11));

        ranges = mt2.invalids(full);
        ranges.next().addAll(new HIterator(2)); // (0,2]
        ranges.next().addAll(new HIterator(4)); // (2,4]
        ranges.next().addAll(new HIterator(6, 8)); // (4,8]: depth 2
        ranges.next().addAll(new HIterator(/*empty*/ new int[0])); // (8,9]
        ranges.next().addAll(new HIterator(/*empty*/ new int[0])); // (9,10]
        ranges.next().addAll(new HIterator(/*empty*/ new int[0])); // (10,11]: depth 4
        ranges.next().addAll(new HIterator(12)); // (11,12]: depth 4
        ranges.next().addAll(new HIterator(14, 0)); // (12,0]: depth 2

        byte[] mthash = mt.hash(full);
        byte[] mt2hash = mt2.hash(full);
        assertHashEquals("Tree hashes did not match: " + mt + " && " + mt2, mthash, mt2hash);
    }
View Full Code Here

        oout.writeObject(mt);
        oout.close();

        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
        ObjectInputStream oin = new ObjectInputStream(bin);
        MerkleTree restored = (MerkleTree)oin.readObject();
   
        // restore partitioner after serialization
        restored.partitioner(partitioner);

        assertHashEquals(initialhash, restored.hash(full));
    }
View Full Code Here

    public void testDifference()
    {
        Range full = new Range(tok(0), tok(0));
        int maxsize = 16;
        mt.maxsize(maxsize);
        MerkleTree mt2 = new MerkleTree(partitioner, RECOMMENDED_DEPTH, maxsize);
        mt.init();
        mt2.init();

        TreeRange leftmost = null;
        TreeRange middle = null;
        TreeRange rightmost = null;

        // compact the leftmost, and split the rightmost
        Iterator<TreeRange> ranges = mt.invalids(full);
        leftmost = ranges.next();
        rightmost = null;
        while (ranges.hasNext())
            rightmost = ranges.next();
        mt.compact(leftmost.right);
        leftmost = mt.get(leftmost.right); // leftmost is now a larger range
        mt.split(rightmost.right);
       
        // set the hash for the left neighbor of rightmost
        middle = mt.get(rightmost.left);
        middle.hash("arbitrary!".getBytes());
        byte depth = middle.depth;

        // add dummy hashes to the rest of both trees
        for (TreeRange range : mt.invalids(full))
            range.addAll(new HIterator(range.right));
        for (TreeRange range : mt2.invalids(full))
            range.addAll(new HIterator(range.right));
       
        // trees should disagree for leftmost, (middle.left, rightmost.right]
        List<TreeRange> diffs = MerkleTree.difference(mt, mt2);
        assertEquals(diffs + " contains wrong number of differences:", 2, diffs.size());
View Full Code Here

TOP

Related Classes of org.apache.cassandra.utils.MerkleTree$MerkleTreeSerializer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.