CachedLack extends Lack { @Override public void acquire(String resource) throws LackException { Boolean locked = cache.getIfPresent(resource); if (locked != null && locked) { throw new LackException(String.format(MESSAGE_ACQUIRE, resource)); } super.acquire(resource); cache.put(resource, true); } CachedLack(LackConfig config, String owner, Cache<String, Boolean> cache);  CachedLack(LackConfig config, String owner, long size); @Override void acquire(String resource); @Override void renew(String resource); @Override void release(String resource);  }
@Test public void alreadyLocked() throws LackException { cachedLack.acquire(resource); thrown.expect(LackException.class); cachedLack.acquire(resource); }
@Test public void alreadyLockedByOther() throws LackException { cachedLack.acquire(resource); thrown.expect(LackException.class); otherCachedLack.acquire(resource); }
@Test public void testReleaseAfterTtl() throws Exception { cachedLack.acquire(resource); Thread.sleep(1200); cachedLack.acquire(resource); verify(cache, times(2)).getIfPresent(resource); verify(cache, times(2)).put(resource, true); verify(cache, never()).put(resource, false); }