Search in sources :

Example 6 with ConsistencyReport

use of org.apache.jackrabbit.core.persistence.check.ConsistencyReport in project jackrabbit by apache.

the class AutoFixCorruptNode method testOrphan.

public void testOrphan() throws Exception {
    // new repository
    TransientRepository rep = new TransientRepository(new File(TEST_DIR));
    Session s = openSession(rep, false);
    try {
        Node root = s.getRootNode();
        Node parent = root.addNode("parent");
        Node test = parent.addNode("test");
        test.addMixin("mix:referenceable");
        String lost = test.getIdentifier();
        Node lnf = root.addNode("lost+found");
        lnf.addMixin("mix:referenceable");
        String lnfid = lnf.getIdentifier();
        s.save();
        Node brokenNode = parent;
        UUID destroy = UUID.fromString(brokenNode.getIdentifier());
        s.logout();
        destroyBundle(destroy, "workspaces/default");
        s = openSession(rep, false);
        ConsistencyReport report = TestHelper.checkConsistency(s, false, null);
        assertTrue("Report should have reported broken nodes", !report.getItems().isEmpty());
        // now retry with lost+found functionality
        ConsistencyReport report2 = TestHelper.checkConsistency(s, true, lnfid);
        assertTrue("Report should have reported broken nodes", !report2.getItems().isEmpty());
        s.logout();
        s = openSession(rep, false);
        Node q = s.getNodeByIdentifier(lost);
        // check the node was moved
        assertEquals(lnfid, q.getParent().getIdentifier());
    } finally {
        s.logout();
    }
}
Also used : TransientRepository(org.apache.jackrabbit.core.TransientRepository) Node(javax.jcr.Node) UUID(java.util.UUID) File(java.io.File) ConsistencyReport(org.apache.jackrabbit.core.persistence.check.ConsistencyReport) Session(javax.jcr.Session)

Example 7 with ConsistencyReport

use of org.apache.jackrabbit.core.persistence.check.ConsistencyReport in project jackrabbit by apache.

the class AutoFixCorruptNode method testMissingRootVersion.

public void testMissingRootVersion() throws Exception {
    // new repository
    TransientRepository rep = new TransientRepository(new File(TEST_DIR));
    Session s = openSession(rep, false);
    String oldVersionRecoveryProp = System.getProperty("org.apache.jackrabbit.version.recovery");
    try {
        Node root = s.getRootNode();
        // add nodes /test and /test/missing
        Node test = root.addNode("test", "nt:file");
        test.addNode("jcr:content", "nt:unstructured");
        test.addMixin("mix:versionable");
        s.save();
        s.getWorkspace().getVersionManager().checkout(test.getPath());
        s.getWorkspace().getVersionManager().checkin(test.getPath());
        Node vhr = s.getWorkspace().getVersionManager().getVersionHistory(test.getPath());
        assertNotNull(vhr);
        Node brokenNode = vhr.getNode("jcr:rootVersion");
        String vhrId = vhr.getIdentifier();
        UUID destroy = UUID.fromString(brokenNode.getIdentifier());
        s.logout();
        destroyBundle(destroy, "version");
        s = openSession(rep, false);
        ConsistencyReport report = TestHelper.checkVersionStoreConsistency(s, false, null);
        assertTrue("Report should have reported broken nodes", !report.getItems().isEmpty());
        try {
            test = s.getRootNode().getNode("test");
            vhr = s.getWorkspace().getVersionManager().getVersionHistory(test.getPath());
            fail("should not get here");
        } catch (Exception ex) {
        // expected
        }
        s.logout();
        System.setProperty("org.apache.jackrabbit.version.recovery", "true");
        s = openSession(rep, false);
        test = s.getRootNode().getNode("test");
        // versioning should be disabled now
        assertFalse(test.isNodeType("mix:versionable"));
        try {
            // try to enable versioning again
            test.addMixin("mix:versionable");
            s.save();
            fail("enabling versioning succeeded unexpectedly");
        } catch (Exception e) {
        // we expect this to fail
        }
        s.logout();
        // now redo after running fixup on versioning storage
        s = openSession(rep, false);
        report = TestHelper.checkVersionStoreConsistency(s, true, null);
        assertTrue("Report should have reported broken nodes", !report.getItems().isEmpty());
        int reportitems = report.getItems().size();
        // problems should now be fixed
        report = TestHelper.checkVersionStoreConsistency(s, false, null);
        assertTrue("Some problems should have been fixed but are not: " + report, report.getItems().size() < reportitems);
        test = s.getRootNode().getNode("test");
        // versioning should be disabled now
        assertFalse(test.isNodeType("mix:versionable"));
        // jcr:uuid property should still be present
        assertTrue(test.hasProperty("jcr:uuid"));
        // ...and have a proper definition
        assertNotNull(test.getProperty("jcr:uuid").getDefinition().getName());
        // try to enable versioning again
        test.addMixin("mix:versionable");
        s.save();
        Node oldVHR = s.getNodeByIdentifier(vhrId);
        Node newVHR = s.getWorkspace().getVersionManager().getVersionHistory(test.getPath());
        assertTrue("old and new version history path should be different: " + oldVHR.getPath() + " vs " + newVHR.getPath(), !oldVHR.getPath().equals(newVHR.getPath()));
        // name should be same plus suffix
        assertTrue(oldVHR.getName().startsWith(newVHR.getName()));
        // try a checkout / checkin
        s.getWorkspace().getVersionManager().checkout(test.getPath());
        s.getWorkspace().getVersionManager().checkin(test.getPath());
        validateDisconnectedVHR(oldVHR);
    } finally {
        s.logout();
        System.setProperty("org.apache.jackrabbit.version.recovery", oldVersionRecoveryProp == null ? "" : oldVersionRecoveryProp);
    }
}
Also used : TransientRepository(org.apache.jackrabbit.core.TransientRepository) Node(javax.jcr.Node) UUID(java.util.UUID) File(java.io.File) ConsistencyReport(org.apache.jackrabbit.core.persistence.check.ConsistencyReport) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) ItemNotFoundException(javax.jcr.ItemNotFoundException) SQLException(java.sql.SQLException) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session)

