use of org.apache.jackrabbit.oak.spi.state.NodeState 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.spi.state.NodeState in project jackrabbit-oak by apache.
the class DocumentBundlingTest method journalDiffAndBundling.
@Test
public void journalDiffAndBundling() throws Exception {
NodeBuilder builder = store.getRoot().builder();
NodeBuilder fileNode = newNode("nt:file");
fileNode.child("jcr:content").setProperty("jcr:data", "foo");
builder.child("test").setChildNode("book.jpg", fileNode.getNodeState());
NodeState r1 = merge(builder);
builder = store.getRoot().builder();
childBuilder(builder, "/test/book.jpg/jcr:content").setProperty("fooContent", "bar");
childBuilder(builder, "/test/book.jpg").setProperty("fooBook", "bar");
NodeState r2 = merge(builder);
final List<String> addedPropertyNames = Lists.newArrayList();
r2.compareAgainstBaseState(r1, new DefaultNodeStateDiff() {
@Override
public boolean propertyAdded(PropertyState after) {
addedPropertyNames.add(after.getName());
return super.propertyAdded(after);
}
@Override
public boolean childNodeChanged(String name, NodeState before, NodeState after) {
return after.compareAgainstBaseState(before, this);
}
});
assertTrue("No change reported for /test/book.jpg", addedPropertyNames.contains("fooBook"));
assertTrue("No change reported for /test/book.jpg/jcr:content", addedPropertyNames.contains("fooContent"));
}
use of org.apache.jackrabbit.oak.spi.state.NodeState in project jackrabbit-oak by apache.
the class DocumentBundlingTest method addBundledNodePostInitialCreation.
@Test
public void addBundledNodePostInitialCreation() 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);
builder = store.getRoot().builder();
NodeBuilder renditions = childBuilder(builder, "/test/book.jpg/jcr:content/renditions");
renditions.child("small").child("jcr:content");
NodeState appNode_v2 = childBuilder(builder, "/test/book.jpg").getNodeState();
merge(builder);
assertThat(childNames(getLatestNode("/test/book.jpg"), "jcr:content/renditions"), hasItems("original", "small"));
assertTrue(AssertingDiff.assertEquals(getLatestNode("/test/book.jpg"), appNode_v2));
}
use of org.apache.jackrabbit.oak.spi.state.NodeState in project jackrabbit-oak by apache.
the class DocumentBundlingTest method modifyBundledChild.
@Test
public void modifyBundledChild() 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);
//Modify bundled property
builder = store.getRoot().builder();
childBuilder(builder, "/test/book.jpg/jcr:content").setProperty("foo", "bar");
merge(builder);
NodeState state = childBuilder(builder, "/test/book.jpg").getNodeState();
assertEquals("bar", getLatestNode("/test/book.jpg/jcr:content").getString("foo"));
assertTrue(AssertingDiff.assertEquals(state, getLatestNode("/test/book.jpg")));
//Modify deep bundled property
builder = store.getRoot().builder();
childBuilder(builder, "/test/book.jpg/jcr:content/renditions").setProperty("foo", "bar");
merge(builder);
state = childBuilder(builder, "/test/book.jpg").getNodeState();
assertEquals("bar", getLatestNode("/test/book.jpg/jcr:content/renditions").getString("foo"));
assertTrue(AssertingDiff.assertEquals(state, getLatestNode("/test/book.jpg")));
//Modify deep unbundled property - jcr:content/comments/@foo
builder = store.getRoot().builder();
childBuilder(builder, "/test/book.jpg/jcr:content/comments").setProperty("foo", "bar");
merge(builder);
state = childBuilder(builder, "/test/book.jpg").getNodeState();
assertEquals("bar", getLatestNode("/test/book.jpg/jcr:content/comments").getString("foo"));
assertTrue(AssertingDiff.assertEquals(state, getLatestNode("/test/book.jpg")));
}
use of org.apache.jackrabbit.oak.spi.state.NodeState in project jackrabbit-oak by apache.
the class ChangeCollectorProviderTest method testNull.
@Test
public void testNull() {
NodeBuilder builder = EMPTY_NODE.builder();
builder.setChildNode("test");
builder.setChildNode("a1").setChildNode("b1").setProperty("p1", 1);
NodeState before = builder.getNodeState();
builder = before.builder();
builder.setChildNode("a2").setChildNode("b12").setProperty("p12", "12");
NodeState after = builder.getNodeState();
assertNull(collectorProvider.getRootValidator(before, after, null));
assertNull(collectorProvider.getRootValidator(before, after, CommitInfo.EMPTY));
assertNotNull(collectorProvider.getRootValidator(before, after, newCommitInfoWithCommitContext(CommitInfo.OAK_UNKNOWN, CommitInfo.OAK_UNKNOWN)));
}
Aggregations