Package org.apache.jackrabbit.oak.plugins.document.Revision

Examples of org.apache.jackrabbit.oak.plugins.document.Revision.RevisionComparator


    }

    @Test
    public void clusterCompare() {
        RevisionComparator comp = new RevisionComparator(1);

        // sequence of revisions as added to comparator later
        Revision r1c1 = new Revision(0x10, 0, 1);
        Revision r1c2 = new Revision(0x20, 0, 2);
        Revision r2c1 = new Revision(0x30, 0, 1);
        Revision r2c2 = new Revision(0x40, 0, 2);
       
        comp.add(r1c1, new Revision(0x10, 0, 0));
        comp.add(r2c1, new Revision(0x20, 0, 0));

        // there's no range for c2, and therefore this
        // revision must be considered to be in the future
        assertTrue(comp.compare(r1c2, r2c1) > 0);
       
        // add a range for r2r2
        comp.add(r2c2, new Revision(0x30, 0, 0));

        // now there is a range for c2, but the revision is old,
        // so it must be considered to be in the past
        assertTrue(comp.compare(r1c2, r2c1) < 0);
    }
View Full Code Here


        assertTrue(comp.compare(r1c2, r2c1) < 0);
    }

    @Test
    public void revisionSeen() {
        RevisionComparator comp = new RevisionComparator(1);

        Revision r0 = new Revision(0x01, 0, 1);
        Revision r1 = new Revision(0x10, 0, 1);
        Revision r2 = new Revision(0x20, 0, 1);
        Revision r21 = new Revision(0x21, 0, 1);
        Revision r3 = new Revision(0x30, 0, 1);
        Revision r4 = new Revision(0x40, 0, 1);
        Revision r5 = new Revision(0x50, 0, 1);

        comp.add(r1, new Revision(0x10, 0, 0));
        comp.add(r2, new Revision(0x20, 0, 0));
        comp.add(r3, new Revision(0x30, 0, 0));
        comp.add(r4, new Revision(0x40, 0, 0));

        // older than first range -> must return null
        assertNull(comp.getRevisionSeen(r0));

        // exact range start matches
        assertEquals(new Revision(0x10, 0, 0), comp.getRevisionSeen(r1));
        assertEquals(new Revision(0x20, 0, 0), comp.getRevisionSeen(r2));
        assertEquals(new Revision(0x30, 0, 0), comp.getRevisionSeen(r3));
        assertEquals(new Revision(0x40, 0, 0), comp.getRevisionSeen(r4));

        // revision newer than most recent range -> NEWEST
        assertEquals(RevisionComparator.NEWEST, comp.getRevisionSeen(r5));

        // within a range -> must return lower bound of next higher range
        assertEquals(new Revision(0x30, 0, 0), comp.getRevisionSeen(r21));
    }
View Full Code Here

        }
    }
   
    @Test
    public void revisionComparatorSimple() {
        RevisionComparator comp = new RevisionComparator(0);
        Revision r1 = Revision.newRevision(0);
        Revision r2 = Revision.newRevision(0);
        assertEquals(r1.compareRevisionTime(r2), comp.compare(r1, r2));
        assertEquals(r2.compareRevisionTime(r1), comp.compare(r2, r1));
        assertEquals(r1.compareRevisionTime(r1), comp.compare(r1, r1));
    }
View Full Code Here

    }

    @Test
    public void revisionComparatorCluster() {

        RevisionComparator comp = new RevisionComparator(0);

        Revision r0c1 = new Revision(0x010, 0, 1);
        Revision r0c2 = new Revision(0x010, 0, 2);
       
        Revision r1c1 = new Revision(0x110, 0, 1);
        Revision r2c1 = new Revision(0x120, 0, 1);
        Revision r3c1 = new Revision(0x130, 0, 1);
        Revision r1c2 = new Revision(0x100, 0, 2);
        Revision r2c2 = new Revision(0x200, 0, 2);
        Revision r3c2 = new Revision(0x300, 0, 2);

        // first, only timestamps are compared
        assertEquals(1, comp.compare(r1c1, r1c2));
        assertEquals(-1, comp.compare(r2c1, r2c2));
        assertEquals(-1, comp.compare(r3c1, r3c2));

        // now we declare r2+r3 of c1 to be after r2+r3 of c2
        comp.add(r2c1, new Revision(0x20, 0, 0));
        comp.add(r2c2, new Revision(0x10, 0, 0));

        assertEquals(
                "1:\n r120-0-1:r20-0-0\n" +
                "2:\n r200-0-2:r10-0-0\n", comp.toString());

        assertEquals(-1, comp.compare(r0c1, r0c2));

        assertEquals(1, comp.compare(r1c1, r1c2));
        assertEquals(1, comp.compare(r2c1, r2c2));
        // both r3cx are still "in the future"
        assertEquals(-1, comp.compare(r3c1, r3c2));

        // now we declare r3 of c1 to be before r3 of c2
        // (with the same range timestamp,
        // the revision timestamps are compared)
        comp.add(r3c1, new Revision(0x30, 0, 0));
        comp.add(r3c2, new Revision(0x30, 0, 0));

        assertEquals(
                "1:\n r120-0-1:r20-0-0 r130-0-1:r30-0-0\n" +
                "2:\n r200-0-2:r10-0-0 r300-0-2:r30-0-0\n", comp.toString());

        assertEquals(1, comp.compare(r1c1, r1c2));
        assertEquals(1, comp.compare(r2c1, r2c2));
        assertEquals(-1, comp.compare(r3c1, r3c2));
        // reverse
        assertEquals(-1, comp.compare(r1c2, r1c1));
        assertEquals(-1, comp.compare(r2c2, r2c1));
        assertEquals(1, comp.compare(r3c2, r3c1));

        // get rid of old timestamps
        comp.purge(0x10);
        assertEquals(
                "1:\n r120-0-1:r20-0-0 r130-0-1:r30-0-0\n" +
                "2:\n r300-0-2:r30-0-0\n", comp.toString());
        comp.purge(0x20);
        assertEquals(
                "1:\n r130-0-1:r30-0-0\n" +
                "2:\n r300-0-2:r30-0-0\n", comp.toString());

        // update an entry
        comp.add(new Revision(0x301, 1, 2), new Revision(0x30, 0, 0));
        assertEquals(
                "1:\n r130-0-1:r30-0-0\n" +
                "2:\n r301-1-2:r30-0-0\n", comp.toString());

        comp.purge(0x30);
        assertEquals("", comp.toString());

    }
