### Question:
LocalMemoryStorage implements Storage<T> { @Override public boolean lock(String key, long timeout, TimeUnit ofUnit) { try { return getLock(key).tryLock(timeout, ofUnit); } catch (Exception e) { LOGGER.warn(String.format("Failed to lock storage by key %s", key), e); } return false; } LocalMemoryStorage();  LocalMemoryStorage(Map<String, T> storage); @Override void put(String key, T value); @Override T get(String key); @Override Set<String> keys(); @Override Map<String, T> valuesMap(); @Override boolean lock(String key, long timeout, TimeUnit ofUnit); @Override void unlock(String key);  }### Answer:
@Test public void testLock() throws InterruptedException { final Storage storage = new LocalMemoryStorage<>(); new Thread() { @Override public void run() { storage.lock(KEY, 0, SECONDS); try { sleep(SECONDS.toMillis(3)); storage.unlock(KEY); } catch (InterruptedException e) { e.printStackTrace(); } } }.start(); sleep(SECONDS.toMillis(1)); assertFalse("Should not allow lock of the key", storage.lock(KEY, 1, SECONDS)); sleep(SECONDS.toMillis(2)); assertTrue("Should allow lock of the key", storage.lock(KEY, 1, SECONDS)); }