Search in sources :

Example 76 with NodeState

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)));
}
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 77 with NodeState

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"));
}
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 78 with NodeState

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));
}
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 79 with NodeState

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")));
}
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 80 with NodeState

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

Aggregations

NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)580 Test (org.junit.Test)375 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)254 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)69 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)46 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)45 ChildNodeEntry (org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)43 FilterImpl (org.apache.jackrabbit.oak.query.index.FilterImpl)39 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)36 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)33 AbstractNodeState (org.apache.jackrabbit.oak.spi.state.AbstractNodeState)32 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)29 Nonnull (javax.annotation.Nonnull)28 Tree (org.apache.jackrabbit.oak.api.Tree)23 NodeStateTestUtils.getNodeState (org.apache.jackrabbit.oak.upgrade.util.NodeStateTestUtils.getNodeState)23 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)19 DocumentNodeState (org.apache.jackrabbit.oak.plugins.document.DocumentNodeState)18 ArrayList (java.util.ArrayList)17 CommitInfo (org.apache.jackrabbit.oak.spi.commit.CommitInfo)16 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)15