use of io.atomix.core.lock.AsyncDistributedLock in project atomix by atomix.
the class DistributedLockTest method testBlockingUnlock.
/**
* Tests unlocking a lock with a blocking call in the event thread.
*/
@Test
public void testBlockingUnlock() throws Throwable {
AsyncDistributedLock lock1 = atomix().lockBuilder("test-blocking-unlock", protocol()).build().async();
AsyncDistributedLock lock2 = atomix().lockBuilder("test-blocking-unlock", protocol()).build().async();
lock1.lock().thenRun(() -> {
lock1.unlock().join();
}).join();
lock2.lock().join();
}
use of io.atomix.core.lock.AsyncDistributedLock in project atomix by atomix.
the class DistributedLockTest method testTryLockSucceedWithTimeout.
/**
* Tests attempting to acquire a lock with a timeout.
*/
@Test
public void testTryLockSucceedWithTimeout() throws Throwable {
AsyncDistributedLock lock1 = atomix().lockBuilder("test-try-lock-succeed-with-timeout", protocol()).build().async();
AsyncDistributedLock lock2 = atomix().lockBuilder("test-try-lock-succeed-with-timeout", protocol()).build().async();
lock1.lock().join();
CompletableFuture<Optional<Version>> future = lock2.tryLock(Duration.ofSeconds(1));
lock1.unlock().join();
assertTrue(future.join().isPresent());
}
use of io.atomix.core.lock.AsyncDistributedLock in project atomix by atomix.
the class DistributedLockTest method testReleaseOnClose.
/**
* Tests releasing a lock when the client's session is closed.
*/
@Test
public void testReleaseOnClose() throws Throwable {
AsyncDistributedLock lock1 = atomix().lockBuilder("test-lock-on-close", protocol()).build().async();
AsyncDistributedLock lock2 = atomix().lockBuilder("test-lock-on-close", protocol()).build().async();
lock1.lock().join();
CompletableFuture<Version> future = lock2.lock();
lock1.close();
future.join();
}
use of io.atomix.core.lock.AsyncDistributedLock in project atomix by atomix.
the class DistributedLockTest method testLockUnlock.
/**
* Tests locking and unlocking a lock.
*/
@Test
public void testLockUnlock() throws Throwable {
AsyncDistributedLock lock = atomix().lockBuilder("test-lock-unlock", protocol()).build().async();
lock.lock().join();
lock.unlock().join();
}
use of io.atomix.core.lock.AsyncDistributedLock in project atomix by atomix.
the class DistributedLockTest method testTryLockFail.
/**
* Tests attempting to acquire a lock.
*/
@Test
public void testTryLockFail() throws Throwable {
AsyncDistributedLock lock1 = atomix().lockBuilder("test-try-lock-fail", protocol()).build().async();
AsyncDistributedLock lock2 = atomix().lockBuilder("test-try-lock-fail", protocol()).build().async();
lock1.lock().join();
assertFalse(lock2.tryLock().join().isPresent());
}
Aggregations