Skip to content

Instantly share code, notes, and snippets.

@xdom
Created October 3, 2016 20:31
Show Gist options
  • Save xdom/eb81fe60d75097b9b81267e37de0db36 to your computer and use it in GitHub Desktop.
Save xdom/eb81fe60d75097b9b81267e37de0db36 to your computer and use it in GitHub Desktop.
@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