Search in sources :

Example 26 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 27 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 28 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 29 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)

Example 30 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)

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