Search in sources :

Example 21 with NodeBuilder

use of org.apache.jackrabbit.oak.spi.state.NodeBuilder 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)));
}
Also used : DocumentNodeState(org.apache.jackrabbit.oak.plugins.document.DocumentNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) AbstractNodeState(org.apache.jackrabbit.oak.spi.state.AbstractNodeState) DocumentNodeState(org.apache.jackrabbit.oak.plugins.document.DocumentNodeState) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 22 with NodeBuilder

use of org.apache.jackrabbit.oak.spi.state.NodeBuilder in project jackrabbit-oak by apache.

the class DocumentBundlingTest method bundledNodeAndNodeChildrenCache.

@Test
public void bundledNodeAndNodeChildrenCache() 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);
    Set<PathRev> cachedPaths = store.getNodeChildrenCache().asMap().keySet();
    for (PathRev pr : cachedPaths) {
        assertFalse(pr.getPath().contains("jcr:content/renditions"));
    }
}
Also used : PathRev(org.apache.jackrabbit.oak.plugins.document.PathRev) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 23 with NodeBuilder

use of org.apache.jackrabbit.oak.spi.state.NodeBuilder 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"));
}
Also used : DocumentNodeState(org.apache.jackrabbit.oak.plugins.document.DocumentNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) AbstractNodeState(org.apache.jackrabbit.oak.spi.state.AbstractNodeState) DefaultNodeStateDiff(org.apache.jackrabbit.oak.spi.state.DefaultNodeStateDiff) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Test(org.junit.Test)

Example 24 with NodeBuilder

use of org.apache.jackrabbit.oak.spi.state.NodeBuilder 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));
}
Also used : DocumentNodeState(org.apache.jackrabbit.oak.plugins.document.DocumentNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) AbstractNodeState(org.apache.jackrabbit.oak.spi.state.AbstractNodeState) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 25 with NodeBuilder

use of org.apache.jackrabbit.oak.spi.state.NodeBuilder in project jackrabbit-oak by apache.

the class DocumentBundlingTest method hasChildren_BundledNode_NoChild.

@Test
public void hasChildren_BundledNode_NoChild() throws Exception {
    createTestNode("/test/book.jpg", createChild(newNode("app:Asset"), "jcr:content").getNodeState());
    ds.reset();
    assertEquals(0, Iterables.size(getLatestNode("test/book.jpg/jcr:content").getChildNodeNames()));
    assertEquals(0, ds.queryPaths.size());
    NodeBuilder builder = store.getRoot().builder();
    childBuilder(builder, "/test/book.jpg/jcr:content/metadata");
    merge(builder);
    ds.reset();
    assertEquals(1, Iterables.size(getLatestNode("test/book.jpg/jcr:content").getChildNodeNames()));
    assertEquals(0, ds.queryPaths.size());
}
Also used : NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Aggregations

NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)948 Test (org.junit.Test)704 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)253 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)84 FilterImpl (org.apache.jackrabbit.oak.query.index.FilterImpl)74 LuceneIndexHelper.newLuceneIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition)73 LuceneIndexHelper.newLucenePropertyIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition)70 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)67 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)60 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)52 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)49 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)43 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)31 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)31 FileStore (org.apache.jackrabbit.oak.segment.file.FileStore)29 Blob (org.apache.jackrabbit.oak.api.Blob)28 CommitInfo (org.apache.jackrabbit.oak.spi.commit.CommitInfo)24 AbstractNodeState (org.apache.jackrabbit.oak.spi.state.AbstractNodeState)22 QueryIndex (org.apache.jackrabbit.oak.spi.query.QueryIndex)21 Nonnull (javax.annotation.Nonnull)20