Search in sources :

Example 16 with DocumentNodeStore

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

the class MongoFactory method create.

@Override
public NodeStore create(BlobStore blobStore, Closer closer) throws IOException {
    System.setProperty(DocumentNodeStore.SYS_PROP_DISABLE_JOURNAL, "true");
    DocumentMK.Builder builder = getBuilder(cacheSize);
    builder.setMongoDB(getDB(closer));
    if (blobStore != null) {
        builder.setBlobStore(blobStore);
    }
    if (readOnly) {
        builder.setReadOnlyMode();
    }
    DocumentNodeStore documentNodeStore = builder.getNodeStore();
    // TODO probably we should disable all observers, see OAK-5651
    documentNodeStore.getBundlingConfigHandler().unregisterObserver();
    closer.register(asCloseable(documentNodeStore));
    return documentNodeStore;
}
Also used : DocumentMK(org.apache.jackrabbit.oak.plugins.document.DocumentMK) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore)

Example 17 with DocumentNodeStore

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

the class ClusterRepositoryInfoTest method checkCustomId.

// below test doesn't make sense anymore in the context
// of getOrCreateId (OAK-4006) where that never returns null
//    @Test
//    public void checkGetIdWhenNotRegistered() {
//        MemoryDocumentStore store = new MemoryDocumentStore();
//        DocumentNodeStore ds1 = builderProvider.newBuilder()
//            .setAsyncDelay(0)
//            .setDocumentStore(store)
//            .setClusterId(1)
//            .getNodeStore();
//        // Should be null and no NPE
//        String id = ClusterRepositoryInfo.getOrCreateId(ds1);
//        Assert.assertNull(id);
//    }
@Test
public void checkCustomId() throws Exception {
    MemoryDocumentStore store = new MemoryDocumentStore();
    DocumentNodeStore ds1 = builderProvider.newBuilder().setAsyncDelay(0).setDocumentStore(store).setClusterId(1).getNodeStore();
    String repoId1 = "yyyyyyy";
    setId(ds1, repoId1);
    ds1.runBackgroundOperations();
    String id = ClusterRepositoryInfo.getOrCreateId(ds1);
    Assert.assertEquals(id, repoId1);
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) Test(org.junit.Test)

Example 18 with DocumentNodeStore

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

the class ClusterRepositoryInfoTest method sameCluster.

@Test
public void sameCluster() throws Exception {
    MemoryDocumentStore store = new MemoryDocumentStore();
    DocumentNodeStore ds1 = builderProvider.newBuilder().setAsyncDelay(0).setDocumentStore(store).setClusterId(1).setBlobStore(blobStore).getNodeStore();
    String repoId1 = ClusterRepositoryInfo.getOrCreateId(ds1);
    ds1.runBackgroundOperations();
    DocumentNodeStore ds2 = builderProvider.newBuilder().setAsyncDelay(0).setDocumentStore(store).setClusterId(2).setBlobStore(blobStore).getNodeStore();
    String repoId2 = ClusterRepositoryInfo.getOrCreateId(ds2);
    // Since the same cluster the ids should be equal
    Assert.assertEquals(repoId1, repoId2);
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) Test(org.junit.Test)

Example 19 with DocumentNodeStore

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

the class DocumentMongoFixture method createNodeStore.

@Override
public NodeStore createNodeStore() {
    try {
        String suffix = String.format("-%d-%d", System.currentTimeMillis(), sequence.incrementAndGet());
        DocumentMK.Builder builder = new DocumentMK.Builder();
        if (blobStore != null) {
            builder.setBlobStore(blobStore);
        }
        builder.setPersistentCache("target/persistentCache,time");
        builder.setMongoDB(getDb(suffix));
        DocumentNodeStore ns = builder.getNodeStore();
        suffixes.put(ns, suffix);
        return ns;
    } catch (Exception e) {
        throw new AssumptionViolatedException("Mongo instance is not available", e);
    }
}
Also used : AssumptionViolatedException(org.junit.AssumptionViolatedException) DocumentMK(org.apache.jackrabbit.oak.plugins.document.DocumentMK) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) AssumptionViolatedException(org.junit.AssumptionViolatedException) UnknownHostException(java.net.UnknownHostException)

Example 20 with DocumentNodeStore

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

the class DocumentMongoFixture method dispose.

@Override
public void dispose(NodeStore nodeStore) {
    if (nodeStore instanceof DocumentNodeStore) {
        ((DocumentNodeStore) nodeStore).dispose();
    }
    if (nodeStore == null) {
        return;
    }
    String suffix = suffixes.remove(nodeStore);
    if (suffix != null) {
        try {
            DB db = getDb(suffix);
            db.dropDatabase();
            db.getMongo().close();
        } catch (Exception e) {
            log.error("Can't close Mongo", e);
        }
    }
}
Also used : DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) DB(com.mongodb.DB) AssumptionViolatedException(org.junit.AssumptionViolatedException) UnknownHostException(java.net.UnknownHostException)

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