ProfiledReentrantReadWriteLock implements ReadWriteLock { @Override public ProfiledLock readLock() { return readLock; } ProfiledReentrantReadWriteLock(ReentrantReadWriteLock delegate, Ticker ticker, String label); @Override ProfiledLock readLock(); @Override ProfiledLock writeLock();  }
@Test public void lockingReadLockOnlyLocksReadLock() { ReentrantReadWriteLock delegate = new ReentrantReadWriteLock(); ProfiledReentrantReadWriteLock testSubject = new ProfiledReentrantReadWriteLock(delegate, Ticker.systemTicker(), LABEL); testSubject.readLock().lock(); Assert.assertEquals(1, delegate.getReadHoldCount()); Assert.assertEquals(0, delegate.getWriteHoldCount()); }
@Test public void timeWaitingForReadLockIsRecorded() { Ticker ticker = createMock(Ticker.class); ProfiledLock testSubject = new ProfiledReentrantReadWriteLock(new ReentrantReadWriteLock(), ticker, LABEL).readLock(); timeWaitingForLockIsRecorded(testSubject, ticker); }
@Test public void timeReadLockSpentLockedIsRecorded() { Ticker ticker = createMock(Ticker.class); ProfiledLock testSubject = new ProfiledReentrantReadWriteLock(new ReentrantReadWriteLock(), ticker, LABEL).readLock(); timeSpentLockedIsRecorded(ticker, testSubject); }
@Test public void onlyOutermostLockUnlockIsProfiledForReadLock() { Ticker ticker = createMock(Ticker.class); ProfiledLock testSubject = new ProfiledReentrantReadWriteLock(new ReentrantReadWriteLock(), ticker, LABEL).readLock(); onlyOutermostLockUnlockIsProfiled(testSubject, ticker); }
@Test public void onlyOutermostLockUnlockIsProfiledForWriteLock() { Ticker ticker = createMock(Ticker.class); ProfiledLock testSubject = new ProfiledReentrantReadWriteLock(new ReentrantReadWriteLock(), ticker, LABEL).readLock(); onlyOutermostLockUnlockIsProfiled(testSubject, ticker); }