ReentrantReadWriteUpdateLock implements ReadWriteUpdateLock { @Override public Lock updateLock() { return updateLock; }  @Override Lock updateLock(); @Override Lock readLock(); @Override Lock writeLock();  }
@Test public void testUpdateLockIsExclusive() throws Exception { assertTrue(executor1.submit(new TryLockTask(reentrantReadWriteUpdateLock.updateLock())).get()); assertFalse(executor2.submit(new TryLockTask(reentrantReadWriteUpdateLock.updateLock())).get()); assertTrue(executor1.submit(new UnlockTask(reentrantReadWriteUpdateLock.updateLock())).get()); assertTrue(executor2.submit(new TryLockTask(reentrantReadWriteUpdateLock.updateLock())).get()); assertTrue(executor2.submit(new UnlockTask(reentrantReadWriteUpdateLock.updateLock())).get()); }
@Test public void testUpdateLockHoldCount() throws Exception { reentrantReadWriteUpdateLock.updateLock().lock(); int hc1 = ((ReentrantReadWriteUpdateLock.UpdateLock)reentrantReadWriteUpdateLock.updateLock()).holdCount().value; reentrantReadWriteUpdateLock.updateLock().unlock(); int hc2 = ((ReentrantReadWriteUpdateLock.UpdateLock)reentrantReadWriteUpdateLock.updateLock()).holdCount().value; assertEquals(1, hc1); assertEquals(0, hc2); }
@Test public void testUpdateLockHoldCount_Interruptibly() throws Exception { reentrantReadWriteUpdateLock.updateLock().lockInterruptibly(); int hc1 = ((ReentrantReadWriteUpdateLock.UpdateLock)reentrantReadWriteUpdateLock.updateLock()).holdCount().value; reentrantReadWriteUpdateLock.updateLock().unlock(); int hc2 = ((ReentrantReadWriteUpdateLock.UpdateLock)reentrantReadWriteUpdateLock.updateLock()).holdCount().value; assertEquals(1, hc1); assertEquals(0, hc2); }
@Test(expected = UnsupportedOperationException.class) public void testUpdateLockNewCondition() throws Exception { reentrantReadWriteUpdateLock.updateLock().newCondition(); }