Last active
September 25, 2016 11:49
-
-
Save xdom/e1cf5cc2e457e20bc52a8f39f53bb37f to your computer and use it in GitHub Desktop.
Lock acquiring test. First obtains a lock and then in new thread tries to obtain lock with the same lock ID. The lock should be obtained only in case that the lock was released by the original thread.
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 testLockAcquiring() throws Exception { | |
final AtomicBoolean released = new AtomicBoolean(false); | |
// acquire lock | |
Registry registry = LocateRegistry.getRegistry(REGISTRY_PORT); | |
LockServer remote = ((LockServer) registry.lookup(LockServer.BINDING_NAME)); | |
assertTrue(remote.acquire("lock", null, 0)); | |
// lock in new Thread, and when completed, assert that lock had been released | |
CompletableFuture.supplyAsync(new LockAcquirer()) | |
.thenAccept(r -> assertTrue(released.get())); | |
// release the lock | |
remote.release("lock", null); | |
released.compareAndSet(false, true); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment