Search in sources :

Example 11 with InvalidItemStateException

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

the class ConcurrentImportTest method concurrentImport.

private void concurrentImport(final String[] mixins, final boolean sync) throws RepositoryException {
    final String[] uuids = new String[NUM_NODES];
    for (int i = 0; i < uuids.length; i++) {
        uuids[i] = UUID.randomUUID().toString();
    }
    log.println("concurrentImport: c=" + CONCURRENCY + ", n=" + NUM_NODES);
    log.flush();
    final Lock lock = new ReentrantLock();
    runTask(new Task() {

        public void execute(Session session, Node test) throws RepositoryException {
            try {
                // add versionable nodes
                for (String uuid : uuids) {
                    if (sync) {
                        lock.lock();
                    }
                    try {
                        session.refresh(false);
                        try {
                            addNode(test, uuid, JcrConstants.NT_UNSTRUCTURED, uuid, mixins);
                            session.save();
                            log.println("Added " + test.getPath() + "/" + uuid);
                            log.flush();
                        } catch (InvalidItemStateException e) {
                            log.println("Ignoring expected error: " + e.toString());
                            log.flush();
                            session.refresh(false);
                        }
                    } finally {
                        if (sync) {
                            lock.unlock();
                        }
                    }
                    try {
                        Thread.sleep(1);
                    } catch (InterruptedException e) {
                    // ignore
                    }
                }
            } catch (RepositoryException e) {
                log.println("Error: " + e);
                log.flush();
                throw e;
            }
        }
    }, CONCURRENCY, "/" + testPath);
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Lock(java.util.concurrent.locks.Lock) Session(javax.jcr.Session)

Example 12 with InvalidItemStateException

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

the class ConcurrentReadWriteTest method testReadWrite.

public void testReadWrite() throws RepositoryException {
    final List uuids = new ArrayList();
    for (int i = 0; i < NUM_NODES; i++) {
        Node n = testRootNode.addNode("node" + i);
        n.addMixin(mixReferenceable);
        uuids.add(n.getUUID());
    }
    final List exceptions = Collections.synchronizedList(new ArrayList());
    final long[] numReads = new long[] { 0 };
    testRootNode.save();
    Thread t = new Thread(new Runnable() {

        public void run() {
            try {
                runTask(new Task() {

                    public void execute(Session session, Node test) throws RepositoryException {
                        Random rand = new Random();
                        long start = System.currentTimeMillis();
                        long reads = 0;
                        while (System.currentTimeMillis() < start + RUN_NUM_SECONDS * 1000) {
                            String uuid = (String) uuids.get(rand.nextInt(uuids.size()));
                            Node n = session.getNodeByUUID(uuid);
                            try {
                                for (PropertyIterator it = n.getProperties(); it.hasNext(); ) {
                                    Property p = it.nextProperty();
                                    if (p.isMultiple()) {
                                        p.getValues();
                                    } else {
                                        p.getValue();
                                    }
                                }
                            } catch (InvalidItemStateException e) {
                            // ignore
                            }
                            reads++;
                        }
                        synchronized (numReads) {
                            numReads[0] += reads;
                        }
                    }
                }, NUM_THREADS, testRoot);
            } catch (RepositoryException e) {
                exceptions.add(e);
            }
        }
    });
    t.start();
    long numWrites = 0;
    while (t.isAlive()) {
        Random rand = new Random();
        String uuid = (String) uuids.get(rand.nextInt(uuids.size()));
        Node n = superuser.getNodeByUUID(uuid);
        if (n.hasProperty("test")) {
            n.getProperty("test").remove();
        } else {
            n.setProperty("test", "hello world");
        }
        n.save();
        numWrites++;
    }
    log.println("#writes performed: " + numWrites);
    log.println("#reads performed: " + numReads[0]);
    if (!exceptions.isEmpty()) {
        fail(((RepositoryException) exceptions.get(0)).getMessage());
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node) ArrayList(java.util.ArrayList) PropertyIterator(javax.jcr.PropertyIterator) RepositoryException(javax.jcr.RepositoryException) Random(java.util.Random) List(java.util.List) ArrayList(java.util.ArrayList) Property(javax.jcr.Property) Session(javax.jcr.Session)

Example 13 with InvalidItemStateException

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

the class ConcurrentAddRemoveMoveTest method testRemoveWithMoveFrom.

public void testRemoveWithMoveFrom() throws Exception {
    Node d = testRootNode.getNode("A").addNode("D");
    superuser.save();
    d.remove();
    session.move(testRoot + "/A/B", testRoot + "/C/B");
    superuser.save();
    try {
        session.save();
    } catch (InvalidItemStateException e) {
        fail("must not throw exception");
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node)

Example 14 with InvalidItemStateException

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

the class ConcurrentAddRemoveMoveTest method testMoveToWithRemove.

public void testMoveToWithRemove() throws Exception {
    Node d = session.getNode(testRoot).getNode("A").addNode("D");
    session.save();
    superuser.move(testRoot + "/C", testRoot + "/A/C");
    d.remove();
    testRootNode.getSession().save();
    try {
        session.save();
    } catch (InvalidItemStateException e) {
        fail("must not throw exception");
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node)

Example 15 with InvalidItemStateException

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

the class ConcurrentAddRemoveMoveTest method testRemoveWithMoveTo.

public void testRemoveWithMoveTo() throws Exception {
    Node d = testRootNode.getNode("A").addNode("D");
    superuser.save();
    d.remove();
    session.move(testRoot + "/C", testRoot + "/A/C");
    superuser.save();
    try {
        session.save();
    } catch (InvalidItemStateException e) {
        fail("must not throw exception");
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node)

Aggregations

InvalidItemStateException (javax.jcr.InvalidItemStateException)100 Node (javax.jcr.Node)67 Session (javax.jcr.Session)35 Test (org.junit.Test)21 Property (javax.jcr.Property)15 RepositoryException (javax.jcr.RepositoryException)14 NodeIterator (javax.jcr.NodeIterator)5 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)5 QueryResult (javax.jcr.query.QueryResult)5 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)5 ItemNotFoundException (javax.jcr.ItemNotFoundException)4 NodeType (javax.jcr.nodetype.NodeType)3 SessionImpl (org.apache.jackrabbit.core.SessionImpl)3 NodeId (org.apache.jackrabbit.core.id.NodeId)3 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)3 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)3 NodeState (org.apache.jackrabbit.core.state.NodeState)3 PathNotFoundException (javax.jcr.PathNotFoundException)2 UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)2 Version (javax.jcr.version.Version)2