Search in sources :

Example 1 with DocumentStore

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

the class MongoCacheConsistencyTest method getFixture.

@Override
public DocumentStoreFixture getFixture() throws Exception {
    Fongo fongo = new OakFongo("fongo") {

        private String suppressedEx = null;

        @Override
        protected void afterInsert(WriteResult result) {
            maybeThrow();
        }

        @Override
        protected void afterFindAndModify(DBObject result) {
            maybeThrow();
        }

        @Override
        protected void afterUpdate(WriteResult result) {
            maybeThrow();
        }

        @Override
        protected void afterRemove(WriteResult result) {
            maybeThrow();
        }

        @Override
        protected void beforeExecuteBulkWriteOperation(boolean ordered, Boolean bypassDocumentValidation, List<?> writeRequests, WriteConcern aWriteConcern) {
            // suppress potentially set exception message because
            // fongo bulk writes call other update methods
            suppressedEx = exceptionMsg;
            exceptionMsg = null;
        }

        @Override
        protected void afterExecuteBulkWriteOperation(BulkWriteResult result) {
            exceptionMsg = suppressedEx;
            suppressedEx = null;
            maybeThrow();
        }

        private void maybeThrow() {
            if (exceptionMsg != null) {
                throw new MongoException(exceptionMsg);
            }
        }
    };
    DocumentMK.Builder builder = provider.newBuilder().setAsyncDelay(0);
    final DocumentStore store = new MongoDocumentStore(fongo.getDB("oak"), builder);
    return new DocumentStoreFixture() {

        @Override
        public String getName() {
            return "MongoDB";
        }

        @Override
        public DocumentStore createDocumentStore(int clusterId) {
            return store;
        }
    };
}
Also used : Fongo(com.github.fakemongo.Fongo) OakFongo(com.mongodb.OakFongo) MongoException(com.mongodb.MongoException) DocumentMK(org.apache.jackrabbit.oak.plugins.document.DocumentMK) OakFongo(com.mongodb.OakFongo) DBObject(com.mongodb.DBObject) BulkWriteResult(com.mongodb.BulkWriteResult) DocumentStore(org.apache.jackrabbit.oak.plugins.document.DocumentStore) WriteResult(com.mongodb.WriteResult) BulkWriteResult(com.mongodb.BulkWriteResult) DocumentStoreFixture(org.apache.jackrabbit.oak.plugins.document.DocumentStoreFixture) WriteConcern(com.mongodb.WriteConcern) List(java.util.List)

Example 2 with DocumentStore

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

the class JournalIT method cacheInvalidationTest.

