Search in sources :

Example 51 with NodeIterator

use of javax.jcr.NodeIterator in project jackrabbit by apache.

the class ConcurrentWorkspaceCopyTest method testConcurrentCopy.

public void testConcurrentCopy() throws Exception {
    for (int n = 0; n < NUM_ITERATIONS; n++) {
        // cleanup
        while (superuser.nodeExists(destPath)) {
            superuser.getNode(destPath).remove();
            superuser.save();
        }
        Thread[] threads = new Thread[NUM_SESSIONS];
        for (int i = 0; i < threads.length; i++) {
            // create new session
            Session session = getHelper().getSuperuserSession();
            String id = "session#" + i;
            TestSession ts = new TestSession(id, session);
            Thread t = new Thread(ts);
            t.setName(id);
            t.start();
            threads[i] = t;
        }
        for (int i = 0; i < threads.length; i++) {
            threads[i].join();
        }
        NodeIterator results = superuser.getNode(destParentPath).getNodes(TARGET_NAME);
        assertEquals(1, results.getSize());
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) Session(javax.jcr.Session)

Example 52 with NodeIterator

use of javax.jcr.NodeIterator in project jackrabbit by apache.

the class ConcurrencyTest3 method scan.

private void scan(Node node) throws RepositoryException {
    // System.err.println(node.getName() + " - " + node.getPath());
    for (NodeIterator it = node.getNodes(); it.hasNext(); ) {
        Node child = it.nextNode();
        scan(child);
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) Node(javax.jcr.Node)

Example 53 with NodeIterator

use of javax.jcr.NodeIterator in project jackrabbit by apache.

the class SkipDeletedNodesTest method testRemoveLastNode.

/**
     * Executes a query with one session and removes a node from that query
     * result with another session.
     */
public void testRemoveLastNode() throws RepositoryException {
    testRootNode.addNode("node1");
    testRootNode.addNode("node2");
    Node n3 = testRootNode.addNode("node3");
    testRootNode.save();
    // query the workspace for all three nodes
    String stmt = testPath + "/*";
    QueryResult res = qm.createQuery(stmt, Query.XPATH).execute();
    // now remove the last node
    n3.remove();
    testRootNode.save();
    // iterate over nodes
    int count = 0;
    log.println("Result nodes:");
    for (NodeIterator it = res.getNodes(); it.hasNext(); ) {
        assertEquals("Wrong value for getPosition().", count++, it.getPosition());
        try {
            log.println(it.nextNode().getPath());
        } catch (InvalidItemStateException e) {
            // this is allowed
            log.println("Invalid: <deleted>");
        }
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) QueryResult(javax.jcr.query.QueryResult) InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node)

Example 54 with NodeIterator

use of javax.jcr.NodeIterator in project jackrabbit by apache.

the class SkipDeletedNodesTest method testRemoveFirstNodeAfterHasNext.

/**
     * Executes a query with one session and removes a node from that query
     * result with another session.
     * </p>This test is different from the other tests that it removes the
     * node after another session has called hasNext() to retrieve the node
     * that gets deleted.
     */
public void testRemoveFirstNodeAfterHasNext() throws RepositoryException {
    Node n1 = testRootNode.addNode("node1");
    testRootNode.addNode("node2");
    testRootNode.addNode("node3");
    testRootNode.save();
    // query the workspace for all three nodes
    String stmt = testPath + "/*";
    QueryResult res = qm.createQuery(stmt, Query.XPATH).execute();
    NodeIterator it = res.getNodes();
    it.hasNext();
    // now remove the first node
    n1.remove();
    testRootNode.save();
    // iterate over nodes
    int count = 0;
    log.println("Result nodes:");
    while (it.hasNext()) {
        assertEquals("Wrong value for getPosition().", count++, it.getPosition());
        try {
            log.println(it.nextNode().getPath());
        } catch (InvalidItemStateException e) {
            // this is allowed
            log.println("Invalid: <deleted>");
        }
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) QueryResult(javax.jcr.query.QueryResult) InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node)

Example 55 with NodeIterator

use of javax.jcr.NodeIterator in project jackrabbit by apache.

the class SkipDeletedNodesTest method testRemoveSomeNode.

/**
     * Executes a query with one session and removes a node from that query
     * result with another session.
     */
public void testRemoveSomeNode() throws RepositoryException {
    testRootNode.addNode("node1");
    Node n2 = testRootNode.addNode("node2");
    testRootNode.addNode("node3");
    testRootNode.save();
    // query the workspace for all three nodes
    String stmt = testPath + "/*";
    QueryResult res = qm.createQuery(stmt, Query.XPATH).execute();
    // now remove the second node
    n2.remove();
    testRootNode.save();
    // iterate over nodes
    int count = 0;
    log.println("Result nodes:");
    for (NodeIterator it = res.getNodes(); it.hasNext(); ) {
        assertEquals("Wrong value for getPosition().", count++, it.getPosition());
        try {
            log.println(it.nextNode().getPath());
        } catch (InvalidItemStateException e) {
            // this is allowed
            log.println("Invalid: <deleted>");
        }
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) QueryResult(javax.jcr.query.QueryResult) InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node)

Aggregations

NodeIterator (javax.jcr.NodeIterator)307 Node (javax.jcr.Node)214 Session (javax.jcr.Session)55 QueryResult (javax.jcr.query.QueryResult)52 RepositoryException (javax.jcr.RepositoryException)40 Query (javax.jcr.query.Query)40 Test (org.junit.Test)36 QueryManager (javax.jcr.query.QueryManager)34 PropertyIterator (javax.jcr.PropertyIterator)30 ArrayList (java.util.ArrayList)26 Property (javax.jcr.Property)24 Version (javax.jcr.version.Version)23 NoSuchElementException (java.util.NoSuchElementException)19 Value (javax.jcr.Value)19 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)19 HashSet (java.util.HashSet)13 PathNotFoundException (javax.jcr.PathNotFoundException)12 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)11 NodeImpl (org.apache.jackrabbit.core.NodeImpl)11 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)11