@Test public void testLockServiceDoesNotEvictLocksThatAreBeingUsedWithHighConcurrencyAndDifferentActions() throws InterruptedException { int clients = TestData.getScaleCount(); final AtomicBoolean done = new AtomicBoolean(false); final AtomicBoolean failed = new AtomicBoolean(false); final Set<String> keys = Sets.newHashSet(); while (keys.size() < clients) { keys.add(TestData.getString()); } final Set<Long> records = Sets.newHashSet(); while (records.size() < clients) { records.add(TestData.getLong()); } Runnable r = new Runnable() { @Override public void run() { while (!done.get()) { try { String key = TCollections.getRandomElement(keys); long record = TCollections.getRandomElement(records); ReadLock readLock = lockService.getReadLock(key, record); readLock.lock(); readLock.unlock(); } catch (IllegalMonitorStateException e) { e.printStackTrace(); done.set(true); failed.set(true); } } } }; for (int i = 0; i < clients; i++) { new Thread(r).start(); } Thread.sleep(TestData.getScaleCount() * 10); done.set(true); 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);  }