use of org.apache.jackrabbit.oak.plugins.document.DocumentNodeState in project jackrabbit-oak by apache.
the class DocumentBundlingTest method jsonSerialization.
@Test
public void jsonSerialization() throws Exception {
NodeBuilder builder = store.getRoot().builder();
NodeBuilder appNB = newNode("app:Asset");
createChild(appNB, "jcr:content", //not bundled
"jcr:content/comments", "jcr:content/metadata", //not bundled
"jcr:content/metadata/xmp", //includes all
"jcr:content/renditions", "jcr:content/renditions/original", "jcr:content/renditions/original/jcr:content");
builder.child("test").setChildNode("book.jpg", appNB.getNodeState());
merge(builder);
DocumentNodeState appNode = (DocumentNodeState) getNode(store.getRoot(), "test/book.jpg");
String json = appNode.asString();
NodeState appNode2 = DocumentNodeState.fromString(store, json);
AssertingDiff.assertEquals(appNode, appNode2);
}
use of org.apache.jackrabbit.oak.plugins.document.DocumentNodeState in project jackrabbit-oak by apache.
the class DocumentBundlingTest method memory.
@Test
public void memory() throws Exception {
NodeBuilder builder = store.getRoot().builder();
NodeBuilder bundledFileNode = newNode("nt:file");
bundledFileNode.child("jcr:content").setProperty("jcr:data", "foo");
builder.child("test").setChildNode("book.jpg", bundledFileNode.getNodeState());
//Create a non bundled NodeState structure nt:File vs nt:file
NodeBuilder nonBundledFileNode = newNode("nt:File");
nonBundledFileNode.child("jcr:content").setProperty("jcr:data", "foo");
builder.child("test").setChildNode("book2.jpg", nonBundledFileNode.getNodeState());
merge(builder);
NodeState root = store.getRoot();
DocumentNodeState bundledFile = asDocumentState(getNode(root, "/test/book.jpg"));
DocumentNodeState nonBundledFile = asDocumentState(getNode(root, "/test/book2.jpg"));
DocumentNodeState nonBundledContent = asDocumentState(getNode(root, "/test/book2.jpg/jcr:content"));
int nonBundledMem = nonBundledFile.getMemory() + nonBundledContent.getMemory();
int bundledMem = bundledFile.getMemory();
assertEquals(1386, bundledMem);
assertThat(bundledMem, is(greaterThan(nonBundledMem)));
}
use of org.apache.jackrabbit.oak.plugins.document.DocumentNodeState in project jackrabbit-oak by apache.
the class DocumentBundlingTest method documentNodeStateBundledMethods.
@Test
public void documentNodeStateBundledMethods() throws Exception {
NodeBuilder builder = store.getRoot().builder();
NodeBuilder appNB = newNode("app:Asset");
createChild(appNB, "jcr:content", //not bundled
"jcr:content/comments", "jcr:content/metadata", //not bundled
"jcr:content/metadata/xmp", //includes all
"jcr:content/renditions", "jcr:content/renditions/original", "jcr:content/renditions/original/jcr:content");
builder.child("test").setChildNode("book.jpg", appNB.getNodeState());
merge(builder);
DocumentNodeState appNode = (DocumentNodeState) getNode(store.getRoot(), "test/book.jpg");
assertTrue(appNode.hasOnlyBundledChildren());
assertEquals(ImmutableSet.of("jcr:content"), appNode.getBundledChildNodeNames());
assertEquals(ImmutableSet.of("metadata", "renditions"), asDocumentState(appNode.getChildNode("jcr:content")).getBundledChildNodeNames());
builder = store.getRoot().builder();
childBuilder(builder, "/test/book.jpg/foo");
merge(builder);
DocumentNodeState appNode2 = (DocumentNodeState) getNode(store.getRoot(), "test/book.jpg");
assertFalse(appNode2.hasOnlyBundledChildren());
}
use of org.apache.jackrabbit.oak.plugins.document.DocumentNodeState 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.DocumentNodeState in project jackrabbit-oak by apache.
the class ReadPreferenceIT method testMongoReadPreferences.
@Test
public void testMongoReadPreferences() throws Exception {
ReadPreference testPref = ReadPreference.secondary();
mongoDS.getDBCollection(NODES).getDB().setReadPreference(testPref);
NodeStore extNodeStore = mk2.getNodeStore();
NodeBuilder b1 = extNodeStore.getRoot().builder();
b1.child("x").child("y").setProperty("xyz", "123");
extNodeStore.merge(b1, EmptyHook.INSTANCE, CommitInfo.EMPTY);
// wait until the change is visible
NodeStore nodeStore = mk.getNodeStore();
while (true) {
if (nodeStore.getRoot().hasChildNode("x")) {
break;
} else {
Thread.sleep(100);
}
}
// the change hasn't been replicated yet, primary must be used
assertEquals(ReadPreference.primary(), mongoDS.getMongoReadPreference(NODES, null, "/x/y", DocumentReadPreference.PREFER_SECONDARY_IF_OLD_ENOUGH));
// make the secondary up-to-date
DocumentNodeState ns = (DocumentNodeState) nodeStore.getRoot().getChildNode("x").getChildNode("y");
// add revision for the local cluster node
RevisionVector lastSeenRev = ns.getLastRevision().update(new Revision(Revision.getCurrentTimestamp(), 0, 1));
primary.set(lastSeenRev);
secondary.set(lastSeenRev);
replica.updateRevisions();
// change has been replicated by now, it's fine to use secondary
assertEquals(testPref, mongoDS.getMongoReadPreference(NODES, null, "/x/y", DocumentReadPreference.PREFER_SECONDARY_IF_OLD_ENOUGH));
}
Aggregations