LockFactory { public ReadWriteLock newReadWriteLock() { return newReadWriteLock(getDefaultPrefix()); } @Inject  LockFactory(Configuration config); Lock newLock(); Lock newLock(String label); ReadWriteLock newReadWriteLock(); ReadWriteLock newReadWriteLock(String label); void debugDump(StringBuilder sb);  }
@Test public void createsRegularReadWriteLockIfDebugIsDisabled() { Configuration config = createNiceMock(Configuration.class); expect(config.isServerLocksProfilingEnabled()).andReturn(false); replayAll(); LockFactory factory = new LockFactory(config); ReadWriteLock lock = factory.newReadWriteLock(); Assert.assertTrue(lock instanceof ReentrantReadWriteLock); verifyAll(); }
@Test public void createsProfiledReadWriteLockIfProfilingIsEnabled() { Configuration config = createNiceMock(Configuration.class); expect(config.isServerLocksProfilingEnabled()).andReturn(true); replayAll(); LockFactory factory = new LockFactory(config); ReadWriteLock lock = factory.newReadWriteLock(); Assert.assertTrue(lock instanceof ProfiledReentrantReadWriteLock); String readLockLabel = ((ProfiledReentrantReadWriteLock) lock).readLock().getLabel(); Assert.assertTrue(readLockLabel, readLockLabel.contains("LockFactoryTest.java")); String writeLockLabel = ((ProfiledReentrantReadWriteLock) lock).writeLock().getLabel(); Assert.assertTrue(writeLockLabel, writeLockLabel.contains("LockFactoryTest.java")); verifyAll(); }