You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-dev@jackrabbit.apache.org by Chetan Mehrotra <ch...@gmail.com> on 2014/06/17 15:12:15 UTC

Re: svn commit: r1603155 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java test/java/org/apache/jackrabbit/oak/plugins/document/CacheConsistencyTest.java

On Tue, Jun 17, 2014 at 6:33 PM,  <mr...@apache.org> wrote:
> +    @Ignore("OAK-1897")
> +    @Test
> +    public void cacheConsistency() throws Exception {
> +        mk.commit("/", "+\"node\":{}", null, null);
> +        // add a child node. this will require an update
> +        // of _lastRev on /node
> +        mk.commit("/node", "+\"child\":{}", null, null);
> +
> +        // make sure the document is not cached
> +        store.invalidateCache(NODES, Utils.getIdFromPath("/node"));
> +
> +        Thread t = new Thread(new Runnable() {
> +            @Override
> +            public void run() {
> +                store.query(NODES,
> +                        Utils.getKeyLowerLimit("/"),
> +                        Utils.getKeyUpperLimit("/"), 10);
> +            }
> +        });
> +        // block thread when it tries to convert db objects
> +        store.semaphores.put(t, new Semaphore(0));
> +        t.start();
> +
> +        while (!store.semaphores.get(t).hasQueuedThreads()) {
> +            Thread.sleep(10);
> +        }
> +
> +        // trigger write back of _lastRevs
> +        mk.runBackgroundOperations();
> +
> +        // release thread
> +        store.semaphores.get(t).release();
> +        t.join();
> +
> +        NodeState root = mk.getNodeStore().getRoot();
> +        assertTrue(root.getChildNode("node").getChildNode("child").exists());
> +    }
> +
> +    private static final class TestStore extends MongoDocumentStore {
> +
> +        final Map<Thread, Semaphore> semaphores = Maps.newConcurrentMap();
> +
> +        TestStore(DB db, DocumentMK.Builder builder) {
> +            super(db, builder);
> +        }
> +
> +        @Override
> +        protected <T extends Document> T convertFromDBObject(
> +                @Nonnull Collection<T> collection, @Nullable DBObject n) {
> +            Semaphore s = semaphores.get(Thread.currentThread());
> +            if (s != null) {
> +                s.acquireUninterruptibly();
> +            }
> +            try {
> +                return super.convertFromDBObject(collection, n);
> +            } finally {
> +                if (s != null) {
> +                    s.release();
> +                }
> +            }
> +        }
> +    }
> +
> +}

Interesting test approach Marcel!!

Chetan Mehrotra