@Test
public void cacheInvalidationTest() throws Exception {
    final DocumentNodeStore ns1 = createMK(1, 0).getNodeStore();
    final DocumentNodeStore ns2 = createMK(2, 0).getNodeStore();
    LOG.info("cache size 1: " + getCacheElementCount(ns1.getDocumentStore()));
    // invalidate cache under test first
    ns1.getDocumentStore().invalidateCache();
    {
        DocumentStore s = ns1.getDocumentStore();
        LOG.info("m.size=" + getCacheElementCount(s));
    }
    LOG.info("cache size 2: " + getCacheElementCount(ns1.getDocumentStore()));
    // first create child node in instance 1
    final List<String> paths = createRandomPaths(1, 5000000, 1000);
    int i = 0;
    for (String path : paths) {
        if (i++ % 100 == 0) {
            LOG.info("at " + i);
        }
        getOrCreate(ns1, path, false);
    }
    final List<String> paths2 = createRandomPaths(20, 2345, 100);
    getOrCreate(ns1, paths2, false);
    ns1.runBackgroundOperations();
    for (String path : paths) {
        assertDocCache(ns1, true, path);
    }
    {
        DocumentStore s = ns1.getDocumentStore();
        LOG.info("m.size=" + getCacheElementCount(s));
    }
    LOG.info("cache size 2: " + getCacheElementCount(ns1.getDocumentStore()));
    long time = System.currentTimeMillis();
    for (int j = 0; j < 100; j++) {
        long now = System.currentTimeMillis();
        LOG.info("loop " + j + ", " + (now - time) + "ms");
        time = now;
        final Set<String> electedPaths = choose(paths2, random.nextInt(30));
        {
            // choose a random few from above created paths and modify them
            final long t1 = System.currentTimeMillis();
            // make sure ns2 has the latest from ns1
            ns2.runBackgroundOperations();
            final long t2 = System.currentTimeMillis();
            LOG.info("ns2 background took " + (t2 - t1) + "ms");
            for (String electedPath : electedPaths) {
                // modify /child in another instance 2
                setProperty(ns2, electedPath, "p", "ns2" + System.currentTimeMillis(), false);
            }
            final long t3 = System.currentTimeMillis();
            LOG.info("setting props " + (t3 - t2) + "ms");
            ns2.runBackgroundOperations();
            final long t4 = System.currentTimeMillis();
            LOG.info("ns2 background took2 " + (t4 - t3) + "ms");
        }
        // that should not have changed the fact that we have it cached in 'ns1'
        for (String electedPath : electedPaths) {
            assertDocCache(ns1, true, electedPath);
        }
        // doing a backgroundOp now should trigger invalidation
        // which thx to the external modification will remove the entry from the cache:
        ns1.runBackgroundOperations();
        for (String electedPath : electedPaths) {
            assertDocCache(ns1, false, electedPath);
        }
        // when I access it again with 'ns1', then it gets cached again:
        for (String electedPath : electedPaths) {
            getOrCreate(ns1, electedPath, false);
            assertDocCache(ns1, true, electedPath);
        }
    }
}
Also used : DocumentStore(org.apache.jackrabbit.oak.plugins.document.DocumentStore) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) Test(org.junit.Test) AbstractJournalTest(org.apache.jackrabbit.oak.plugins.document.AbstractJournalTest)

Example 3 with DocumentStore

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

the class ReadOnlyDocumentStoreWrapperTest method testPassthrough.

