Created
October 3, 2016 20:31
-
-
Save xdom/eb81fe60d75097b9b81267e37de0db36 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void testAcquiringLockInNoneStateRemotelyLocked() throws Exception { | |
final ExecutorService executor = Executors.newFixedThreadPool(2); | |
final AtomicBoolean wasAcquired = new AtomicBoolean(false); | |
Mockito.when(lockServer.acquire("lock", OWNER_ID, 0)).then( | |
new Answer<Boolean>() { | |
@Override | |
public Boolean answer(InvocationOnMock invocation) throws Throwable { | |
return wasAcquired.getAndSet(true); | |
} | |
} | |
); | |
executor.submit(() -> cache.acquire("lock")); | |
Mockito.verify(lockServer, Mockito.after(200).times(1)).acquire("lock", OWNER_ID, 0); | |
executor.submit(() -> { | |
try { | |
cache.retry("lock", 0); | |
} catch (RemoteException e) { | |
throw new RuntimeException(e); | |
} | |
}); | |
Mockito.verify(lockServer, Mockito.after(200).times(2)).acquire("lock", OWNER_ID, 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment