use of org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider in project jackrabbit-oak by apache.
the class CommitContextTest method attributesBeingReset.
@Test
public void attributesBeingReset() throws Exception {
// This test can only work with DocumentNodeStore as only that
// reattempt a failed merge. SegmentNodeStore would not do another
// attempt
assumeDocumentStore();
final AtomicInteger invokeCount = new AtomicInteger();
repository = new Oak(store).with(new OpenSecurityProvider()).with(observer).with(new CommitHook() {
@Nonnull
@Override
public NodeState processCommit(NodeState before, NodeState after, CommitInfo info) throws CommitFailedException {
CommitContext attrs = (CommitContext) info.getInfo().get(CommitContext.NAME);
int count = invokeCount.getAndIncrement();
if (count == 0) {
attrs.set("a", "1");
attrs.set("b", "2");
} else {
attrs.set("a", "3");
}
return after;
}
}).with(new CommitHook() {
@Nonnull
@Override
public NodeState processCommit(NodeState before, NodeState after, CommitInfo info) throws CommitFailedException {
if (invokeCount.get() == 1) {
throw new CommitFailedException(MERGE, 0, "attribute reset test");
}
return after;
}
}).createContentRepository();
session = newSession();
Root root = session.getLatestRoot();
Tree tree = root.getTree("/");
tree.setProperty("a", 1);
root.commit();
assertNotNull(observer.info);
CommitContext attrs = (CommitContext) observer.info.getInfo().get(CommitContext.NAME);
assertEquals("3", attrs.get("a"));
assertNull(attrs.get("b"));
}
Aggregations