@Test
public void testPassthrough() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    final List<String> disallowedMethods = Lists.newArrayList("create", "update", "remove", "createOrUpdate", "findAndUpdate");
    InvocationHandler handler = new InvocationHandler() {

        @Override
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            String methodName = method.getName();
            if (disallowedMethods.contains(methodName)) {
                Assert.fail(String.format("Invalid passthrough of method (%s) with params %s", method, Arrays.toString(args)));
            }
            if ("determineServerTimeDifferenceMillis".equals(methodName)) {
                return new Long(0);
            } else {
                return null;
            }
        }
    };
    DocumentStore proxyStore = (DocumentStore) Proxy.newProxyInstance(DocumentStore.class.getClassLoader(), new Class[] { DocumentStore.class }, handler);
    DocumentStore readOnlyStore = ReadOnlyDocumentStoreWrapperFactory.getInstance(proxyStore);
    Collection<? extends Document>[] collections = new Collection[] { Collection.CLUSTER_NODES, Collection.JOURNAL, Collection.NODES, Collection.SETTINGS };
    for (Collection collection : collections) {
        readOnlyStore.find(collection, null);
        readOnlyStore.find(collection, null, 0);
        readOnlyStore.query(collection, null, null, 0);
        readOnlyStore.query(collection, null, null, null, 0, 0);
        boolean uoeThrown = false;
        try {
            readOnlyStore.remove(collection, "");
        } catch (UnsupportedOperationException uoe) {
            //catch uoe thrown by read only wrapper
            uoeThrown = true;
        }
        assertTrue("remove must throw UnsupportedOperationException", uoeThrown);
        uoeThrown = false;
        try {
            readOnlyStore.remove(collection, Lists.<String>newArrayList());
        } catch (UnsupportedOperationException uoe) {
            //catch uoe thrown by read only wrapper
            uoeThrown = true;
        }
        assertTrue("remove must throw UnsupportedOperationException", uoeThrown);
        uoeThrown = false;
        try {
            readOnlyStore.remove(collection, Maps.<String, Map<UpdateOp.Key, UpdateOp.Condition>>newHashMap());
        } catch (UnsupportedOperationException uoe) {
            //catch uoe thrown by read only wrapper
            uoeThrown = true;
        }
        assertTrue("remove must throw UnsupportedOperationException", uoeThrown);
        uoeThrown = false;
        try {
            readOnlyStore.create(collection, null);
        } catch (UnsupportedOperationException uoe) {
            //catch uoe thrown by read only wrapper
            uoeThrown = true;
        }
        assertTrue("create must throw UnsupportedOperationException", uoeThrown);
        uoeThrown = false;
        try {
            readOnlyStore.update(collection, null, null);
        } catch (UnsupportedOperationException uoe) {
            //catch uoe thrown by read only wrapper
            uoeThrown = true;
        }
        assertTrue("update must throw UnsupportedOperationException", uoeThrown);
        uoeThrown = false;
        try {
            readOnlyStore.createOrUpdate(collection, (UpdateOp) null);
        } catch (UnsupportedOperationException uoe) {
            //catch uoe thrown by read only wrapper
            uoeThrown = true;
        }
        assertTrue("createOrUpdate must throw UnsupportedOperationException", uoeThrown);
        uoeThrown = false;
        try {
            readOnlyStore.createOrUpdate(collection, Lists.<UpdateOp>newArrayList());
        } catch (UnsupportedOperationException uoe) {
            //catch uoe thrown by read only wrapper
            uoeThrown = true;
        }
        assertTrue("createOrUpdate must throw UnsupportedOperationException", uoeThrown);
        uoeThrown = false;
        try {
            readOnlyStore.findAndUpdate(collection, null);
        } catch (UnsupportedOperationException uoe) {
            //catch uoe thrown by read only wrapper
            uoeThrown = true;
        }
        assertTrue("findAndUpdate must throw UnsupportedOperationException", uoeThrown);
        readOnlyStore.invalidateCache(collection, null);
        readOnlyStore.getIfCached(collection, null);
    }
    readOnlyStore.invalidateCache();
    readOnlyStore.invalidateCache(null);
    readOnlyStore.dispose();
    readOnlyStore.setReadWriteMode(null);
    readOnlyStore.getCacheStats();
    readOnlyStore.getMetadata();
    readOnlyStore.determineServerTimeDifferenceMillis();
}
Also used : Method(java.lang.reflect.Method) Document(org.apache.jackrabbit.oak.plugins.document.Document) InvocationHandler(java.lang.reflect.InvocationHandler) DocumentStore(org.apache.jackrabbit.oak.plugins.document.DocumentStore) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) Collection(org.apache.jackrabbit.oak.plugins.document.Collection) Test(org.junit.Test)

Example 4 with DocumentStore

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

the class TimingDocumentStoreWrapperTest method createOrUpdate.

@Test
public void createOrUpdate() {
    DocumentStore store = new TimingDocumentStoreWrapper(new MemoryDocumentStore());
    UpdateOp op = new UpdateOp("foo", true);
    store.createOrUpdate(Collection.NODES, Collections.singletonList(op));
}
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) UpdateOp(org.apache.jackrabbit.oak.plugins.document.UpdateOp) Test(org.junit.Test)

Example 5 with DocumentStore

use of org.apache.jackrabbit.oak.plugins.document.DocumentStore 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)

Aggregations

DocumentStore (org.apache.jackrabbit.oak.plugins.document.DocumentStore)9 DocumentMK (org.apache.jackrabbit.oak.plugins.document.DocumentMK)5 Test (org.junit.Test)5 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)4 DocumentNodeStore (org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore)3 MongoConnection (org.apache.jackrabbit.oak.plugins.document.util.MongoConnection)3 UpdateOp (org.apache.jackrabbit.oak.plugins.document.UpdateOp)2 MongoDocumentStore (org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore)2 Fongo (com.github.fakemongo.Fongo)1 BulkWriteResult (com.mongodb.BulkWriteResult)1 DBObject (com.mongodb.DBObject)1 MongoClientURI (com.mongodb.MongoClientURI)1 MongoException (com.mongodb.MongoException)1 OakFongo (com.mongodb.OakFongo)1 WriteConcern (com.mongodb.WriteConcern)1 WriteResult (com.mongodb.WriteResult)1 InvocationHandler (java.lang.reflect.InvocationHandler)1 Method (java.lang.reflect.Method)1 List (java.util.List)1 DataSource (javax.sql.DataSource)1