Search in sources :

Example 76 with PropertyState

use of org.apache.jackrabbit.oak.api.PropertyState 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 77 with PropertyState

use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.

the class AllPermissionsTest method testIsGranted.

@Test
public void testIsGranted() {
    for (String path : paths) {
        Tree tree = RootFactory.createReadOnlyRoot(root).getTree(path);
        assertTrue(tree.exists());
        assertTrue(all.isGranted(tree, null, Permissions.ALL));
        for (PropertyState prop : tree.getProperties()) {
            assertTrue(all.isGranted(tree, prop, Permissions.ALL));
        }
        for (Tree child : tree.getChildren()) {
            assertTrue(all.isGranted(child, null, Permissions.ALL));
        }
    }
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 78 with PropertyState

use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.

the class EmptyCugTreePermissionTest method testIsGrantedProperty.

@Test
public void testIsGrantedProperty() {
    PropertyState ps = PropertyStates.createProperty("prop", "val");
    assertFalse(tp.isGranted(Permissions.ALL, ps));
    assertFalse(tp.isGranted(Permissions.WRITE, ps));
    assertFalse(tp.isGranted(Permissions.READ, ps));
}
Also used : PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Test(org.junit.Test)

Example 79 with PropertyState

use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.

the class DocumentPropertyState method size.

@Override
public long size(int index) {
    long size;
    PropertyState parsed = parsed();
    if (parsed.getType() == Type.BINARIES) {
        size = parsed.getValue(Type.BINARY, index).length();
    } else {
        size = parsed.size(index);
    }
    return size;
}
Also used : StringPropertyState(org.apache.jackrabbit.oak.plugins.memory.StringPropertyState) LongPropertyState(org.apache.jackrabbit.oak.plugins.memory.LongPropertyState) BooleanPropertyState(org.apache.jackrabbit.oak.plugins.memory.BooleanPropertyState) AbstractPropertyState(org.apache.jackrabbit.oak.plugins.memory.AbstractPropertyState) BinaryPropertyState(org.apache.jackrabbit.oak.plugins.memory.BinaryPropertyState) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) DoublePropertyState(org.apache.jackrabbit.oak.plugins.memory.DoublePropertyState)

Example 80 with PropertyState

use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.

the class DocumentNodeState method getMemory.

@Override
public int getMemory() {
    long size = // shallow
    40 + (lastRevision != null ? lastRevision.getMemory() : 0) + rootRevision.getMemory() + estimateMemoryUsage(path);
    // rough approximation for properties
    for (Map.Entry<String, PropertyState> entry : bundlingContext.getAllProperties().entrySet()) {
        // name
        size += estimateMemoryUsage(entry.getKey());
        PropertyState propState = entry.getValue();
        if (propState.getType() != Type.BINARY && propState.getType() != Type.BINARIES) {
            for (int i = 0; i < propState.count(); i++) {
                // size() returns length of string
                // shallow memory:
                // - 8 bytes per reference in values list
                // - 48 bytes per string
                // double useage per property because of parsed PropertyState
                size += (56 + propState.size(i) * 2) * 2;
            }
        } else {
            // calculate size based on blobId value
            // referencing the binary in the blob store
            // double the size because the parsed PropertyState
            // will have a similarly sized blobId as well
            size += (long) estimateMemoryUsage(getPropertyAsString(entry.getKey())) * 2;
        }
    }
    if (size > Integer.MAX_VALUE) {
        log.debug("Estimated memory footprint larger than Integer.MAX_VALUE: {}.", size);
        size = Integer.MAX_VALUE;
    }
    return (int) size;
}
Also used : HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Aggregations

PropertyState (org.apache.jackrabbit.oak.api.PropertyState)404 Test (org.junit.Test)189 Tree (org.apache.jackrabbit.oak.api.Tree)138 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)49 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)45 Nonnull (javax.annotation.Nonnull)31 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)29 RemoteTree (org.apache.jackrabbit.oak.remote.RemoteTree)28 RemoteValue (org.apache.jackrabbit.oak.remote.RemoteValue)28 Blob (org.apache.jackrabbit.oak.api.Blob)21 ArrayList (java.util.ArrayList)20 LongPropertyState (org.apache.jackrabbit.oak.plugins.memory.LongPropertyState)17 ChildNodeEntry (org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)16 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)14 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)13 CheckForNull (javax.annotation.CheckForNull)12 RepositoryException (javax.jcr.RepositoryException)10 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)10 Map (java.util.Map)9 Value (javax.jcr.Value)9