View Full Code Here

        }
    }

    @Test
    public void revisionComparatorSimple() {
        RevisionComparator comp = new RevisionComparator(0);
        Revision r1 = Revision.newRevision(0);
        Revision r2 = Revision.newRevision(0);
        assertEquals(r1.compareRevisionTime(r2), comp.compare(r1, r2));
        assertEquals(r2.compareRevisionTime(r1), comp.compare(r2, r1));
        assertEquals(r1.compareRevisionTime(r1), comp.compare(r1, r1));
    }
View Full Code Here

    }

    @Test
    public void revisionComparatorCluster() {

        RevisionComparator comp = new RevisionComparator(0);

        Revision r0c1 = new Revision(0x010, 0, 1);
        Revision r0c2 = new Revision(0x010, 0, 2);

        Revision r1c1 = new Revision(0x110, 0, 1);
        Revision r2c1 = new Revision(0x120, 0, 1);
        Revision r3c1 = new Revision(0x130, 0, 1);
        Revision r1c2 = new Revision(0x100, 0, 2);
        Revision r2c2 = new Revision(0x200, 0, 2);
        Revision r3c2 = new Revision(0x300, 0, 2);

        // first, only timestamps are compared
        assertEquals(1, comp.compare(r1c1, r1c2));
        assertEquals(-1, comp.compare(r2c1, r2c2));
        assertEquals(-1, comp.compare(r3c1, r3c2));

        // now we declare r2+r3 of c1 to be after r2+r3 of c2
        comp.add(r2c1, new Revision(0x20, 0, 0));
        comp.add(r2c2, new Revision(0x10, 0, 0));

        assertEquals(
                "1:\n r120-0-1:r20-0-0\n" +
                "2:\n r200-0-2:r10-0-0\n", comp.toString());

        // r0c2 happens before r0c1 because r2c2 is declared before r2c1
        assertEquals(1, comp.compare(r0c1, r0c2));

        assertEquals(1, comp.compare(r1c1, r1c2));
        assertEquals(1, comp.compare(r2c1, r2c2));
        // both r3cx are still "in the future"
        assertEquals(-1, comp.compare(r3c1, r3c2));

        // now we declare r3 of c1 to be before r3 of c2
        // (with the same range timestamp,
        // the revision timestamps are compared)
        comp.add(r3c1, new Revision(0x30, 0, 0));
        comp.add(r3c2, new Revision(0x30, 0, 0));

        assertEquals(
                "1:\n r120-0-1:r20-0-0 r130-0-1:r30-0-0\n" +
                "2:\n r200-0-2:r10-0-0 r300-0-2:r30-0-0\n", comp.toString());

        assertEquals(1, comp.compare(r1c1, r1c2));
        assertEquals(1, comp.compare(r2c1, r2c2));
        assertEquals(-1, comp.compare(r3c1, r3c2));
        // reverse
        assertEquals(-1, comp.compare(r1c2, r1c1));
        assertEquals(-1, comp.compare(r2c2, r2c1));
        assertEquals(1, comp.compare(r3c2, r3c1));

        // get rid of old timestamps
        comp.purge(0x10);
        assertEquals(
                "1:\n r120-0-1:r20-0-0 r130-0-1:r30-0-0\n" +
                "2:\n r300-0-2:r30-0-0\n", comp.toString());
        comp.purge(0x20);
        assertEquals(
                "1:\n r130-0-1:r30-0-0\n" +
                "2:\n r300-0-2:r30-0-0\n", comp.toString());

        // update an entry
        comp.add(new Revision(0x301, 1, 2), new Revision(0x30, 0, 0));
        assertEquals(
                "1:\n r130-0-1:r30-0-0\n" +
                "2:\n r301-1-2:r30-0-0\n", comp.toString());

        comp.purge(0x30);
        assertEquals("", comp.toString());

    }
