On Tue, Jun 17, 2014 at 6:33 PM, <mreut...@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