use of org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState in project jackrabbit-oak by apache.
the class SecondaryStoreCacheTest method binarySearch.
@Test
public void binarySearch() throws Exception {
SecondaryStoreCache cache = createCache(new PathFilter(of("/a"), empty));
List<AbstractDocumentNodeState> roots = Lists.newArrayList();
List<RevisionVector> revs = Lists.newArrayList();
for (int i = 0; i < 50; i++) {
NodeBuilder nb = primary.getRoot().builder();
create(nb, "/a/b" + i);
AbstractDocumentNodeState r = merge(nb);
roots.add(r);
revs.add(r.getRootRevision());
}
AbstractDocumentNodeState[] rootsArr = Iterables.toArray(roots, AbstractDocumentNodeState.class);
Collections.shuffle(revs);
for (RevisionVector rev : revs) {
AbstractDocumentNodeState result = SecondaryStoreCache.findMatchingRoot(rootsArr, rev);
assertNotNull(result);
assertEquals(rev, result.getRootRevision());
}
NodeBuilder nb = primary.getRoot().builder();
create(nb, "/a/m");
AbstractDocumentNodeState r = merge(nb);
AbstractDocumentNodeState result = SecondaryStoreCache.findMatchingRoot(rootsArr, r.getRootRevision());
assertNull(result);
}
use of org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState in project jackrabbit-oak by apache.
the class DelegatingDocumentNodeStateTest method basicWorking.
@Test
public void basicWorking() throws Exception {
RevisionVector rv1 = new RevisionVector(new Revision(1, 0, 1));
RevisionVector rv2 = new RevisionVector(new Revision(1, 0, 3));
builder.setProperty(asPropertyState(PROP_REVISION, rv1));
builder.setProperty(asPropertyState(PROP_LAST_REV, rv2));
AbstractDocumentNodeState state = DelegatingDocumentNodeState.wrap(builder.getNodeState(), NodeStateDiffer.DEFAULT_DIFFER);
assertEquals(rv1, state.getRootRevision());
assertEquals(rv2, state.getLastRevision());
assertTrue(state.hasNoChildren());
assertTrue(state.exists());
assertFalse(state.isFromExternalChange());
}
use of org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState in project jackrabbit-oak by apache.
the class DelegatingDocumentNodeStateTest method withRootRevision.
@Test
public void withRootRevision() throws Exception {
RevisionVector rv1 = new RevisionVector(new Revision(1, 0, 1));
RevisionVector rv2 = new RevisionVector(new Revision(1, 0, 3));
builder.setProperty(asPropertyState(PROP_REVISION, rv1));
builder.setProperty(asPropertyState(PROP_LAST_REV, rv2));
AbstractDocumentNodeState state = DelegatingDocumentNodeState.wrap(builder.getNodeState(), NodeStateDiffer.DEFAULT_DIFFER);
AbstractDocumentNodeState state2 = state.withRootRevision(rv1, false);
assertSame(state, state2);
RevisionVector rv4 = new RevisionVector(new Revision(1, 0, 4));
AbstractDocumentNodeState state3 = state.withRootRevision(rv4, true);
assertEquals(rv4, state3.getRootRevision());
assertTrue(state3.isFromExternalChange());
}
use of org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState in project jackrabbit-oak by apache.
the class BundledDocumentDiffer method getDocumentNodeState.
private DocumentNodeState getDocumentNodeState(AbstractDocumentNodeState state) {
DocumentNodeState result;
if (state instanceof DocumentNodeState) {
result = (DocumentNodeState) state;
} else if (BundlorUtils.isBundledChild(state)) {
//In case of bundle child determine the bundling root
//and from there traverse down to the actual child node
checkState(BundlorUtils.isBundledChild(state));
String bundlingPath = state.getString(DocumentBundlor.META_PROP_BUNDLING_PATH);
String bundlingRootPath = PathUtils.getAncestorPath(state.getPath(), PathUtils.getDepth(bundlingPath));
DocumentNodeState bundlingRoot = nodeStore.getNode(bundlingRootPath, state.getLastRevision());
result = (DocumentNodeState) NodeStateUtils.getNode(bundlingRoot, bundlingPath);
} else {
result = nodeStore.getNode(state.getPath(), state.getLastRevision());
}
checkNotNull(result, "Node at [%s] not found for fromRev [%s]", state.getPath(), state.getLastRevision());
return result;
}
use of org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState in project jackrabbit-oak by apache.
the class BundledDocumentDiffer method diff.
/**
* Performs diff for bundled nodes. The passed state can be DocumentNodeState or
* one from secondary nodestore i.e. {@code DelegatingDocumentNodeState}. So the
* passed states cannot be cast down to DocumentNodeState
*
* @param from from state
* @param to to state
* @param w jsop diff
* @return true if the diff needs to be continued. In case diff is complete it would return false
*/
public boolean diff(AbstractDocumentNodeState from, AbstractDocumentNodeState to, JsopWriter w) {
boolean fromBundled = BundlorUtils.isBundledNode(from);
boolean toBundled = BundlorUtils.isBundledNode(to);
//Neither of the nodes bundled
if (!fromBundled && !toBundled) {
return true;
}
DocumentNodeState fromDocState = getDocumentNodeState(from);
DocumentNodeState toDocState = getDocumentNodeState(to);
diffChildren(fromDocState.getBundledChildNodeNames(), toDocState.getBundledChildNodeNames(), w);
//If all child nodes are bundled then diff is complete
if (fromDocState.hasOnlyBundledChildren() && toDocState.hasOnlyBundledChildren()) {
return false;
}
return true;
}
Aggregations