Search in sources :

Example 1 with DocumentNodeState

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);
}
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 2 with DocumentNodeState

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)));
}
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 3 with DocumentNodeState

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

Example 4 with DocumentNodeState

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;
}
Also used : DocumentNodeState(org.apache.jackrabbit.oak.plugins.document.DocumentNodeState) AbstractDocumentNodeState(org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState)

Example 5 with DocumentNodeState

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));
}
Also used : ReadPreference(com.mongodb.ReadPreference) DocumentReadPreference(org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore.DocumentReadPreference) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) Revision(org.apache.jackrabbit.oak.plugins.document.Revision) RevisionVector(org.apache.jackrabbit.oak.plugins.document.RevisionVector) DocumentNodeState(org.apache.jackrabbit.oak.plugins.document.DocumentNodeState) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test) AbstractMongoConnectionTest(org.apache.jackrabbit.oak.plugins.document.AbstractMongoConnectionTest)

Aggregations

DocumentNodeState (org.apache.jackrabbit.oak.plugins.document.DocumentNodeState)7 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)5 Test (org.junit.Test)5 AbstractNodeState (org.apache.jackrabbit.oak.spi.state.AbstractNodeState)3 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)3 AbstractDocumentNodeState (org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState)2 ReadPreference (com.mongodb.ReadPreference)1 AbstractMongoConnectionTest (org.apache.jackrabbit.oak.plugins.document.AbstractMongoConnectionTest)1 Revision (org.apache.jackrabbit.oak.plugins.document.Revision)1 RevisionVector (org.apache.jackrabbit.oak.plugins.document.RevisionVector)1 DocumentReadPreference (org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore.DocumentReadPreference)1 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)1