Package org.apache.cassandra.dht

Examples of org.apache.cassandra.dht.Range


        assertEquals(3, mt.size());
       
        // should fail to split below hashdepth
        assertFalse(mt.split(tok(1)));
        assertEquals(3, mt.size());
        assertEquals(new Range(tok(4), tok(-1)), mt.get(tok(-1)));
        assertEquals(new Range(tok(-1), tok(2)), mt.get(tok(2)));
        assertEquals(new Range(tok(2), tok(4)), mt.get(tok(4)));
    }
View Full Code Here


        assertEquals(2, mt.size());
       
        // should fail to split above maxsize
        assertFalse(mt.split(tok(2)));
        assertEquals(2, mt.size());
        assertEquals(new Range(tok(4), tok(-1)), mt.get(tok(-1)));
        assertEquals(new Range(tok(-1), tok(4)), mt.get(tok(4)));
    }
View Full Code Here

        // compact (zero,two] and then (four,six]
        mt.compact(tok(1));
        mt.compact(tok(5));
        assertEquals(6, mt.size());
        assertEquals(new Range(tok(-1), tok(2)), mt.get(tok(2)));
        assertEquals(new Range(tok(2), tok(3)), mt.get(tok(3)));
        assertEquals(new Range(tok(3), tok(4)), mt.get(tok(4)));
        assertEquals(new Range(tok(4), tok(6)), mt.get(tok(5)));
        assertEquals(new Range(tok(6), tok(7)), mt.get(tok(7)));
        assertEquals(new Range(tok(7), tok(-1)), mt.get(tok(-1)));
        // compacted ranges should be at depth 2, and the rest at 3
        for (int i : new int[]{2,6}){ assertEquals((byte)2, mt.get(tok(i)).depth); }
        for (int i : new int[]{3,4,7,-1}){ assertEquals((byte)3, mt.get(tok(i)).depth); }

        // compact (two,four] and then (six,zero]
        mt.compact(tok(3));
        mt.compact(tok(7));
        assertEquals(4, mt.size());
        assertEquals(new Range(tok(-1), tok(2)), mt.get(tok(2)));
        assertEquals(new Range(tok(2), tok(4)), mt.get(tok(4)));
        assertEquals(new Range(tok(4), tok(6)), mt.get(tok(5)));
        assertEquals(new Range(tok(6), tok(-1)), mt.get(tok(-1)));
        for (int i : new int[]{2,4,5,-1}){ assertEquals((byte)2, mt.get(tok(i)).depth); }

        // compact (zero,four]
        mt.compact(tok(2));
        assertEquals(3, mt.size());
        assertEquals(new Range(tok(-1), tok(4)), mt.get(tok(2)));
        assertEquals(new Range(tok(4), tok(6)), mt.get(tok(6)));
        assertEquals(new Range(tok(6), tok(-1)), mt.get(tok(-1)));

        // compact (four, zero]
        mt.compact(tok(6));
        assertEquals(2, mt.size());
        assertEquals(new Range(tok(-1), tok(4)), mt.get(tok(2)));
        assertEquals(new Range(tok(4), tok(-1)), mt.get(tok(6)));
        assertEquals((byte)1, mt.get(tok(2)).depth);
        assertEquals((byte)1, mt.get(tok(6)).depth);

        // compact (zero, zero] (the root)
        mt.compact(tok(4));
        assertEquals(1, mt.size());
        assertEquals(new Range(tok(-1), tok(-1)), mt.get(tok(-1)));
        assertEquals((byte)0, mt.get(tok(-1)).depth);
    }
