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);
}
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());
}
}
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");
}
}
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");
}
}
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");
}
}
Aggregations