Search in sources :

Example 11 with LockToken

use of com.palantir.lock.v2.LockToken in project atlasdb by palantir.

the class AsyncLockServiceEteTest method canLockAndUnlock.

@Test
public void canLockAndUnlock() {
    LockToken token = lockSynchronously(REQUEST_1, LOCK_A);
    assertLocked(LOCK_A);
    assertTrue(service.unlock(token));
    assertNotLocked(LOCK_A);
}
Also used : LockToken(com.palantir.lock.v2.LockToken) Test(org.junit.Test)

Example 12 with LockToken

use of com.palantir.lock.v2.LockToken in project atlasdb by palantir.

the class AsyncLockServiceEteTest method waitForLocksRequestsAreIdempotent.

@Test
public void waitForLocksRequestsAreIdempotent() {
    LockToken token = lockSynchronously(REQUEST_1, LOCK_A);
    AsyncResult<Void> request = service.waitForLocks(REQUEST_2, descriptors(LOCK_A), SHORT_TIMEOUT);
    AsyncResult<Void> duplicate = service.waitForLocks(REQUEST_2, descriptors(LOCK_A), SHORT_TIMEOUT);
    assertThat(request).isEqualTo(duplicate);
    service.unlock(token);
    assertThat(request.isCompletedSuccessfully()).isTrue();
    assertThat(duplicate.isCompletedSuccessfully()).isTrue();
}
Also used : LockToken(com.palantir.lock.v2.LockToken) Test(org.junit.Test)

Example 13 with LockToken

use of com.palantir.lock.v2.LockToken in project atlasdb by palantir.

the class AsyncLockServiceEteTest method waitingRequestGetsTheLockAfterItIsUnlocked.

@Test
public void waitingRequestGetsTheLockAfterItIsUnlocked() {
    LockToken request1 = lockSynchronously(REQUEST_1, LOCK_A);
    AsyncResult<LockToken> request2 = lock(REQUEST_2, LOCK_A);
    assertThat(request2.isComplete()).isFalse();
    service.unlock(request1);
    assertThat(request2.isCompletedSuccessfully()).isTrue();
}
Also used : LockToken(com.palantir.lock.v2.LockToken) Test(org.junit.Test)

Example 14 with LockToken

use of com.palantir.lock.v2.LockToken in project atlasdb by palantir.

the class AsyncLockServiceEteTest method canWaitForLock.

@Test
public void canWaitForLock() {
    LockToken lockAHolder = lockSynchronously(REQUEST_1, LOCK_A);
    AsyncResult<Void> waitResult = waitForLocks(REQUEST_2, LOCK_A);
    assertThat(waitResult.isComplete()).isFalse();
    service.unlock(lockAHolder);
    assertThat(waitResult.isCompletedSuccessfully()).isTrue();
    assertNotLocked(LOCK_A);
}
Also used : LockToken(com.palantir.lock.v2.LockToken) Test(org.junit.Test)

Example 15 with LockToken

use of com.palantir.lock.v2.LockToken in project atlasdb by palantir.

the class AsyncLockServiceEteTest method waitingRequestGetsTheLockAfterItIsUnlockedWithMultipleLocks.

@Test
public void waitingRequestGetsTheLockAfterItIsUnlockedWithMultipleLocks() {
    LockToken request1 = lockSynchronously(REQUEST_1, LOCK_A, LOCK_C);
    AsyncResult<LockToken> request2 = lock(REQUEST_2, LOCK_A, LOCK_B, LOCK_C, LOCK_D);
    assertThat(request2.isComplete()).isFalse();
    service.unlock(request1);
    assertThat(request2.isCompletedSuccessfully()).isTrue();
}
Also used : LockToken(com.palantir.lock.v2.LockToken) Test(org.junit.Test)

Aggregations

LockToken (com.palantir.lock.v2.LockToken)42 Test (org.junit.Test)32 LockResponse (com.palantir.lock.v2.LockResponse)5 TimelockService (com.palantir.lock.v2.TimelockService)4 LockRequest (com.palantir.lock.v2.LockRequest)3 WaitForLocksResponse (com.palantir.lock.v2.WaitForLocksResponse)3 Timer (com.codahale.metrics.Timer)1 SafeAndUnsafeTableReferences (com.palantir.atlasdb.logging.LoggingArgs.SafeAndUnsafeTableReferences)1 TransactionLockAcquisitionTimeoutException (com.palantir.atlasdb.transaction.api.TransactionLockAcquisitionTimeoutException)1 TransactionLockTimeoutException (com.palantir.atlasdb.transaction.api.TransactionLockTimeoutException)1 ShouldRetry (com.palantir.flake.ShouldRetry)1 AtlasCellLockDescriptor (com.palantir.lock.AtlasCellLockDescriptor)1 AtlasRowLockDescriptor (com.palantir.lock.AtlasRowLockDescriptor)1 LockDescriptor (com.palantir.lock.LockDescriptor)1 LockRefreshToken (com.palantir.lock.LockRefreshToken)1 LockImmutableTimestampResponse (com.palantir.lock.v2.LockImmutableTimestampResponse)1 WaitForLocksRequest (com.palantir.lock.v2.WaitForLocksRequest)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1