Search in sources :

Example 11 with DocumentNodeStore

use of org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore in project jackrabbit-oak by apache.

the class SameNodeSiblingsTest method snsShouldntBeRenamed.

@Test
public void snsShouldntBeRenamed() throws RepositoryException, IOException {
    DocumentNodeStore nodeStore = migrate(new SourceDataCreator() {

        @Override
        public void create(Session session) throws RepositoryException {
            Node parent = session.getRootNode().addNode("parent");
            parent.addNode("child", "nt:folder");
            parent.addNode("child", "nt:folder");
            parent.addNode("child", "nt:folder");
            parent.addNode("something_else", "nt:folder");
            session.save();
        }
    });
    try {
        NodeState parent = nodeStore.getRoot().getChildNode("parent");
        Set<String> children = newHashSet(parent.getChildNodeNames());
        assertEquals(of("child", "child[2]", "child[3]", "something_else"), children);
    } finally {
        nodeStore.dispose();
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) Node(javax.jcr.Node) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session) Test(org.junit.Test)

Example 12 with DocumentNodeStore

use of org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore in project jackrabbit-oak by apache.

the class SameNodeSiblingsTest method snsShouldBeRenamed.

@Test
public void snsShouldBeRenamed() throws RepositoryException, IOException {
    DocumentNodeStore nodeStore = migrate(new SourceDataCreator() {

        @Override
        public void create(Session session) throws RepositoryException {
            Node parent = session.getRootNode().addNode("parent");
            parent.addNode("child", "nt:folder");
            parent.addNode("child", "nt:folder");
            parent.addNode("child", "nt:folder");
            parent.addNode("something_else", "nt:folder");
            session.save();
            // change parent type to
            parent.setPrimaryType("nt:folder");
            // something that doesn't
            // allow SNS
            session.save();
        }
    });
    try {
        NodeState parent = nodeStore.getRoot().getChildNode("parent");
        Set<String> children = newHashSet(parent.getChildNodeNames());
        assertEquals(of("child", "child_2_", "child_3_", "something_else"), children);
    } finally {
        nodeStore.dispose();
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) Node(javax.jcr.Node) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session) Test(org.junit.Test)

Example 13 with DocumentNodeStore

use of org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore in project jackrabbit-oak by apache.

the class ReadOnlyDocumentStoreWrapperTest method backgroundRead.

@Test
public void backgroundRead() throws Exception {
    DocumentStore docStore = new MemoryDocumentStore();
    DocumentNodeStore store = builderProvider.newBuilder().setAsyncDelay(0).setDocumentStore(docStore).setClusterId(2).getNodeStore();
    DocumentNodeStore readOnlyStore = builderProvider.newBuilder().setAsyncDelay(0).setDocumentStore(docStore).setClusterId(1).setReadOnlyMode().getNodeStore();
    NodeBuilder builder = store.getRoot().builder();
    builder.child("node");
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    store.runBackgroundOperations();
    // at this point node must not be visible
    assertFalse(readOnlyStore.getRoot().hasChildNode("node"));
    readOnlyStore.runBackgroundOperations();
    // at this point node should get visible
    assertTrue(readOnlyStore.getRoot().hasChildNode("node"));
}
Also used : DocumentStore(org.apache.jackrabbit.oak.plugins.document.DocumentStore) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 14 with DocumentNodeStore

use of org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore in project jackrabbit-oak by apache.

the class UtilsTest method getAllDocuments.

@Test
public void getAllDocuments() throws CommitFailedException {
    DocumentNodeStore store = new DocumentMK.Builder().getNodeStore();
    try {
        NodeBuilder builder = store.getRoot().builder();
        for (int i = 0; i < 1000; i++) {
            builder.child("test-" + i);
        }
        store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
        assertEquals(1001, /* root + 1000 children */
        Iterables.size(Utils.getAllDocuments(store.getDocumentStore())));
    } finally {
        store.dispose();
    }
}
Also used : DocumentMK(org.apache.jackrabbit.oak.plugins.document.DocumentMK) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 15 with DocumentNodeStore

use of org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore in project jackrabbit-oak by apache.

the class JdbcFactory method create.

@Override
public NodeStore create(BlobStore blobStore, Closer closer) throws IOException {
    System.setProperty(DocumentNodeStore.SYS_PROP_DISABLE_JOURNAL, "true");
    DocumentMK.Builder builder = MongoFactory.getBuilder(cacheSize);
    if (blobStore != null) {
        builder.setBlobStore(blobStore);
    }
    builder.setRDBConnection(getDataSource(closer));
    if (readOnly) {
        builder.setReadOnlyMode();
    }
    log.info("Initialized DocumentNodeStore on RDB with Cache size : {} MB, Fast migration : {}", cacheSize, builder.isDisableBranches());
    DocumentNodeStore documentNodeStore = builder.getNodeStore();
    // TODO probably we should disable all observers, see OAK-5651
    documentNodeStore.getBundlingConfigHandler().unregisterObserver();
    closer.register(MongoFactory.asCloseable(documentNodeStore));
    return documentNodeStore;
}
Also used : DocumentMK(org.apache.jackrabbit.oak.plugins.document.DocumentMK) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore)

Aggregations

DocumentNodeStore (org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore)32 Test (org.junit.Test)13 DocumentMK (org.apache.jackrabbit.oak.plugins.document.DocumentMK)12 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)8 Closer (com.google.common.io.Closer)6 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)6 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)5 MongoClientURI (com.mongodb.MongoClientURI)4 RepositoryException (javax.jcr.RepositoryException)4 Session (javax.jcr.Session)4 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)4 MongoClient (com.mongodb.MongoClient)3 Node (javax.jcr.Node)3 OptionParser (joptsimple.OptionParser)3 OptionSet (joptsimple.OptionSet)3 DocumentStore (org.apache.jackrabbit.oak.plugins.document.DocumentStore)3 AssumptionViolatedException (org.junit.AssumptionViolatedException)3 DB (com.mongodb.DB)2 File (java.io.File)2 UnknownHostException (java.net.UnknownHostException)2