Index: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdate.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdate.java (revision 1718599) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdate.java (working copy) @@ -502,7 +502,8 @@ throws CommitFailedException { // check for concurrent updates by this async task NodeState async = before.getChildNode(ASYNC); - if (checkpoint == null || Objects.equal(checkpoint, async.getString(name)) + if ((checkpoint == null || Objects.equal(checkpoint, + async.getString(name))) && lease == async.getLong(leasify(name))) { return after; } else { Index: oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdateLeaseTest.java =================================================================== --- oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdateLeaseTest.java (revision 1718599) +++ oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdateLeaseTest.java (working copy) @@ -239,7 +239,6 @@ @Test public void testPrePrepareRexindex() throws Exception { - final IndexStatusListener l1 = new IndexStatusListener() { @Override @@ -293,6 +292,66 @@ assertRunOk(new SpecialAsyncIndexUpdate(name, store, provider, l1)); } + @Test + public void testPostPrepareReindexLeaseExpired() throws Exception { + final long lease = 50; + final IndexStatusListener l1 = new IndexStatusListener() { + + @Override + protected void postPrepare() { + executed.set(true); + try { + TimeUnit.MILLISECONDS.sleep(lease * 3); + } catch (InterruptedException e) { + // + } + assertRunOk(new AsyncIndexUpdate(name, store, provider)); + } + }; + assertRunKo(new SpecialAsyncIndexUpdate(name, store, provider, l1) + .setLeaseTimeOut(lease)); + } + + @Test + public void testPreIndexUpdateReindexLeaseExpired() throws Exception { + final long lease = 50; + final IndexStatusListener l1 = new IndexStatusListener() { + + @Override + protected void preIndexUpdate() { + executed.set(true); + try { + TimeUnit.MILLISECONDS.sleep(lease * 3); + } catch (InterruptedException e) { + // + } + assertRunOk(new AsyncIndexUpdate(name, store, provider)); + } + }; + assertRunKo(new SpecialAsyncIndexUpdate(name, store, provider, l1) + .setLeaseTimeOut(lease)); + } + + @Test + public void testPostIndexUpdateReindexLeaseExpired() throws Exception { + final long lease = 50; + final IndexStatusListener l1 = new IndexStatusListener() { + + @Override + protected void postIndexUpdate() { + executed.set(true); + try { + TimeUnit.MILLISECONDS.sleep(lease * 3); + } catch (InterruptedException e) { + // + } + assertRunOk(new AsyncIndexUpdate(name, store, provider)); + } + }; + assertRunKo(new SpecialAsyncIndexUpdate(name, store, provider, l1) + .setLeaseTimeOut(lease)); + } + // ------------------------------------------------------------------- private static String getReferenceCp(NodeStore store, String name) { @@ -309,9 +368,9 @@ assertConcurrentUpdate(a.getIndexStats()); } - private void assertRun(AsyncIndexUpdate a, boolean status) { + private void assertRun(AsyncIndexUpdate a, boolean failing) { a.run(); - assertEquals("Unexpected failiure flag", status, a.isFailing()); + assertEquals("Unexpected failiure flag", failing, a.isFailing()); } private void assertConcurrentUpdate(AsyncIndexStats stats) {