Search in sources :

Example 11 with TransientRepository

use of org.apache.jackrabbit.core.TransientRepository 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 12 with TransientRepository

use of org.apache.jackrabbit.core.TransientRepository 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)

Example 13 with TransientRepository

use of org.apache.jackrabbit.core.TransientRepository in project jackrabbit by apache.

the class ItemStateCacheSyncTest method setUp.

protected void setUp() throws Exception {
    directory = new File("target", "jackrabbit-sync-test-repo");
    repository = new TransientRepository(directory);
    session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
    // Add a tree of 100k medium-sized (~10kB) nodes
    String[] data = new String[1000];
    Arrays.fill(data, "something");
    root = session.getRootNode();
    for (int i = 0; i < 1000; i++) {
        Node a = root.addNode("a" + i);
        for (int j = 0; j < 100; j++) {
            Node b = a.addNode("b" + j);
            b.setProperty("data", data);
        }
        session.save();
        System.out.println((i + 1) * 1000 + " nodes created");
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) TransientRepository(org.apache.jackrabbit.core.TransientRepository) Node(javax.jcr.Node) File(java.io.File)

Example 14 with TransientRepository

use of org.apache.jackrabbit.core.TransientRepository in project sling by apache.

the class ReorderChildNodesCommandTest method doReorderingTest.

private void doReorderingTest(List<String> nodeNames, List<String> resourceNames, List<String> expected) throws Exception {
    if (expected == null) {
        expected = resourceNames;
    }
    File out = new File(new File("target"), "jackrabbit");
    TransientRepository repo = new TransientRepository(new File(out, "repository.xml"), new File(out, "repository"));
    SimpleCredentials credentials = new SimpleCredentials("admin", "admin".toCharArray());
    Session session = repo.login(credentials);
    List<String> finalOrder;
    try {
        Node content = session.getRootNode().addNode("content");
        for (String nodeName : nodeNames) {
            content.addNode(nodeName);
        }
        session.save();
        ResourceProxy resource = newResource("/content", "nt:unstructured");
        for (String resourceName : resourceNames) {
            resource.addChild(newResource("/content/" + resourceName, "nt:unstructured"));
        }
        ReorderChildNodesCommand cmd = new ReorderChildNodesCommand(repo, credentials, resource, logger);
        cmd.execute().get();
        session.refresh(false);
        finalOrder = new ArrayList<>();
        NodeIterator nodes = session.getNode("/content").getNodes();
        while (nodes.hasNext()) {
            finalOrder.add(nodes.nextNode().getName());
        }
    } finally {
        session.removeItem("/content");
        session.save();
        session.logout();
    }
    assertThat("Incorrect node order", finalOrder, equalTo(expected));
}
Also used : NodeIterator(javax.jcr.NodeIterator) SimpleCredentials(javax.jcr.SimpleCredentials) TransientRepository(org.apache.jackrabbit.core.TransientRepository) Node(javax.jcr.Node) File(java.io.File) ResourceProxy(org.apache.sling.ide.transport.ResourceProxy) Session(javax.jcr.Session)

Aggregations

File (java.io.File)14 TransientRepository (org.apache.jackrabbit.core.TransientRepository)14 Node (javax.jcr.Node)10 Session (javax.jcr.Session)10 UUID (java.util.UUID)7 ConsistencyReport (org.apache.jackrabbit.core.persistence.check.ConsistencyReport)6 SimpleCredentials (javax.jcr.SimpleCredentials)5 RepositoryException (javax.jcr.RepositoryException)3 Context (javax.naming.Context)3 FileNotFoundException (java.io.FileNotFoundException)2 SQLException (java.sql.SQLException)2 ItemNotFoundException (javax.jcr.ItemNotFoundException)2 NodeIterator (javax.jcr.NodeIterator)2 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)2 AccessControlList (javax.jcr.security.AccessControlList)1 AccessControlManager (javax.jcr.security.AccessControlManager)1 AccessControlPolicyIterator (javax.jcr.security.AccessControlPolicyIterator)1 User (org.apache.jackrabbit.api.security.user.User)1 UserManager (org.apache.jackrabbit.api.security.user.UserManager)1 SessionImpl (org.apache.jackrabbit.core.SessionImpl)1