Search in sources :

Example 6 with AsyncDistributedLock

use of io.atomix.core.lock.AsyncDistributedLock in project atomix by atomix.

the class DistributedLockTest method testTryLockFailWithTimeout.

/**
 * Tests attempting to acquire a lock with a timeout.
 */
@Test
public void testTryLockFailWithTimeout() throws Throwable {
    AsyncDistributedLock lock1 = atomix().lockBuilder("test-try-lock-fail-with-timeout", protocol()).build().async();
    AsyncDistributedLock lock2 = atomix().lockBuilder("test-try-lock-fail-with-timeout", protocol()).build().async();
    lock1.lock().join();
    assertFalse(lock2.tryLock(Duration.ofSeconds(1)).join().isPresent());
}
Also used : AsyncDistributedLock(io.atomix.core.lock.AsyncDistributedLock) Test(org.junit.Test) AbstractPrimitiveTest(io.atomix.core.AbstractPrimitiveTest)

Example 7 with AsyncDistributedLock

use of io.atomix.core.lock.AsyncDistributedLock in project atomix by atomix.

the class DistributedLockTest method testTryLockSucceed.

/**
 * Tests attempting to acquire a lock.
 */
@Test
public void testTryLockSucceed() throws Throwable {
    AsyncDistributedLock lock = atomix().lockBuilder("test-try-lock-succeed", protocol()).build().async();
    assertTrue(lock.tryLock().join().isPresent());
}
Also used : AsyncDistributedLock(io.atomix.core.lock.AsyncDistributedLock) Test(org.junit.Test) AbstractPrimitiveTest(io.atomix.core.AbstractPrimitiveTest)

Aggregations

AbstractPrimitiveTest (io.atomix.core.AbstractPrimitiveTest)7 AsyncDistributedLock (io.atomix.core.lock.AsyncDistributedLock)7 Test (org.junit.Test)7 Version (io.atomix.utils.time.Version)1 Optional (java.util.Optional)1