use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.
the class PrivilegeValidatorTest method testBitsConflict.
@Test
public void testBitsConflict() {
try {
Tree privTree = createPrivilegeTree("test");
bitsProvider.getBits(JCR_READ).writeTo(privTree);
root.commit();
fail("Conflicting privilege bits property must be detected.");
} catch (CommitFailedException e) {
// success
assertTrue(e.isConstraintViolation());
assertEquals(49, e.getCode());
} finally {
root.refresh();
}
}
use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.
the class NodeStoreTest method rebaseWithFailedMerge.
// OAK-1320
@Test
public void rebaseWithFailedMerge() throws CommitFailedException {
NodeBuilder rootBuilder = store.getRoot().builder();
rootBuilder.child("foo");
// commit something in between to force rebase
NodeBuilder b = store.getRoot().builder();
b.child("bar");
store.merge(b, EmptyHook.INSTANCE, CommitInfo.EMPTY);
try {
store.merge(rootBuilder, new CommitHook() {
@Nonnull
@Override
public NodeState processCommit(NodeState before, NodeState after, CommitInfo info) throws CommitFailedException {
throw new CommitFailedException("", 0, "commit rejected");
}
}, CommitInfo.EMPTY);
fail("must throw CommitFailedException");
} catch (CommitFailedException e) {
// expected
}
// merge again
NodeState root = store.merge(rootBuilder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
assertTrue(root.hasChildNode("bar"));
}
use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.
the class NodeDelegate method unlock.
public void unlock() throws RepositoryException {
String path = getPath();
Root root = sessionDelegate.getContentSession().getLatestRoot();
Tree tree = root.getTree(path);
if (!tree.exists()) {
throw new ItemNotFoundException("Node " + path + " does not exist");
} else if (!isNodeType(tree, MIX_LOCKABLE, root)) {
throw new LockException("Node " + path + " is not lockable");
} else if (!tree.hasProperty(JCR_LOCKISDEEP)) {
throw new LockException("Node " + path + " is not locked");
}
try {
tree.removeProperty(JCR_LOCKISDEEP);
tree.removeProperty(JCR_LOCKOWNER);
sessionDelegate.commit(root);
} catch (CommitFailedException e) {
if (e.isAccessViolation()) {
throw new AccessControlException("Access denied to unlock node " + path, e);
} else {
throw new RepositoryException("Unable to unlock node " + path, e);
}
}
}
use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.
the class NodeDelegate method lock.
public void lock(boolean isDeep) throws RepositoryException {
String path = getPath();
Root root = sessionDelegate.getContentSession().getLatestRoot();
Tree tree = root.getTree(path);
if (!tree.exists()) {
throw new ItemNotFoundException("Node " + path + " does not exist");
} else if (!isNodeType(tree, MIX_LOCKABLE, root)) {
throw new LockException("Node " + path + " is not lockable");
} else if (tree.hasProperty(JCR_LOCKISDEEP)) {
throw new LockException("Node " + path + " is already locked");
}
// look for locked ancestor
Tree inheritedLock = findLock(tree, true);
if (inheritedLock != null) {
throw new LockException("Node already indirectly locked by " + inheritedLock.getPath());
}
// scan for locked descendant
if (isDeep) {
Tree descendantLock = findDescendantLock(tree);
if (descendantLock != null) {
throw new LockException("Lock conflicts with lock hold by " + descendantLock.getPath());
}
}
try {
String owner = sessionDelegate.getAuthInfo().getUserID();
if (owner == null) {
owner = "";
}
tree.setProperty(JCR_LOCKISDEEP, isDeep);
tree.setProperty(JCR_LOCKOWNER, owner);
sessionDelegate.commit(root);
} catch (CommitFailedException e) {
if (e.isAccessViolation()) {
throw new AccessControlException("Access denied to lock node " + path, e);
} else {
throw new RepositoryException("Unable to lock node " + path, e);
}
}
}
use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.
the class SlowObservationIT method initJcr.
@Override
protected Jcr initJcr(Jcr jcr) {
CommitRateLimiter limiter = new CommitRateLimiter() {
long lastLog;
@Override
public void setDelay(long delay) {
long now = System.currentTimeMillis();
if (now > lastLog + 1000) {
log("Delay " + delay);
lastLog = now;
}
super.setDelay(delay);
}
@Override
protected void delay() throws CommitFailedException {
if (!NO_DELAY_JUST_BLOCK) {
// default behavior
super.delay();
return;
}
if (getBlockCommits() && isThreadBlocking()) {
synchronized (this) {
try {
while (getBlockCommits()) {
wait(1000);
}
} catch (InterruptedException e) {
throw new CommitFailedException(CommitFailedException.OAK, 2, "Interrupted while waiting to commit", e);
}
}
}
}
};
return super.initJcr(jcr).with(limiter);
}
Aggregations