Example 8 with ConsistencyReport

use of org.apache.jackrabbit.core.persistence.check.ConsistencyReport in project jackrabbit by apache.

the class AutoFixCorruptNode method testMissingVHR.

public void testMissingVHR() throws Exception {
    // new repository
    TransientRepository rep = new TransientRepository(new File(TEST_DIR));
    Session s = openSession(rep, false);
    String oldVersionRecoveryProp = System.getProperty("org.apache.jackrabbit.version.recovery");
    try {
        Node root = s.getRootNode();
        Node test = root.addNode("test");
        test.addMixin("mix:versionable");
        s.save();
        Node vhr = s.getWorkspace().getVersionManager().getVersionHistory(test.getPath());
        assertNotNull(vhr);
        Node brokenNode = vhr;
        String vhrRootVersionId = vhr.getNode("jcr:rootVersion").getIdentifier();
        UUID destroy = UUID.fromString(brokenNode.getIdentifier());
        s.logout();
        destroyBundle(destroy, "version");
        s = openSession(rep, false);
        ConsistencyReport report = TestHelper.checkVersionStoreConsistency(s, false, null);
        assertTrue("Report should have reported broken nodes", !report.getItems().isEmpty());
        try {
            test = s.getRootNode().getNode("test");
            vhr = s.getWorkspace().getVersionManager().getVersionHistory(test.getPath());
            fail("should not get here");
        } catch (Exception ex) {
        // expected
        }
        s.logout();
        System.setProperty("org.apache.jackrabbit.version.recovery", "true");
        s = openSession(rep, false);
        test = s.getRootNode().getNode("test");
        // versioning should be disabled now
        assertFalse(test.isNodeType("mix:versionable"));
        try {
            // try to enable versioning again
            test.addMixin("mix:versionable");
            s.save();
            fail("enabling versioning succeeded unexpectedly");
        } catch (Exception e) {
        // we expect this to fail
        }
        s.logout();
        // now redo after running fixup on versioning storage
        s = openSession(rep, false);
        report = TestHelper.checkVersionStoreConsistency(s, true, null);
        assertTrue("Report should have reported broken nodes", !report.getItems().isEmpty());
        int reportitems = report.getItems().size();
        // problems should now be fixed
        report = TestHelper.checkVersionStoreConsistency(s, false, null);
        assertTrue("Some problems should have been fixed but are not: " + report, report.getItems().size() < reportitems);
        // get a fresh session
        s.logout();
        s = openSession(rep, false);
        test = s.getRootNode().getNode("test");
        // versioning should be disabled now
        assertFalse(test.isNodeType("mix:versionable"));
        // try to enable versioning again
        test.addMixin("mix:versionable");
        s.save();
        Node oldRootVersion = s.getNodeByIdentifier(vhrRootVersionId);
        try {
            String path = oldRootVersion.getPath();
            fail("got path " + path + " for a node believed to be orphaned");
        } catch (ItemNotFoundException ex) {
        // orphaned
        }
        Node newRootVersion = s.getWorkspace().getVersionManager().getVersionHistory(test.getPath()).getRootVersion();
        assertFalse("new root version should be a different node than the one destroyed by the test case", newRootVersion.getIdentifier().equals(vhrRootVersionId));
        assertNotNull("new root version should have a intact path", newRootVersion.getPath());
    } finally {
        s.logout();
        System.setProperty("org.apache.jackrabbit.version.recovery", oldVersionRecoveryProp == null ? "" : oldVersionRecoveryProp);
    }
}
Also used : TransientRepository(org.apache.jackrabbit.core.TransientRepository) Node(javax.jcr.Node) UUID(java.util.UUID) File(java.io.File) ConsistencyReport(org.apache.jackrabbit.core.persistence.check.ConsistencyReport) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) ItemNotFoundException(javax.jcr.ItemNotFoundException) SQLException(java.sql.SQLException) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 9 with ConsistencyReport

