Search in sources :

Example 21 with DocumentNodeStore

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

the class JournalIT method simpleCacheInvalidationTest.

@Test
public void simpleCacheInvalidationTest() throws Exception {
    final DocumentNodeStore ns1 = createMK(1, 0).getNodeStore();
    final DocumentNodeStore ns2 = createMK(2, 0).getNodeStore();
    // invalidate cache under test first
    ns1.getDocumentStore().invalidateCache();
    // first create child node in instance 1
    getOrCreate(ns1, "/child", true);
    assertDocCache(ns1, true, "/child");
    {
        // modify /child in another instance 2
        // read latest changes from ns1
        ns2.runBackgroundOperations();
        setProperty(ns2, "/child", "p", "ns2" + System.currentTimeMillis(), true);
    }
    // that should not have changed the fact that we have it cached in 'ns'
    assertDocCache(ns1, true, "/child");
    // doing a backgroundOp now should trigger invalidation
    // which thx to the external modification will remove the entry from the cache:
    ns1.runBackgroundOperations();
    assertDocCache(ns1, false, "/child");
    // when I access it again with 'ns', then it gets cached again:
    getOrCreate(ns1, "/child", false);
    assertDocCache(ns1, true, "/child");
}
Also used : DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) Test(org.junit.Test) AbstractJournalTest(org.apache.jackrabbit.oak.plugins.document.AbstractJournalTest)

Example 22 with DocumentNodeStore

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

the class AsyncIndexUpdateClusterTestIT method create.

private DocumentNodeStore create(int clusterId) {
    DocumentMK.Builder builder = new DocumentMK.Builder();
    if (ds == null) {
        ds = new MemoryDocumentStore();
    }
    if (bs == null) {
        bs = new MemoryBlobStore();
    }
    builder.setDocumentStore(ds).setBlobStore(bs);
    DocumentNodeStore store = builder.setClusterId(++clusterId).setLeaseCheck(false).open().getNodeStore();
    return store;
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) DocumentMK(org.apache.jackrabbit.oak.plugins.document.DocumentMK) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) MemoryBlobStore(org.apache.jackrabbit.oak.spi.blob.MemoryBlobStore)

Example 23 with DocumentNodeStore

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

the class NonLocalObservationIT method getFixture.

@Override
protected NodeStoreFixture getFixture() {
    /**
         * Fixes the cluster use case plus allowing to control the cache sizes.
         * In theory other users of DocumentMongoFixture might have similar 
         * test cases - but keeping it simple for now - thus going via subclass.
         */
    return new DocumentMongoFixture() {

        private String clusterSuffix = System.currentTimeMillis() + "-NonLocalObservationIT";

        private DB db;

        /** keep a reference to the node stores so that the db only gets closed after the last nodeStore was closed */
        private Set<NodeStore> nodeStores = new HashSet<NodeStore>();

        /**
             * This is not implemented in the super class at all.
             * <ul>
             *  <li>use a specific suffix to make sure we have our own, new db and clean it up after the test</li>
             *  <li>properly drop that db created above in dispose</li>
             *  <li>use only 32MB (vs default of 256MB) memory to ensure we're not going OOM just because of this (which happens with the default)</li>
             *  <li>disable the persistent cache for the same reason</li>
             * </ul>
             */
        @Override
        public NodeStore createNodeStore(int clusterNodeId) {
            try {
                DocumentMK.Builder builder = new DocumentMK.Builder();
                // keep this one low to avoid OOME
                builder.memoryCacheSize(32 * 1024 * 1024);
                // turn this one off to avoid OOME
                builder.setPersistentCache(null);
                final String suffix = clusterSuffix;
                // db will be overwritten - but that's fine
                db = getDb(suffix);
                builder.setMongoDB(db);
                DocumentNodeStore ns = builder.getNodeStore();
                nodeStores.add(ns);
                return ns;
            } catch (Exception e) {
                throw new AssumptionViolatedException("Mongo instance is not available", e);
            }
        }

        @Override
        public void dispose(NodeStore nodeStore) {
            super.dispose(nodeStore);
            nodeStores.remove(nodeStore);
            if (db != null && nodeStores.size() == 0) {
                try {
                    db.dropDatabase();
                    db.getMongo().close();
                    db = null;
                } catch (Exception e) {
                    log.error("dispose: Can't close Mongo", e);
                }
            }
        }

        @Override
        public String toString() {
            return "NonLocalObservationIT's DocumentMongoFixture flavour";
        }
    };
}
Also used : DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) HashSet(java.util.HashSet) Set(java.util.Set) AssumptionViolatedException(org.junit.AssumptionViolatedException) DocumentMongoFixture(org.apache.jackrabbit.oak.fixture.DocumentMongoFixture) DocumentMK(org.apache.jackrabbit.oak.plugins.document.DocumentMK) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) DB(com.mongodb.DB) RepositoryException(javax.jcr.RepositoryException) AssumptionViolatedException(org.junit.AssumptionViolatedException)

Example 24 with DocumentNodeStore

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

the class AtomicCounterIT method setup.

@Before
public void setup() throws Exception {
    DocumentNodeStore ns = builderProvider.newBuilder().getNodeStore();
    NodeBuilder builder = ns.getRoot().builder();
    NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME);
    NodeBuilder lucene = newLuceneIndexDefinition(index, "lucene", ImmutableSet.of("String"), null, "async");
    lucene.setProperty("async", of("async", "nrt"), STRINGS);
    IndexDefinition.updateDefinition(index.child("lucene"));
    ns.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    LuceneIndexEditorProvider editorProvider = new LuceneIndexEditorProvider();
    editorProvider.setIndexingQueue(mock(DocumentQueue.class));
    LuceneIndexProvider provider = new LuceneIndexProvider();
    ContentRepository repository = new Oak(ns).with(// Clusterable
    ns).with(new OpenSecurityProvider()).with((QueryIndexProvider) provider).with((Observer) provider).with(editorProvider).with(executorService).withAtomicCounter().withAsyncIndexing("async", 1).withFailOnMissingIndexProvider().createContentRepository();
    session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()), null);
    while (isReindexing(session)) {
        Thread.sleep(100);
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) LuceneIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexEditorProvider) ContentRepository(org.apache.jackrabbit.oak.api.ContentRepository) Oak(org.apache.jackrabbit.oak.Oak) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) DocumentQueue(org.apache.jackrabbit.oak.plugins.index.lucene.hybrid.DocumentQueue) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider) LuceneIndexProvider(org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexProvider) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) QueryIndexProvider(org.apache.jackrabbit.oak.spi.query.QueryIndexProvider) Before(org.junit.Before)

Example 25 with DocumentNodeStore

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

the class SameNodeSiblingsTest method snsNewNameAlreadyExists.

@Test
public void snsNewNameAlreadyExists() 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("child_2_", "nt:folder");
            parent.addNode("child_3_", "nt:folder");
            parent.addNode("child_3_2", "nt:folder");
            session.save();
            parent.setPrimaryType("nt:folder");
            session.save();
        }
    });
    try {
        NodeState parent = nodeStore.getRoot().getChildNode("parent");
        Set<String> children = newHashSet(parent.getChildNodeNames());
        assertEquals(of("child", "child_2_", "child_3_", "child_2_2", "child_3_2", "child_3_3"), 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)

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