View Full Code Here

    public void testInvalids()
    {
        Iterator<TreeRange> ranges;
       
        // (zero, zero]
        ranges = mt.invalids(new Range(tok(-1), tok(-1)));
        assertEquals(new Range(tok(-1), tok(-1)), ranges.next());
        assertFalse(ranges.hasNext());

        // all invalid
        mt.split(tok(4));
        mt.split(tok(2));
        mt.split(tok(6));
        mt.split(tok(3));
        mt.split(tok(5));
        ranges = mt.invalids(new Range(tok(-1), tok(-1)));
        assertEquals(new Range(tok(-1), tok(2)), ranges.next());
        assertEquals(new Range(tok(2), tok(3)), ranges.next());
        assertEquals(new Range(tok(3), tok(4)), ranges.next());
        assertEquals(new Range(tok(4), tok(5)), ranges.next());
        assertEquals(new Range(tok(5), tok(6)), ranges.next());
        assertEquals(new Range(tok(6), tok(-1)), ranges.next());
        assertFalse(ranges.hasNext());
       
        // some invalid
        mt.get(tok(2)).hash("non-null!".getBytes());
        mt.get(tok(4)).hash("non-null!".getBytes());
        mt.get(tok(5)).hash("non-null!".getBytes());
        mt.get(tok(-1)).hash("non-null!".getBytes());
        ranges = mt.invalids(new Range(tok(-1), tok(-1)));
        assertEquals(new Range(tok(2), tok(3)), ranges.next());
        assertEquals(new Range(tok(5), tok(6)), ranges.next());
        assertFalse(ranges.hasNext());
       
        // some invalid in left subrange
        ranges = mt.invalids(new Range(tok(-1), tok(6)));
        assertEquals(new Range(tok(2), tok(3)), ranges.next());
        assertEquals(new Range(tok(5), tok(6)), ranges.next());
        assertFalse(ranges.hasNext());

        // some invalid in right subrange
        ranges = mt.invalids(new Range(tok(2), tok(-1)));
        assertEquals(new Range(tok(2), tok(3)), ranges.next());
        assertEquals(new Range(tok(5), tok(6)), ranges.next());
        assertFalse(ranges.hasNext());
    }
View Full Code Here

    @Test
    public void testHashFull()
    {
        byte[] val = DUMMY;
        Range range = new Range(tok(-1), tok(-1));

        // (zero, zero]
        assertNull(mt.hash(range));
       
        // validate the range
View Full Code Here

    public void testHashPartial()
    {
        byte[] val = DUMMY;
        byte[] leftval = hashed(val, 1, 1);
        byte[] partialval = hashed(val, 1);
        Range left = new Range(tok(-1), tok(4));
        Range partial = new Range(tok(2), tok(4));
        Range right = new Range(tok(4), tok(-1));
        Range linvalid = new Range(tok(1), tok(4));
        Range rinvalid = new Range(tok(4), tok(6));

        // (zero,two] (two,four] (four, zero]
        mt.split(tok(4));
        mt.split(tok(2));
        assertNull(mt.hash(left));
View Full Code Here

    {
        byte[] val = DUMMY;
        byte[] lchildval = hashed(val, 3, 3, 2);
        byte[] rchildval = hashed(val, 2, 2);
        byte[] fullval = hashed(val, 3, 3, 2, 2, 2);
        Range full = new Range(tok(-1), tok(-1));
        Range lchild = new Range(tok(-1), tok(4));
        Range rchild = new Range(tok(4), tok(-1));
        Range invalid = new Range(tok(1), tok(-1));

        // (zero,one] (one, two] (two,four] (four, six] (six, zero]
        mt.split(tok(4));
        mt.split(tok(2));
        mt.split(tok(6));
View Full Code Here

        TOKEN_SCALE = new BigInteger("32");

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

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

            if (!mt.split(tok(random.nextInt(max))))
                break;
        }

        // validate the tree
        TreeRangeIterator ranges = mt.invalids(new Range(tok(-1), tok(-1)));
        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;
    }
View Full Code Here

    @Test
    public void testValidateTree()
    {
        TOKEN_SCALE = new BigInteger("16"); // this test needs slightly more resolution

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

        mt.split(tok(8));
        mt.split(tok(4));
View Full Code Here

TOP

Related Classes of org.apache.cassandra.dht.Range

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.