@Test public void testLockServiceDoesNotEvictLocksThatAreBeingUsedEvenWithSomeDelay() { final AtomicBoolean wait0 = new AtomicBoolean(true); final AtomicBoolean wait1 = new AtomicBoolean(true); final AtomicBoolean done = new AtomicBoolean(false); final AtomicBoolean failed = new AtomicBoolean(false); Thread t1 = new Thread(new Runnable() { @Override public void run() { try { ReadLock readLock = lockService.getReadLock("foo", 1); readLock.lock(); wait0.set(false); while (wait1.get()) { continue; } Thread.sleep(TestData.getScaleCount() * 4); readLock.unlock(); } catch (IllegalMonitorStateException e) { failed.set(true); e.printStackTrace(); } catch (InterruptedException e) { throw CheckedExceptions.wrapAsRuntimeException(e); } finally { done.set(true); } } }); Thread t2 = new Thread(new Runnable() { @Override public void run() { while (wait0.get()) { continue; } ReadLock readLock = lockService.getReadLock("foo", 1); readLock.lock(); readLock.unlock(); wait1.set(false); } }); t1.start(); t2.start(); while (!done.get()) { continue; } Assert.assertFalse(failed.get()); }
public ReadLock getReadLock(Object... objects) { return getReadLock(Token.wrap(objects)); }
LockService extends AbstractLockService<Token, TokenReadWriteLock> { public ReadLock getReadLock(Object... objects) { return getReadLock(Token.wrap(objects)); } }
LockService extends AbstractLockService<Token, TokenReadWriteLock> { public ReadLock getReadLock(Object... objects) { return getReadLock(Token.wrap(objects)); } private  LockService(); private  LockService(ConcurrentHashMap<Token, TokenReadWriteLock> locks); }
LockService extends AbstractLockService<Token, TokenReadWriteLock> { public ReadLock getReadLock(Object... objects) { return getReadLock(Token.wrap(objects)); } private  LockService(); private  LockService(ConcurrentHashMap<Token, TokenReadWriteLock> locks); static LockService create(); static LockService noOp(); ReadLock getReadLock(Object... objects); WriteLock getWriteLock(Object... objects); }
LockService extends AbstractLockService<Token, TokenReadWriteLock> { public ReadLock getReadLock(Object... objects) { return getReadLock(Token.wrap(objects)); } private  LockService(); private  LockService(ConcurrentHashMap<Token, TokenReadWriteLock> locks); static LockService create(); static LockService noOp(); ReadLock getReadLock(Object... objects); WriteLock getWriteLock(Object... objects);  }