use of org.apache.jackrabbit.oak.plugins.document.UpdateOp.Key in project jackrabbit-oak by apache.
the class DocumentStoreStatsIT method removeConditional.
@Test
public void removeConditional() throws Exception {
Revision r = Revision.newRevision(1);
Key modified = new Key(MODIFIED_IN_SECS, null);
Condition c = newEqualsCondition(getModifiedInSecs(r.getTimestamp()));
Map<String, Map<Key, Condition>> ids = Maps.newHashMap();
for (int i = 0; i < 10; i++) {
String id = testName.getMethodName() + "-" + i;
ids.put(id, singletonMap(modified, c));
UpdateOp up = new UpdateOp(id, true);
NodeDocument.setModified(up, r);
ds.create(Collection.NODES, singletonList(up));
removeMe.add(id);
}
DocumentStoreStatsCollector coll = mock(DocumentStoreStatsCollector.class);
configureStatsCollector(coll);
ds.remove(Collection.NODES, ids);
verify(coll).doneRemove(anyLong(), eq(Collection.NODES), eq(10));
}
use of org.apache.jackrabbit.oak.plugins.document.UpdateOp.Key in project jackrabbit-oak by apache.
the class DocumentNodeStoreTest method failFastOnBranchConflict.
@Test
public void failFastOnBranchConflict() throws Exception {
final AtomicInteger mergeAttempts = new AtomicInteger();
MemoryDocumentStore store = new MemoryDocumentStore() {
@Override
public <T extends Document> T findAndUpdate(Collection<T> collection, UpdateOp update) {
for (Key k : update.getConditions().keySet()) {
if (k.getName().equals(NodeDocument.COLLISIONS)) {
mergeAttempts.incrementAndGet();
break;
}
}
return super.findAndUpdate(collection, update);
}
};
DocumentNodeStore ds = builderProvider.newBuilder().setDocumentStore(store).setAsyncDelay(0).getNodeStore();
DocumentNodeState root = ds.getRoot();
DocumentNodeStoreBranch b = ds.createBranch(root);
// branch state is now Unmodified
NodeBuilder builder = root.builder();
builder.child("foo");
b.setRoot(builder.getNodeState());
// branch state is now InMemory
for (int i = 0; i < DocumentMK.UPDATE_LIMIT; i++) {
builder.child("bar").setProperty("p-" + i, "foo");
}
b.setRoot(builder.getNodeState());
// branch state is now Persisted
// create conflict with persisted branch
NodeBuilder nb = ds.getRoot().builder();
nb.child("bar").setProperty("p", "bar");
merge(ds, nb);
mergeAttempts.set(0);
try {
b.merge(EmptyHook.INSTANCE, CommitInfo.EMPTY);
fail("must fail with CommitFailedException");
} catch (CommitFailedException e) {
// expected
}
assertTrue("too many merge attempts: " + mergeAttempts.get(), mergeAttempts.get() <= 1);
}
use of org.apache.jackrabbit.oak.plugins.document.UpdateOp.Key in project jackrabbit-oak by apache.
the class NodeDocumentSweeperTest method sweepUncommittedBeforeHead.
@Test
public void sweepUncommittedBeforeHead() throws Exception {
Revision uncommitted = ns.newRevision();
NodeBuilder b = ns.getRoot().builder();
b.child("test");
merge(ns, b);
ns.runBackgroundUpdateOperations();
UpdateOp op = new UpdateOp(getIdFromPath("/test"), false);
op.setMapEntry("foo", uncommitted, "value");
setCommitRoot(op, uncommitted, 0);
setModified(op, uncommitted);
assertNotNull(store.findAndUpdate(NODES, op));
List<UpdateOp> ops = Lists.newArrayList();
Revision nextSweepStart = sweep(ops);
assertEquals(ns.getHeadRevision().getRevision(ns.getClusterId()), nextSweepStart);
assertEquals(1, ops.size());
op = ops.get(0);
Map<Key, Operation> changes = op.getChanges();
assertEquals(2, changes.size());
Operation o = changes.get(new Key(COMMIT_ROOT, uncommitted));
assertNotNull(o);
assertEquals(REMOVE_MAP_ENTRY, o.type);
o = changes.get(new Key("foo", uncommitted));
assertNotNull(o);
assertEquals(REMOVE_MAP_ENTRY, o.type);
}
use of org.apache.jackrabbit.oak.plugins.document.UpdateOp.Key in project jackrabbit-oak by apache.
the class NodeDocumentSweeperTest method updatePre18Branch.
@Test
public void updatePre18Branch() throws Exception {
String branchRev = mk.branch(null);
branchRev = mk.commit("/", "+\"foo\":{}", branchRev, null);
mk.merge(branchRev, null);
ns.runBackgroundUpdateOperations();
// simulate a pre 1.8 branch commit by removing the branch commit entry
NodeDocument doc = store.find(NODES, getIdFromPath("/foo"));
assertNotNull(doc);
assertEquals(1, doc.getLocalBranchCommits().size());
UpdateOp op = new UpdateOp(doc.getId(), false);
for (Revision r : doc.getLocalBranchCommits()) {
NodeDocument.removeBranchCommit(op, r);
}
assertNotNull(store.findAndUpdate(NODES, op));
List<UpdateOp> ops = Lists.newArrayList();
Revision nextSweepStart = sweep(ops);
assertEquals(ns.getHeadRevision().getRevision(ns.getClusterId()), nextSweepStart);
assertEquals(1, ops.size());
op = ops.get(0);
Map<Key, Operation> changes = op.getChanges();
assertEquals(1, changes.size());
Key k = changes.keySet().iterator().next();
assertEquals("_bc", k.getName());
assertEquals(SET_MAP_ENTRY, changes.get(k).type);
}
Aggregations