View Full Code Here

    }

    @Test
    public void clusterCompare() {
        RevisionComparator comp = new RevisionComparator(1);

        // sequence of revisions as added to comparator later
        Revision r1c1 = new Revision(0x10, 0, 1);
        Revision r1c2 = new Revision(0x20, 0, 2);
        Revision r2c1 = new Revision(0x30, 0, 1);
        Revision r2c2 = new Revision(0x40, 0, 2);

        comp.add(r1c1, new Revision(0x10, 0, 0));
        comp.add(r2c1, new Revision(0x30, 0, 0));

        // there's no range for c2, and therefore this
        // revision must be considered to be in the future
        assertTrue(comp.compare(r1c2, r2c1) > 0);

        // add a range for r2r2
        comp.add(r2c2, new Revision(0x40, 0, 0));
        comp.purge(0x20);

        // now there is a range for c2, but the revision is old (before purge
        // time, so it must be considered to be in the past
        assertTrue(comp.compare(r1c2, r2c1) < 0);
    }
View Full Code Here

    }

    // OAK-1727
    @Test
    public void clusterCompare2() {
        RevisionComparator comp = new RevisionComparator(1);

        comp.add(Revision.fromString("r3-0-1"), Revision.fromString("r1-1-0"));

        Revision r1 = Revision.fromString("r1-0-2");
        Revision r2 = Revision.fromString("r4-0-2");

        // cluster sync
        Revision c1sync = Revision.fromString("r5-0-1");
        comp.add(c1sync,  Revision.fromString("r2-0-0"));
        Revision c2sync = Revision.fromString("r4-1-2");
        comp.add(c2sync,  Revision.fromString("r2-1-0"));
        Revision c3sync = Revision.fromString("r2-0-3");
        comp.add(c3sync, Revision.fromString("r2-1-0"));

        assertTrue(comp.compare(r1, r2) < 0);
        assertTrue(comp.compare(r2, c2sync) < 0);
        // same seen-at revision, but clusterId 2 < 3
        assertTrue(comp.compare(c2sync, c3sync) < 0);

        // this means, c3sync must be after r1 and r2
        // because: r1 < r2 < c2sync < c3sync
        assertTrue(comp.compare(r1, c3sync) < 0);
        assertTrue(comp.compare(r2, c3sync) < 0);
    }
View Full Code Here

        assertTrue(comp.compare(r2, c3sync) < 0);
    }

    @Test
    public void revisionSeen() {
        RevisionComparator comp = new RevisionComparator(1);
        comp.purge(0);

        Revision r0 = new Revision(0x01, 0, 1);
        Revision r1 = new Revision(0x10, 0, 1);
        Revision r2 = new Revision(0x20, 0, 1);
        Revision r21 = new Revision(0x21, 0, 1);
        Revision r3 = new Revision(0x30, 0, 1);
        Revision r4 = new Revision(0x40, 0, 1);
        Revision r5 = new Revision(0x50, 0, 1);

        comp.add(r1, new Revision(0x10, 0, 0));
        comp.add(r2, new Revision(0x20, 0, 0));
        comp.add(r3, new Revision(0x30, 0, 0));
        comp.add(r4, new Revision(0x40, 0, 0));

        // older than first range, but after purge timestamp
        // -> must return seen-at of first range
        assertEquals(new Revision(0x10, 0, 0), comp.getRevisionSeen(r0));

        // exact range start matches
        assertEquals(new Revision(0x10, 0, 0), comp.getRevisionSeen(r1));
        assertEquals(new Revision(0x20, 0, 0), comp.getRevisionSeen(r2));
        assertEquals(new Revision(0x30, 0, 0), comp.getRevisionSeen(r3));
        assertEquals(new Revision(0x40, 0, 0), comp.getRevisionSeen(r4));

        // revision newer than most recent range -> NEWEST
        assertEquals(RevisionComparator.NEWEST, comp.getRevisionSeen(r5));

        // within a range -> must return lower bound of next higher range
        assertEquals(new Revision(0x30, 0, 0), comp.getRevisionSeen(r21));
    }
View Full Code Here

    }

    // OAK-1814
    @Test
    public void seenAtAfterPurge() throws Exception {
        RevisionComparator comp = new RevisionComparator(1);

        // some revisions from another cluster node
        Revision r1 = new Revision(0x01, 0, 2);
        Revision r2 = new Revision(0x02, 0, 2);

        // make them visible
        comp.add(r1, new Revision(0x01, 0, 0));
        comp.add(r2, new Revision(0x02, 0, 0));

        comp.purge(0x01);

        // null indicates older than earliest range
        assertNull(comp.getRevisionSeen(r1));
        // r2 is still seen at 0x02
        assertEquals(new Revision(0x02, 0, 0), comp.getRevisionSeen(r2));

        comp.purge(0x02);

        // now also r2 is considered old
        assertNull(comp.getRevisionSeen(r2));
    }
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.oak.plugins.document.Revision.RevisionComparator

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.