use of org.apache.jackrabbit.core.persistence.check.ConsistencyReport in project jackrabbit by apache.

the class AutoFixCorruptNode method testBrokenVhrParent.

// tests recovery from a broken hierarchy in the version store
public void testBrokenVhrParent() throws Exception {
    // new repository
    TransientRepository rep = new TransientRepository(new File(TEST_DIR));
    Session s = openSession(rep, false);
    try {
        Node root = s.getRootNode();
        // add node /test
        Node test = root.addNode("test");
        test.addMixin("mix:versionable");
        s.save();
        Node vhr = s.getWorkspace().getVersionManager().getVersionHistory(test.getPath());
        assertNotNull(vhr);
        Node brokenNode = vhr.getParent().getParent();
        UUID destroy = UUID.fromString(brokenNode.getIdentifier());
        // disable versioning
        test.removeMixin("mix:versionable");
        s.save();
        s.logout();
        destroyBundle(destroy, "version");
        s = openSession(rep, false);
        ConsistencyReport report = TestHelper.checkVersionStoreConsistency(s, true, null);
        assertTrue("Report should have reported broken nodes", !report.getItems().isEmpty());
        s.logout();
        s = openSession(rep, false);
        test = s.getRootNode().getNode("test");
        // versioning should still be disabled
        assertFalse(test.isNodeType("mix:versionable"));
        // try to enable versioning again
        test.addMixin("mix:versionable");
        s.save();
        // try a checkout / checkin
        s.getWorkspace().getVersionManager().checkout(test.getPath());
        s.getWorkspace().getVersionManager().checkin(test.getPath());
    } finally {
        s.logout();
    }
}
Also used : TransientRepository(org.apache.jackrabbit.core.TransientRepository) Node(javax.jcr.Node) UUID(java.util.UUID) File(java.io.File) ConsistencyReport(org.apache.jackrabbit.core.persistence.check.ConsistencyReport) Session(javax.jcr.Session)

Example 10 with ConsistencyReport

use of org.apache.jackrabbit.core.persistence.check.ConsistencyReport in project jackrabbit by apache.

the class AutoFixCorruptNode method testAutoFixWithConsistencyCheck.

/**
     * Unit test for <a
     * href="https://issues.apache.org/jira/browse/JCR-3069">JCR-3069</a>
     */
public void testAutoFixWithConsistencyCheck() throws Exception {
    // new repository
    TransientRepository rep = new TransientRepository(new File(TEST_DIR));
    Session s = openSession(rep, false);
    Node root = s.getRootNode();
    // add nodes /test and /test/missing
    Node test = root.addNode("test");
    Node missing = test.addNode("missing");
    missing.addMixin("mix:referenceable");
    UUID id = UUID.fromString(missing.getIdentifier());
    s.save();
    s.logout();
    destroyBundle(id, "workspaces/default");
    s = openSession(rep, false);
    try {
        ConsistencyReport r = TestHelper.checkConsistency(s, false, null);
        assertNotNull(r);
        assertNotNull(r.getItems());
        assertEquals(1, r.getItems().size());
        assertEquals(test.getIdentifier(), r.getItems().iterator().next().getNodeId());
    } finally {
        s.logout();
        rep.shutdown();
        FileUtils.deleteDirectory(new File("repository"));
    }
}
Also used : TransientRepository(org.apache.jackrabbit.core.TransientRepository) Node(javax.jcr.Node) UUID(java.util.UUID) File(java.io.File) ConsistencyReport(org.apache.jackrabbit.core.persistence.check.ConsistencyReport) Session(javax.jcr.Session)

Aggregations

ConsistencyReport (org.apache.jackrabbit.core.persistence.check.ConsistencyReport)11 Session (javax.jcr.Session)8 Node (javax.jcr.Node)7 File (java.io.File)6 UUID (java.util.UUID)6 TransientRepository (org.apache.jackrabbit.core.TransientRepository)6 SQLException (java.sql.SQLException)2 ItemNotFoundException (javax.jcr.ItemNotFoundException)2 RepositoryException (javax.jcr.RepositoryException)2 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)2 InvalidItemStateException (javax.jcr.InvalidItemStateException)1 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)1